From 17465417a9a3e0e4121afcfc1f82b4af06354786 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Mon, 30 Dec 2019 13:19:24 +0300 Subject: [PATCH] tests(core): add replaceable-components.state.spec #2404 --- .../replaceable-components.state.spec.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 npm/ng-packs/packages/core/src/lib/tests/replaceable-components.state.spec.ts diff --git a/npm/ng-packs/packages/core/src/lib/tests/replaceable-components.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/replaceable-components.state.spec.ts new file mode 100644 index 0000000000..c294b131e1 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tests/replaceable-components.state.spec.ts @@ -0,0 +1,41 @@ +import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; +import { NgxsModule, Store } from '@ngxs/store'; +import { ReplaceableComponentsState } from '../states/replaceable-components.state'; +import { Component } from '@angular/core'; +import { AddReplaceableComponent } from '../actions'; + +@Component({ selector: 'abp-dummy', template: 'dummy works' }) +class DummyComponent {} + +describe('ReplaceableComponentsState', () => { + let spectator: SpectatorHost; + const createHost = createHostFactory({ + component: DummyComponent, + imports: [NgxsModule.forRoot([ReplaceableComponentsState])], + }); + + beforeEach(() => { + spectator = createHost(''); + }); + + it('should add a component to the state', () => { + const store = spectator.get(Store); + expect(store.selectSnapshot(ReplaceableComponentsState.getAll)).toEqual([]); + store.dispatch(new AddReplaceableComponent({ component: DummyComponent, key: 'Dummy' })); + expect(store.selectSnapshot(ReplaceableComponentsState.getComponent('Dummy'))).toEqual({ + component: DummyComponent, + key: 'Dummy', + }); + }); + + it('should replace a exist component', () => { + const store = spectator.get(Store); + store.dispatch(new AddReplaceableComponent({ component: DummyComponent, key: 'Dummy' })); + store.dispatch(new AddReplaceableComponent({ component: null, key: 'Dummy' })); + expect(store.selectSnapshot(ReplaceableComponentsState.getComponent('Dummy'))).toEqual({ + component: null, + key: 'Dummy', + }); + expect(store.selectSnapshot(ReplaceableComponentsState.getAll)).toHaveLength(1); + }); +});