mirror of https://github.com/abpframework/abp.git
committed by
GitHub
14 changed files with 60 additions and 363 deletions
@ -1,27 +0,0 @@ |
|||
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; |
|||
import { of } from 'rxjs'; |
|||
import { ApplicationConfigurationService, RestService } from '../services'; |
|||
|
|||
describe('ApplicationConfigurationService', () => { |
|||
let spectator: SpectatorService<ApplicationConfigurationService>; |
|||
const createService = createServiceFactory({ |
|||
service: ApplicationConfigurationService, |
|||
mocks: [RestService], |
|||
}); |
|||
|
|||
beforeEach(() => (spectator = createService())); |
|||
|
|||
it('should send a GET to application-configuration API', () => { |
|||
const rest = spectator.inject(RestService); |
|||
|
|||
const requestSpy = jest.spyOn(rest, 'request'); |
|||
requestSpy.mockReturnValue(of(null)); |
|||
|
|||
spectator.service.getConfiguration().subscribe(); |
|||
|
|||
expect(requestSpy).toHaveBeenCalledWith( |
|||
{ method: 'GET', url: '/api/abp/application-configuration' }, |
|||
{}, |
|||
); |
|||
}); |
|||
}); |
|||
@ -1,126 +0,0 @@ |
|||
import { SpectatorDirective, createDirectiveFactory } from '@ngneat/spectator/jest'; |
|||
import { VisibilityDirective } from '../directives/visibility.directive'; |
|||
|
|||
describe('VisibilityDirective', () => { |
|||
let spectator: SpectatorDirective<VisibilityDirective>; |
|||
let directive: VisibilityDirective; |
|||
const createDirective = createDirectiveFactory({ |
|||
directive: VisibilityDirective, |
|||
}); |
|||
|
|||
describe('without content', () => { |
|||
beforeEach(() => { |
|||
spectator = createDirective('<div [abpVisibility]></div>'); |
|||
directive = spectator.directive; |
|||
}); |
|||
|
|||
it('should be created', () => { |
|||
expect(directive).toBeTruthy(); |
|||
}); |
|||
|
|||
xit('should be removed', done => { |
|||
setTimeout(() => { |
|||
expect(spectator.query('div')).toBeFalsy(); |
|||
done(); |
|||
}, 0); |
|||
}); |
|||
}); |
|||
|
|||
describe('without mutation observer and with content', () => { |
|||
beforeEach(() => { |
|||
spectator = createDirective('<div [abpVisibility]><p id="content">Content</p></div>'); |
|||
directive = spectator.directive; |
|||
}); |
|||
|
|||
it('should not removed', done => { |
|||
setTimeout(() => { |
|||
expect(spectator.query('div')).toBeTruthy(); |
|||
done(); |
|||
}, 0); |
|||
}); |
|||
}); |
|||
|
|||
describe('without mutation observer and with focused element', () => { |
|||
beforeEach(() => { |
|||
spectator = createDirective( |
|||
'<div id="main" [abpVisibility]="container"></div><div #container><p id="content">Content</p></div>', |
|||
); |
|||
directive = spectator.directive; |
|||
}); |
|||
|
|||
it('should not removed', done => { |
|||
setTimeout(() => { |
|||
expect(spectator.query('#main')).toBeTruthy(); |
|||
done(); |
|||
}, 0); |
|||
}); |
|||
}); |
|||
|
|||
describe('without content and with focused element', () => { |
|||
beforeEach(() => { |
|||
spectator = createDirective( |
|||
'<div id="main" [abpVisibility]="container"></div><div #container></div>', |
|||
); |
|||
directive = spectator.directive; |
|||
}); |
|||
|
|||
xit('should be removed', done => { |
|||
setTimeout(() => { |
|||
expect(spectator.query('#main')).toBeFalsy(); |
|||
done(); |
|||
}, 0); |
|||
}); |
|||
}); |
|||
|
|||
describe('with mutation observer and with content', () => { |
|||
beforeEach(() => { |
|||
spectator = createDirective('<div [abpVisibility]><div id="content">Content</div></div>'); |
|||
directive = spectator.directive; |
|||
}); |
|||
|
|||
xit('should remove the main div element when content removed', done => { |
|||
spectator.query('#content').remove(); |
|||
|
|||
setTimeout(() => { |
|||
expect(spectator.query('div')).toBeFalsy(); |
|||
done(); |
|||
}, 0); |
|||
}); |
|||
|
|||
it('should not remove the main div element', done => { |
|||
spectator.query('div').appendChild(document.createElement('div')); |
|||
|
|||
setTimeout(() => { |
|||
expect(spectator.query('div')).toBeTruthy(); |
|||
done(); |
|||
}, 100); |
|||
}); |
|||
}); |
|||
|
|||
describe('with mutation observer and with focused element', () => { |
|||
beforeEach(() => { |
|||
spectator = createDirective( |
|||
'<div id="main" [abpVisibility]="container"></div><div #container><p id="content">Content</p></div>', |
|||
); |
|||
directive = spectator.directive; |
|||
}); |
|||
|
|||
xit('should remove the main div element when content removed', done => { |
|||
spectator.query('#content').remove(); |
|||
|
|||
setTimeout(() => { |
|||
expect(spectator.query('#main')).toBeFalsy(); |
|||
done(); |
|||
}, 0); |
|||
}); |
|||
|
|||
it('should not remove the main div element', done => { |
|||
spectator.query('#content').appendChild(document.createElement('div')); |
|||
|
|||
setTimeout(() => { |
|||
expect(spectator.query('#main')).toBeTruthy(); |
|||
done(); |
|||
}, 100); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -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(''); |
|||
}); |
|||
}); |
|||
@ -1,6 +1,5 @@ |
|||
import { InjectionToken } from '@angular/core'; |
|||
|
|||
// TODO: Should be documented
|
|||
export const SUPPRESS_UNSAVED_CHANGES_WARNING = new InjectionToken<boolean>( |
|||
'SUPPRESS_UNSAVED_CHANGES_WARNING', |
|||
); |
|||
|
|||
Loading…
Reference in new issue