|
8 | 8 | createSchematicRunner, |
9 | 9 | } from '../utils/testHelper'; |
10 | 10 |
|
| 11 | +import { determineStoreLocation } from './factory'; |
11 | 12 | import { PwaStoreOptionsSchema as Options } from './schema'; |
12 | 13 |
|
13 | 14 | describe('Store Schematic', () => { |
@@ -67,34 +68,9 @@ export interface CoreState { |
67 | 68 | export const getCoreState: Selector<CoreState, CoreState> = state => state; |
68 | 69 | ` |
69 | 70 | ); |
70 | | - appTree.create( |
71 | | - '/projects/bar/src/app/core/store/bar/bar-store.module.ts', |
72 | | - `import { NgModule } from '@angular/core'; |
73 | | -import { EffectsModule } from '@ngrx/effects'; |
74 | | -import { ActionReducerMap, StoreModule } from '@ngrx/store'; |
75 | | -
|
76 | | -import { BarState } from './bar-store'; |
77 | | -
|
78 | | -export const barReducers: ActionReducerMap<BarState> = {}; |
79 | | -
|
80 | | -export const barEffects = []; |
81 | | -
|
82 | | -@NgModule({ |
83 | | - imports: [ |
84 | | - EffectsModule.forRoot(barEffects), |
85 | | - StoreModule.forRoot(barReducers), |
86 | | - ], |
87 | | -}) |
88 | | -export class BarStoreModule {} |
89 | | -` |
90 | | - ); |
91 | | - appTree.create( |
92 | | - '/projects/bar/src/app/core/store/bar/bar-store.ts', |
93 | | - `import { Selector } from '@ngrx/store'; |
94 | | -
|
95 | | -export interface BarState {} |
96 | | -` |
97 | | - ); |
| 71 | + appTree = await schematicRunner |
| 72 | + .runSchematicAsync('store-group', { ...defaultOptions, name: 'bar' }, appTree) |
| 73 | + .toPromise(); |
98 | 74 | }); |
99 | 75 |
|
100 | 76 | it('should create a store in core store by default', async () => { |
@@ -203,4 +179,52 @@ export interface BarState {} |
203 | 179 | done(); |
204 | 180 | }); |
205 | 181 | }); |
| 182 | + |
| 183 | + describe('determineStoreLocation', () => { |
| 184 | + it('should handle simple stores', () => { |
| 185 | + const config = { |
| 186 | + extension: undefined, |
| 187 | + feature: undefined, |
| 188 | + name: 'foobar', |
| 189 | + parent: 'core', |
| 190 | + parentStorePath: 'projects/bar/src/app/core/store/core', |
| 191 | + path: 'projects/bar/src/app/core/store/', |
| 192 | + project: 'bar', |
| 193 | + }; |
| 194 | + |
| 195 | + expect(determineStoreLocation(appTree, { ...defaultOptions, name: 'foobar' })).toEqual(config); |
| 196 | + expect(determineStoreLocation(appTree, { ...defaultOptions, name: 'core/store/foobar' })).toEqual(config); |
| 197 | + }); |
| 198 | + |
| 199 | + it('should handle feature stores', () => { |
| 200 | + const config = { |
| 201 | + extension: undefined, |
| 202 | + feature: 'bar', |
| 203 | + name: 'foobar', |
| 204 | + parent: 'bar', |
| 205 | + parentStorePath: 'projects/bar/src/app/core/store/bar/bar', |
| 206 | + path: 'projects/bar/src/app/core/store/bar/', |
| 207 | + project: 'bar', |
| 208 | + }; |
| 209 | + |
| 210 | + expect(determineStoreLocation(appTree, { ...defaultOptions, name: 'foobar', feature: 'bar' })).toEqual(config); |
| 211 | + expect(determineStoreLocation(appTree, { ...defaultOptions, name: 'bar/foobar' })).toEqual(config); |
| 212 | + expect(determineStoreLocation(appTree, { ...defaultOptions, name: 'core/store/bar/foobar' })).toEqual(config); |
| 213 | + }); |
| 214 | + |
| 215 | + it('should handle extension stores', () => { |
| 216 | + const config = { |
| 217 | + extension: 'bar', |
| 218 | + feature: undefined, |
| 219 | + name: 'foobar', |
| 220 | + parent: 'bar', |
| 221 | + parentStorePath: 'projects/bar/src/app/extensions/bar/store/bar', |
| 222 | + path: 'projects/bar/src/app/extensions/bar/store/', |
| 223 | + project: 'bar', |
| 224 | + }; |
| 225 | + |
| 226 | + expect(determineStoreLocation(appTree, { ...defaultOptions, name: 'foobar', extension: 'bar' })).toEqual(config); |
| 227 | + expect(determineStoreLocation(appTree, { ...defaultOptions, name: 'extensions/bar/foobar' })).toEqual(config); |
| 228 | + }); |
| 229 | + }); |
206 | 230 | }); |
0 commit comments