mirror of https://github.com/abpframework/abp.git
7 changed files with 31 additions and 186 deletions
@ -1,34 +0,0 @@ |
|||
import { Component, ComponentFactoryResolver, ComponentRef } from '@angular/core'; |
|||
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; |
|||
import { ModalContainerComponent } from '../components/modal/modal-container.component'; |
|||
|
|||
describe('ModalContainerComponent', () => { |
|||
@Component({ template: '<div class="foo">bar</div>' }) |
|||
class TestComponent {} |
|||
|
|||
let componentRef: ComponentRef<TestComponent>; |
|||
let spectator: Spectator<ModalContainerComponent>; |
|||
|
|||
const createComponent = createComponentFactory({ |
|||
component: ModalContainerComponent, |
|||
entryComponents: [TestComponent], |
|||
}); |
|||
|
|||
beforeEach(() => (spectator = createComponent())); |
|||
|
|||
afterEach(() => componentRef.destroy()); |
|||
|
|||
describe('#container', () => { |
|||
it('should be a ViewContainerRef', () => { |
|||
let foo = document.querySelector('div.foo'); |
|||
expect(foo).toBeNull(); |
|||
|
|||
const cfResolver = spectator.inject(ComponentFactoryResolver); |
|||
const factory = cfResolver.resolveComponentFactory(TestComponent); |
|||
componentRef = spectator.component.container.createComponent(factory); |
|||
|
|||
foo = document.querySelector('div.foo'); |
|||
expect(foo.textContent).toBe('bar'); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -1,87 +0,0 @@ |
|||
import { Component, TemplateRef, ViewChild } from '@angular/core'; |
|||
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; |
|||
import { ModalContainerComponent } from '../components/modal/modal-container.component'; |
|||
import { ModalService } from '../services'; |
|||
|
|||
describe('ModalContainerComponent', () => { |
|||
@Component({ |
|||
template: ` |
|||
<ng-template #ref> |
|||
<div class="foo">bar</div> |
|||
</ng-template> |
|||
`,
|
|||
}) |
|||
class TestComponent { |
|||
@ViewChild('ref', { static: true }) |
|||
template: TemplateRef<any>; |
|||
|
|||
constructor(public modalService: ModalService) {} |
|||
} |
|||
|
|||
let spectator: Spectator<TestComponent>; |
|||
let service: ModalService; |
|||
|
|||
const createComponent = createComponentFactory({ |
|||
component: TestComponent, |
|||
entryComponents: [ModalContainerComponent], |
|||
}); |
|||
|
|||
beforeEach(() => { |
|||
spectator = createComponent(); |
|||
service = spectator.component.modalService; |
|||
}); |
|||
|
|||
afterEach(() => { |
|||
service.getContainer().clear(); |
|||
service['containerComponentRef'].changeDetectorRef.detectChanges(); |
|||
service['containerComponentRef'].destroy(); |
|||
}); |
|||
|
|||
describe('#getContainer', () => { |
|||
it('should return the ViewContainerRef of ModalContainerComponent', () => { |
|||
let foo = document.querySelector('div.foo'); |
|||
expect(foo).toBeNull(); |
|||
|
|||
const containerRef = service.getContainer(); |
|||
const embeddedViewRef = containerRef.createEmbeddedView(spectator.component.template); |
|||
|
|||
foo = document.querySelector('div.foo'); |
|||
expect(foo).toBe(embeddedViewRef.rootNodes[0]); |
|||
expect(foo.textContent).toBe('bar'); |
|||
}); |
|||
}); |
|||
|
|||
describe('#renderTemplate', () => { |
|||
it('should render given template using the ViewContainerRef of ModalContainerComponent', () => { |
|||
let foo = document.querySelector('div.foo'); |
|||
expect(foo).toBeNull(); |
|||
|
|||
service.renderTemplate(spectator.component.template); |
|||
|
|||
foo = document.querySelector('div.foo'); |
|||
expect(foo.textContent).toBe('bar'); |
|||
}); |
|||
}); |
|||
|
|||
describe('#detectChanges', () => { |
|||
it('should call detectChanges on the containerComponentRef', () => { |
|||
const spy = jest.spyOn(service['containerComponentRef'].changeDetectorRef, 'detectChanges'); |
|||
|
|||
service.detectChanges(); |
|||
|
|||
expect(spy).toHaveBeenCalledTimes(1); |
|||
}); |
|||
}); |
|||
|
|||
describe('#clearModal', () => { |
|||
it('should call clear on the ViewContainerRef and detectChanges', () => { |
|||
const clear = jest.spyOn(service.getContainer(), 'clear'); |
|||
const detectChanges = jest.spyOn(service, 'detectChanges'); |
|||
|
|||
service.clearModal(); |
|||
|
|||
expect(clear).toHaveBeenCalledTimes(1); |
|||
expect(detectChanges).toHaveBeenCalledTimes(1); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -1,46 +0,0 @@ |
|||
import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; |
|||
import { SortOrderIconComponent } from '../components/sort-order-icon/sort-order-icon.component'; |
|||
|
|||
describe('SortOrderIconComponent', () => { |
|||
let spectator: SpectatorHost<SortOrderIconComponent>; |
|||
let component: SortOrderIconComponent; |
|||
const createHost = createHostFactory(SortOrderIconComponent); |
|||
|
|||
beforeEach(() => { |
|||
spectator = createHost( |
|||
'<abp-sort-order-icon sortKey="testKey" [(selectedSortKey)]="selectedSortKey" [(order)]="order"></abp-sort-order-icon>', |
|||
{ |
|||
hostProps: { |
|||
selectedSortKey: '', |
|||
order: '', |
|||
}, |
|||
}, |
|||
); |
|||
component = spectator.component; |
|||
}); |
|||
|
|||
test('should have correct icon class when selectedSortKey and sortKey are the same', () => { |
|||
const newKey = 'testKey'; |
|||
component.sort(newKey); |
|||
expect(component.selectedSortKey).toBe(newKey); |
|||
expect(component.order).toBe('asc'); |
|||
expect(component.icon).toBe('sorting_asc'); |
|||
}); |
|||
|
|||
test("shouldn't have any icon class when sortKey and selectedSortKey are different", () => { |
|||
const newKey = 'otherKey'; |
|||
component.sort(newKey); |
|||
expect(component.selectedSortKey).toBe(newKey); |
|||
expect(component.order).toBe('asc'); |
|||
expect(component.icon).toBe('sorting'); |
|||
}); |
|||
|
|||
test('should change order correctly when sort function called', () => { |
|||
component.sort('testKey'); |
|||
expect(component.order).toBe('asc'); |
|||
component.sort('testKey'); |
|||
expect(component.order).toBe('desc'); |
|||
component.sort('testKey'); |
|||
expect(component.order).toBe(''); |
|||
}); |
|||
}); |
|||
Loading…
Reference in new issue