mirror of https://github.com/abpframework/abp.git
38 changed files with 605 additions and 585 deletions
@ -1,201 +1,201 @@ |
|||||
import { HttpClient } from '@angular/common/http'; |
import { HttpClient } from '@angular/common/http'; |
||||
import { Component, NgModule } from '@angular/core'; |
import { Component, NgModule, inject as inject_1 } from '@angular/core'; |
||||
import { ActivatedRoute, RouterModule } from '@angular/router'; |
import { ActivatedRoute, RouterModule } from '@angular/router'; |
||||
import { createRoutingFactory, SpectatorRouting } from '@ngneat/spectator/jest'; |
import { createRoutingFactory, SpectatorRouting } from '@ngneat/spectator/jest'; |
||||
import { DynamicLayoutComponent, RouterOutletComponent } from '../components'; |
import { DynamicLayoutComponent, RouterOutletComponent } from '../components'; |
||||
import { eLayoutType } from '../enums/common'; |
import { eLayoutType } from '../enums/common'; |
||||
import { ABP } from '../models'; |
import { ABP } from '../models'; |
||||
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; |
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; |
||||
import { ReplaceableComponentsService, RoutesService } from '../services'; |
import { ReplaceableComponentsService, RoutesService } from '../services'; |
||||
import { mockRoutesService } from './routes.service.spec'; |
import { mockRoutesService } from './routes.service.spec'; |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-layout-application', |
selector: 'abp-layout-application', |
||||
template: '<router-outlet></router-outlet>', |
template: '<router-outlet></router-outlet>', |
||||
}) |
}) |
||||
class DummyApplicationLayoutComponent {} |
class DummyApplicationLayoutComponent {} |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-layout-account', |
selector: 'abp-layout-account', |
||||
template: '<router-outlet></router-outlet>', |
template: '<router-outlet></router-outlet>', |
||||
}) |
}) |
||||
class DummyAccountLayoutComponent {} |
class DummyAccountLayoutComponent {} |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-layout-empty', |
selector: 'abp-layout-empty', |
||||
template: '<router-outlet></router-outlet>', |
template: '<router-outlet></router-outlet>', |
||||
}) |
}) |
||||
class DummyEmptyLayoutComponent {} |
class DummyEmptyLayoutComponent {} |
||||
|
|
||||
const LAYOUTS = [ |
const LAYOUTS = [ |
||||
DummyApplicationLayoutComponent, |
DummyApplicationLayoutComponent, |
||||
DummyAccountLayoutComponent, |
DummyAccountLayoutComponent, |
||||
DummyEmptyLayoutComponent, |
DummyEmptyLayoutComponent, |
||||
]; |
]; |
||||
|
|
||||
@NgModule({ |
@NgModule({ |
||||
imports: [RouterModule], |
imports: [RouterModule], |
||||
declarations: [...LAYOUTS], |
declarations: [...LAYOUTS], |
||||
}) |
}) |
||||
class DummyLayoutModule {} |
class DummyLayoutModule {} |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-dummy', |
selector: 'abp-dummy', |
||||
template: '{{route.snapshot.data?.name}} works!', |
template: '{{route.snapshot.data?.name}} works!', |
||||
}) |
}) |
||||
class DummyComponent { |
class DummyComponent {
route = inject_1(ActivatedRoute); |
||||
constructor(public route: ActivatedRoute) {} |
|
||||
} |
} |
||||
|
|
||||
const routes: ABP.Route[] = [ |
const routes: ABP.Route[] = [ |
||||
{ |
{ |
||||
path: '', |
path: '', |
||||
name: 'Root', |
name: 'Root', |
||||
}, |
}, |
||||
{ |
{ |
||||
path: '/parentWithLayout', |
path: '/parentWithLayout', |
||||
name: 'ParentWithLayout', |
name: 'ParentWithLayout', |
||||
parentName: 'Root', |
parentName: 'Root', |
||||
layout: eLayoutType.application, |
layout: eLayoutType.application, |
||||
}, |
}, |
||||
{ |
{ |
||||
path: '/parentWithLayout/childWithoutLayout', |
path: '/parentWithLayout/childWithoutLayout', |
||||
name: 'ChildWithoutLayout', |
name: 'ChildWithoutLayout', |
||||
parentName: 'ParentWithLayout', |
parentName: 'ParentWithLayout', |
||||
}, |
}, |
||||
{ |
{ |
||||
path: '/parentWithLayout/childWithLayout', |
path: '/parentWithLayout/childWithLayout', |
||||
name: 'ChildWithLayout', |
name: 'ChildWithLayout', |
||||
parentName: 'ParentWithLayout', |
parentName: 'ParentWithLayout', |
||||
layout: eLayoutType.account, |
layout: eLayoutType.account, |
||||
}, |
}, |
||||
{ |
{ |
||||
path: '/withData', |
path: '/withData', |
||||
name: 'WithData', |
name: 'WithData', |
||||
layout: eLayoutType.application, |
layout: eLayoutType.application, |
||||
}, |
}, |
||||
]; |
]; |
||||
|
|
||||
describe('DynamicLayoutComponent', () => { |
describe('DynamicLayoutComponent', () => { |
||||
const createComponent = createRoutingFactory({ |
const createComponent = createRoutingFactory({ |
||||
component: RouterOutletComponent, |
component: RouterOutletComponent, |
||||
stubsEnabled: false, |
stubsEnabled: false, |
||||
declarations: [DummyComponent, DynamicLayoutComponent], |
declarations: [DummyComponent, DynamicLayoutComponent], |
||||
mocks: [AbpApplicationConfigurationService, HttpClient], |
mocks: [AbpApplicationConfigurationService, HttpClient], |
||||
providers: [ |
providers: [ |
||||
{ |
{ |
||||
provide: RoutesService, |
provide: RoutesService, |
||||
useFactory: () => mockRoutesService(), |
useFactory: () => mockRoutesService(), |
||||
}, |
}, |
||||
ReplaceableComponentsService, |
ReplaceableComponentsService, |
||||
], |
], |
||||
imports: [RouterModule, DummyLayoutModule], |
imports: [RouterModule, DummyLayoutModule], |
||||
routes: [ |
routes: [ |
||||
{ path: '', component: RouterOutletComponent }, |
{ path: '', component: RouterOutletComponent }, |
||||
{ |
{ |
||||
path: 'parentWithLayout', |
path: 'parentWithLayout', |
||||
component: DynamicLayoutComponent, |
component: DynamicLayoutComponent, |
||||
children: [ |
children: [ |
||||
{ |
{ |
||||
path: 'childWithoutLayout', |
path: 'childWithoutLayout', |
||||
component: DummyComponent, |
component: DummyComponent, |
||||
data: { name: 'childWithoutLayout' }, |
data: { name: 'childWithoutLayout' }, |
||||
}, |
}, |
||||
{ |
{ |
||||
path: 'childWithLayout', |
path: 'childWithLayout', |
||||
component: DummyComponent, |
component: DummyComponent, |
||||
data: { name: 'childWithLayout' }, |
data: { name: 'childWithLayout' }, |
||||
}, |
}, |
||||
], |
], |
||||
}, |
}, |
||||
{ |
{ |
||||
path: 'withData', |
path: 'withData', |
||||
component: DynamicLayoutComponent, |
component: DynamicLayoutComponent, |
||||
children: [ |
children: [ |
||||
{ |
{ |
||||
path: '', |
path: '', |
||||
component: DummyComponent, |
component: DummyComponent, |
||||
data: { name: 'withData' }, |
data: { name: 'withData' }, |
||||
}, |
}, |
||||
], |
], |
||||
data: { layout: eLayoutType.empty }, |
data: { layout: eLayoutType.empty }, |
||||
}, |
}, |
||||
{ |
{ |
||||
path: 'withoutLayout', |
path: 'withoutLayout', |
||||
component: DynamicLayoutComponent, |
component: DynamicLayoutComponent, |
||||
children: [ |
children: [ |
||||
{ |
{ |
||||
path: '', |
path: '', |
||||
component: DummyComponent, |
component: DummyComponent, |
||||
data: { name: 'withoutLayout' }, |
data: { name: 'withoutLayout' }, |
||||
}, |
}, |
||||
], |
], |
||||
data: { layout: null }, |
data: { layout: null }, |
||||
}, |
}, |
||||
], |
], |
||||
}); |
}); |
||||
|
|
||||
let spectator: SpectatorRouting<RouterOutletComponent>; |
let spectator: SpectatorRouting<RouterOutletComponent>; |
||||
let replaceableComponents: ReplaceableComponentsService; |
let replaceableComponents: ReplaceableComponentsService; |
||||
|
|
||||
beforeEach(async () => { |
beforeEach(async () => { |
||||
spectator = createComponent(); |
spectator = createComponent(); |
||||
replaceableComponents = spectator.inject(ReplaceableComponentsService); |
replaceableComponents = spectator.inject(ReplaceableComponentsService); |
||||
const routesService = spectator.inject(RoutesService); |
const routesService = spectator.inject(RoutesService); |
||||
routesService.add(routes); |
routesService.add(routes); |
||||
|
|
||||
replaceableComponents.add({ |
replaceableComponents.add({ |
||||
key: 'Theme.ApplicationLayoutComponent', |
key: 'Theme.ApplicationLayoutComponent', |
||||
component: DummyApplicationLayoutComponent, |
component: DummyApplicationLayoutComponent, |
||||
}); |
}); |
||||
replaceableComponents.add({ |
replaceableComponents.add({ |
||||
key: 'Theme.AccountLayoutComponent', |
key: 'Theme.AccountLayoutComponent', |
||||
component: DummyAccountLayoutComponent, |
component: DummyAccountLayoutComponent, |
||||
}); |
}); |
||||
replaceableComponents.add({ |
replaceableComponents.add({ |
||||
key: 'Theme.EmptyLayoutComponent', |
key: 'Theme.EmptyLayoutComponent', |
||||
component: DummyEmptyLayoutComponent, |
component: DummyEmptyLayoutComponent, |
||||
}); |
}); |
||||
}); |
}); |
||||
|
|
||||
it('should handle application layout from parent abp route and display it', async () => { |
it('should handle application layout from parent abp route and display it', async () => { |
||||
spectator.router.navigateByUrl('/parentWithLayout/childWithoutLayout'); |
spectator.router.navigateByUrl('/parentWithLayout/childWithoutLayout'); |
||||
await spectator.fixture.whenStable(); |
await spectator.fixture.whenStable(); |
||||
spectator.detectComponentChanges(); |
spectator.detectComponentChanges(); |
||||
expect(spectator.query('abp-dynamic-layout')).toBeTruthy(); |
expect(spectator.query('abp-dynamic-layout')).toBeTruthy(); |
||||
expect(spectator.query('abp-layout-application')).toBeTruthy(); |
expect(spectator.query('abp-layout-application')).toBeTruthy(); |
||||
}); |
}); |
||||
|
|
||||
it('should handle account layout from own property and display it', async () => { |
it('should handle account layout from own property and display it', async () => { |
||||
spectator.router.navigateByUrl('/parentWithLayout/childWithLayout'); |
spectator.router.navigateByUrl('/parentWithLayout/childWithLayout'); |
||||
await spectator.fixture.whenStable(); |
await spectator.fixture.whenStable(); |
||||
spectator.detectComponentChanges(); |
spectator.detectComponentChanges(); |
||||
expect(spectator.query('abp-layout-account')).toBeTruthy(); |
expect(spectator.query('abp-layout-account')).toBeTruthy(); |
||||
}); |
}); |
||||
|
|
||||
it('should handle empty layout from route data and display it', async () => { |
it('should handle empty layout from route data and display it', async () => { |
||||
spectator.router.navigateByUrl('/withData'); |
spectator.router.navigateByUrl('/withData'); |
||||
await spectator.fixture.whenStable(); |
await spectator.fixture.whenStable(); |
||||
spectator.detectComponentChanges(); |
spectator.detectComponentChanges(); |
||||
expect(spectator.query('abp-layout-empty')).toBeTruthy(); |
expect(spectator.query('abp-layout-empty')).toBeTruthy(); |
||||
}); |
}); |
||||
|
|
||||
it('should display empty layout when layout is null', async () => { |
it('should display empty layout when layout is null', async () => { |
||||
spectator.router.navigateByUrl('/withoutLayout'); |
spectator.router.navigateByUrl('/withoutLayout'); |
||||
await spectator.fixture.whenStable(); |
await spectator.fixture.whenStable(); |
||||
spectator.detectComponentChanges(); |
spectator.detectComponentChanges(); |
||||
expect(spectator.query('abp-layout-empty')).toBeTruthy(); |
expect(spectator.query('abp-layout-empty')).toBeTruthy(); |
||||
}); |
}); |
||||
|
|
||||
it('should not display any layout when layouts are empty', async () => { |
it('should not display any layout when layouts are empty', async () => { |
||||
const spy = jest.spyOn(replaceableComponents, 'get'); |
const spy = jest.spyOn(replaceableComponents, 'get'); |
||||
spy.mockReturnValue(null); |
spy.mockReturnValue(null); |
||||
spectator.detectChanges(); |
spectator.detectChanges(); |
||||
|
|
||||
spectator.router.navigateByUrl('/withoutLayout'); |
spectator.router.navigateByUrl('/withoutLayout'); |
||||
await spectator.fixture.whenStable(); |
await spectator.fixture.whenStable(); |
||||
spectator.detectComponentChanges(); |
spectator.detectComponentChanges(); |
||||
|
|
||||
expect(spectator.query('abp-layout-empty')).toBeFalsy(); |
expect(spectator.query('abp-layout-empty')).toBeFalsy(); |
||||
}); |
}); |
||||
}); |
}); |
||||
|
|||||
@ -1,178 +1,174 @@ |
|||||
import { Component, EventEmitter, Inject, Input, Optional, Output } from '@angular/core'; |
import { Component, EventEmitter, Input, Output, inject } from '@angular/core'; |
||||
import { Router } from '@angular/router'; |
import { Router } from '@angular/router'; |
||||
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; |
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; |
||||
import { BehaviorSubject } from 'rxjs'; |
import { BehaviorSubject } from 'rxjs'; |
||||
import { ReplaceableTemplateDirective } from '../directives/replaceable-template.directive'; |
import { ReplaceableTemplateDirective } from '../directives/replaceable-template.directive'; |
||||
import { ReplaceableComponents } from '../models/replaceable-components'; |
import { ReplaceableComponents } from '../models/replaceable-components'; |
||||
import { ReplaceableComponentsService } from '../services/replaceable-components.service'; |
import { ReplaceableComponentsService } from '../services/replaceable-components.service'; |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-default-component', |
selector: 'abp-default-component', |
||||
template: ' <p>default</p> ', |
template: ' <p>default</p> ', |
||||
exportAs: 'abpDefaultComponent', |
exportAs: 'abpDefaultComponent', |
||||
}) |
}) |
||||
class DefaultComponent { |
class DefaultComponent { |
||||
@Input() |
@Input() |
||||
oneWay; |
oneWay; |
||||
|
|
||||
@Input() |
@Input() |
||||
twoWay: boolean; |
twoWay: boolean; |
||||
|
|
||||
@Output() |
@Output() |
||||
readonly twoWayChange = new EventEmitter<boolean>(); |
readonly twoWayChange = new EventEmitter<boolean>(); |
||||
|
|
||||
@Output() |
@Output() |
||||
readonly someOutput = new EventEmitter<string>(); |
readonly someOutput = new EventEmitter<string>(); |
||||
|
|
||||
setTwoWay(value) { |
setTwoWay(value) { |
||||
this.twoWay = value; |
this.twoWay = value; |
||||
this.twoWayChange.emit(value); |
this.twoWayChange.emit(value); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-external-component', |
selector: 'abp-external-component', |
||||
template: ' <p>external</p> ', |
template: ' <p>external</p> ', |
||||
}) |
}) |
||||
class ExternalComponent { |
class ExternalComponent {
data = inject<ReplaceableComponents.ReplaceableTemplateData<any, any>>('REPLACEABLE_DATA' as any, { optional: true })!; |
||||
constructor( |
|
||||
@Optional() |
} |
||||
@Inject('REPLACEABLE_DATA') |
|
||||
public data: ReplaceableComponents.ReplaceableTemplateData<any, any>, |
describe('ReplaceableTemplateDirective', () => { |
||||
) {} |
let spectator: SpectatorDirective<ReplaceableTemplateDirective>; |
||||
} |
const get$Res = new BehaviorSubject(undefined); |
||||
|
|
||||
describe('ReplaceableTemplateDirective', () => { |
const createDirective = createDirectiveFactory({ |
||||
let spectator: SpectatorDirective<ReplaceableTemplateDirective>; |
directive: ReplaceableTemplateDirective, |
||||
const get$Res = new BehaviorSubject(undefined); |
declarations: [DefaultComponent, ExternalComponent], |
||||
|
entryComponents: [ExternalComponent], |
||||
const createDirective = createDirectiveFactory({ |
mocks: [Router], |
||||
directive: ReplaceableTemplateDirective, |
providers: [{ provide: ReplaceableComponentsService, useValue: { get$: () => get$Res } }], |
||||
declarations: [DefaultComponent, ExternalComponent], |
}); |
||||
entryComponents: [ExternalComponent], |
|
||||
mocks: [Router], |
describe('without external component', () => { |
||||
providers: [{ provide: ReplaceableComponentsService, useValue: { get$: () => get$Res } }], |
const twoWayChange = jest.fn(a => a); |
||||
}); |
const someOutput = jest.fn(a => a); |
||||
|
|
||||
describe('without external component', () => { |
beforeEach(() => { |
||||
const twoWayChange = jest.fn(a => a); |
spectator = createDirective( |
||||
const someOutput = jest.fn(a => a); |
` |
||||
|
<div *abpReplaceableTemplate="{inputs: {oneWay: {value: oneWay}, twoWay: {value: twoWay, twoWay: true}}, outputs: {twoWayChange: twoWayChange, someOutput: someOutput}, componentKey: 'TestModule.TestComponent'}; let initTemplate = initTemplate"> |
||||
beforeEach(() => { |
<abp-default-component #defaultComponent="abpDefaultComponent"></abp-default-component> |
||||
spectator = createDirective( |
</div> |
||||
` |
`,
|
||||
<div *abpReplaceableTemplate="{inputs: {oneWay: {value: oneWay}, twoWay: {value: twoWay, twoWay: true}}, outputs: {twoWayChange: twoWayChange, someOutput: someOutput}, componentKey: 'TestModule.TestComponent'}; let initTemplate = initTemplate"> |
{ |
||||
<abp-default-component #defaultComponent="abpDefaultComponent"></abp-default-component> |
hostProps: { |
||||
</div> |
oneWay: { label: 'Test' }, |
||||
`,
|
twoWay: false, |
||||
{ |
twoWayChange, |
||||
hostProps: { |
someOutput, |
||||
oneWay: { label: 'Test' }, |
}, |
||||
twoWay: false, |
}, |
||||
twoWayChange, |
); |
||||
someOutput, |
|
||||
}, |
const component = spectator.query(DefaultComponent); |
||||
}, |
spectator.directive.context.initTemplate(component); |
||||
); |
spectator.detectChanges(); |
||||
|
}); |
||||
const component = spectator.query(DefaultComponent); |
|
||||
spectator.directive.context.initTemplate(component); |
afterEach(() => twoWayChange.mockClear()); |
||||
spectator.detectChanges(); |
|
||||
}); |
it('should display the default template when store response is undefined', () => { |
||||
|
expect(spectator.query('abp-default-component')).toBeTruthy(); |
||||
afterEach(() => twoWayChange.mockClear()); |
}); |
||||
|
|
||||
it('should display the default template when store response is undefined', () => { |
it('should be setted inputs and outputs', () => { |
||||
expect(spectator.query('abp-default-component')).toBeTruthy(); |
const component = spectator.query(DefaultComponent); |
||||
}); |
expect(component.oneWay).toEqual({ label: 'Test' }); |
||||
|
expect(component.twoWay).toEqual(false); |
||||
it('should be setted inputs and outputs', () => { |
}); |
||||
const component = spectator.query(DefaultComponent); |
|
||||
expect(component.oneWay).toEqual({ label: 'Test' }); |
it('should change the component inputs', () => { |
||||
expect(component.twoWay).toEqual(false); |
const component = spectator.query(DefaultComponent); |
||||
}); |
spectator.setHostInput({ oneWay: 'test' }); |
||||
|
component.setTwoWay(true); |
||||
it('should change the component inputs', () => { |
component.someOutput.emit('someOutput emitted'); |
||||
const component = spectator.query(DefaultComponent); |
expect(component.oneWay).toBe('test'); |
||||
spectator.setHostInput({ oneWay: 'test' }); |
expect(twoWayChange).toHaveBeenCalledWith(true); |
||||
component.setTwoWay(true); |
expect(someOutput).toHaveBeenCalledWith('someOutput emitted'); |
||||
component.someOutput.emit('someOutput emitted'); |
}); |
||||
expect(component.oneWay).toBe('test'); |
}); |
||||
expect(twoWayChange).toHaveBeenCalledWith(true); |
|
||||
expect(someOutput).toHaveBeenCalledWith('someOutput emitted'); |
describe('with external component', () => { |
||||
}); |
const twoWayChange = jest.fn(a => a); |
||||
}); |
const someOutput = jest.fn(a => a); |
||||
|
|
||||
describe('with external component', () => { |
beforeEach(() => { |
||||
const twoWayChange = jest.fn(a => a); |
spectator = createDirective( |
||||
const someOutput = jest.fn(a => a); |
` |
||||
|
<div *abpReplaceableTemplate="{inputs: {oneWay: {value: oneWay}, twoWay: {value: twoWay, twoWay: true}}, outputs: {twoWayChange: twoWayChange, someOutput: someOutput}, componentKey: 'TestModule.TestComponent'}; let initTemplate = initTemplate"> |
||||
beforeEach(() => { |
<abp-default-component #defaultComponent="abpDefaultComponent"></abp-default-component> |
||||
spectator = createDirective( |
</div> |
||||
` |
`,
|
||||
<div *abpReplaceableTemplate="{inputs: {oneWay: {value: oneWay}, twoWay: {value: twoWay, twoWay: true}}, outputs: {twoWayChange: twoWayChange, someOutput: someOutput}, componentKey: 'TestModule.TestComponent'}; let initTemplate = initTemplate"> |
{ hostProps: { oneWay: { label: 'Test' }, twoWay: false, twoWayChange, someOutput } }, |
||||
<abp-default-component #defaultComponent="abpDefaultComponent"></abp-default-component> |
); |
||||
</div> |
|
||||
`,
|
get$Res.next({ component: ExternalComponent, key: 'TestModule.TestComponent' }); |
||||
{ hostProps: { oneWay: { label: 'Test' }, twoWay: false, twoWayChange, someOutput } }, |
}); |
||||
); |
|
||||
|
afterEach(() => twoWayChange.mockClear()); |
||||
get$Res.next({ component: ExternalComponent, key: 'TestModule.TestComponent' }); |
|
||||
}); |
it('should display the external component', () => { |
||||
|
expect(spectator.query('p')).toHaveText('external'); |
||||
afterEach(() => twoWayChange.mockClear()); |
}); |
||||
|
|
||||
it('should display the external component', () => { |
it('should be injected the data object', () => { |
||||
expect(spectator.query('p')).toHaveText('external'); |
const externalComponent = spectator.query(ExternalComponent); |
||||
}); |
expect(externalComponent.data).toEqual({ |
||||
|
componentKey: 'TestModule.TestComponent', |
||||
it('should be injected the data object', () => { |
inputs: { oneWay: { label: 'Test' }, twoWay: false }, |
||||
const externalComponent = spectator.query(ExternalComponent); |
outputs: { someOutput, twoWayChange }, |
||||
expect(externalComponent.data).toEqual({ |
}); |
||||
componentKey: 'TestModule.TestComponent', |
}); |
||||
inputs: { oneWay: { label: 'Test' }, twoWay: false }, |
|
||||
outputs: { someOutput, twoWayChange }, |
it('should be worked all data properties', () => { |
||||
}); |
const externalComponent = spectator.query(ExternalComponent); |
||||
}); |
spectator.setHostInput({ oneWay: 'test' }); |
||||
|
externalComponent.data.inputs.twoWay = true; |
||||
it('should be worked all data properties', () => { |
externalComponent.data.outputs.someOutput('someOutput emitted'); |
||||
const externalComponent = spectator.query(ExternalComponent); |
expect(externalComponent.data.inputs.oneWay).toBe('test'); |
||||
spectator.setHostInput({ oneWay: 'test' }); |
expect(twoWayChange).toHaveBeenCalledWith(true); |
||||
externalComponent.data.inputs.twoWay = true; |
expect(someOutput).toHaveBeenCalledWith('someOutput emitted'); |
||||
externalComponent.data.outputs.someOutput('someOutput emitted'); |
|
||||
expect(externalComponent.data.inputs.oneWay).toBe('test'); |
spectator.setHostInput({ twoWay: 'twoWay test' }); |
||||
expect(twoWayChange).toHaveBeenCalledWith(true); |
expect(externalComponent.data.inputs.twoWay).toBe('twoWay test'); |
||||
expect(someOutput).toHaveBeenCalledWith('someOutput emitted'); |
}); |
||||
|
|
||||
spectator.setHostInput({ twoWay: 'twoWay test' }); |
it('should be worked correctly the default component when the external component has been removed from store', () => { |
||||
expect(externalComponent.data.inputs.twoWay).toBe('twoWay test'); |
expect(spectator.query('p')).toHaveText('external'); |
||||
}); |
const externalComponent = spectator.query(ExternalComponent); |
||||
|
spectator.setHostInput({ oneWay: 'test' }); |
||||
it('should be worked correctly the default component when the external component has been removed from store', () => { |
externalComponent.data.inputs.twoWay = true; |
||||
expect(spectator.query('p')).toHaveText('external'); |
get$Res.next({ component: null, key: 'TestModule.TestComponent' }); |
||||
const externalComponent = spectator.query(ExternalComponent); |
spectator.detectChanges(); |
||||
spectator.setHostInput({ oneWay: 'test' }); |
const component = spectator.query(DefaultComponent); |
||||
externalComponent.data.inputs.twoWay = true; |
spectator.directive.context.initTemplate(component); |
||||
get$Res.next({ component: null, key: 'TestModule.TestComponent' }); |
expect(spectator.query('abp-default-component')).toBeTruthy(); |
||||
spectator.detectChanges(); |
|
||||
const component = spectator.query(DefaultComponent); |
expect(component.oneWay).toEqual('test'); |
||||
spectator.directive.context.initTemplate(component); |
expect(component.twoWay).toEqual(true); |
||||
expect(spectator.query('abp-default-component')).toBeTruthy(); |
}); |
||||
|
|
||||
expect(component.oneWay).toEqual('test'); |
it('should reset default component subscriptions', () => { |
||||
expect(component.twoWay).toEqual(true); |
get$Res.next({ component: null, key: 'TestModule.TestComponent' }); |
||||
}); |
const component = spectator.query(DefaultComponent); |
||||
|
spectator.directive.context.initTemplate(component); |
||||
it('should reset default component subscriptions', () => { |
spectator.detectChanges(); |
||||
get$Res.next({ component: null, key: 'TestModule.TestComponent' }); |
const unsubscribe = jest.fn(() => {}); |
||||
const component = spectator.query(DefaultComponent); |
spectator.directive.defaultComponentSubscriptions.twoWayChange.unsubscribe = unsubscribe; |
||||
spectator.directive.context.initTemplate(component); |
|
||||
spectator.detectChanges(); |
get$Res.next({ component: ExternalComponent, key: 'TestModule.TestComponent' }); |
||||
const unsubscribe = jest.fn(() => {}); |
expect(unsubscribe).toHaveBeenCalled(); |
||||
spectator.directive.defaultComponentSubscriptions.twoWayChange.unsubscribe = unsubscribe; |
}); |
||||
|
}); |
||||
get$Res.next({ component: ExternalComponent, key: 'TestModule.TestComponent' }); |
}); |
||||
expect(unsubscribe).toHaveBeenCalled(); |
|
||||
}); |
|
||||
}); |
|
||||
}); |
|
||||
|
|||||
Loading…
Reference in new issue