|
1 | 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
|
2 | 2 |
|
| 3 | +exports[`Feature Schematic should create all files of a feature with an entity 1`] = ` |
| 4 | +"import { createActionGroup, emptyProps, props } from '@ngrx/store'; |
| 5 | +import { Update } from '@ngrx/entity'; |
| 6 | +
|
| 7 | +import { Foo } from './foo.model'; |
| 8 | +
|
| 9 | +export const FooActions = createActionGroup({ |
| 10 | + source: 'Foo/API', |
| 11 | + events: { |
| 12 | + 'Load Foos': props<{ foos: Foo[] }>(), |
| 13 | + 'Add Foo': props<{ foo: Foo }>(), |
| 14 | + 'Upsert Foo': props<{ foo: Foo }>(), |
| 15 | + 'Add Foos': props<{ foo: Foo[] }>(), |
| 16 | + 'Upsert Foos': props<{ foo: Foo[] }>(), |
| 17 | + 'Update Foo': props<{ foo: Update<Foo> }>(), |
| 18 | + 'Update Foos': props<{ foos: Update<Foo>[] }>(), |
| 19 | + 'Delete Foo': props<{ id: string }>(), |
| 20 | + 'Delete Foos': props<{ ids: string[] }>(), |
| 21 | + 'Clear Foos': emptyProps(), |
| 22 | + } |
| 23 | +}); |
| 24 | +" |
| 25 | +`; |
| 26 | + |
| 27 | +exports[`Feature Schematic should create all files of a feature with an entity 2`] = ` |
| 28 | +"import { createFeature, createReducer, on } from '@ngrx/store'; |
| 29 | +import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity'; |
| 30 | +import { Foo } from './foo.model'; |
| 31 | +import { FooActions } from './foo.actions'; |
| 32 | +
|
| 33 | +export const foosFeatureKey = 'foos'; |
| 34 | +
|
| 35 | +export interface State extends EntityState<Foo> { |
| 36 | + // additional entities state properties |
| 37 | +} |
| 38 | +
|
| 39 | +export const adapter: EntityAdapter<Foo> = createEntityAdapter<Foo>(); |
| 40 | +
|
| 41 | +export const initialState: State = adapter.getInitialState({ |
| 42 | + // additional entity state properties |
| 43 | +}); |
| 44 | +
|
| 45 | +export const reducer = createReducer( |
| 46 | + initialState, |
| 47 | + on(FooActions.addFoo, |
| 48 | + (state, action) => adapter.addOne(action.foo, state) |
| 49 | + ), |
| 50 | + on(FooActions.upsertFoo, |
| 51 | + (state, action) => adapter.upsertOne(action.foo, state) |
| 52 | + ), |
| 53 | + on(FooActions.addFoos, |
| 54 | + (state, action) => adapter.addMany(action.foos, state) |
| 55 | + ), |
| 56 | + on(FooActions.upsertFoos, |
| 57 | + (state, action) => adapter.upsertMany(action.foos, state) |
| 58 | + ), |
| 59 | + on(FooActions.updateFoo, |
| 60 | + (state, action) => adapter.updateOne(action.foo, state) |
| 61 | + ), |
| 62 | + on(FooActions.updateFoos, |
| 63 | + (state, action) => adapter.updateMany(action.foos, state) |
| 64 | + ), |
| 65 | + on(FooActions.deleteFoo, |
| 66 | + (state, action) => adapter.removeOne(action.id, state) |
| 67 | + ), |
| 68 | + on(FooActions.deleteFoos, |
| 69 | + (state, action) => adapter.removeMany(action.ids, state) |
| 70 | + ), |
| 71 | + on(FooActions.loadFoos, |
| 72 | + (state, action) => adapter.setAll(action.foos, state) |
| 73 | + ), |
| 74 | + on(FooActions.clearFoos, |
| 75 | + state => adapter.removeAll(state) |
| 76 | + ), |
| 77 | +); |
| 78 | +
|
| 79 | +export const foosFeature = createFeature({ |
| 80 | + name: foosFeatureKey, |
| 81 | + reducer, |
| 82 | + extraSelectors: ({ selectFoosState }) => ({ |
| 83 | + ...adapter.getSelectors(selectFoosState) |
| 84 | + }), |
| 85 | +}); |
| 86 | +
|
| 87 | +export const { |
| 88 | + selectIds, |
| 89 | + selectEntities, |
| 90 | + selectAll, |
| 91 | + selectTotal, |
| 92 | +} = foosFeature; |
| 93 | +" |
| 94 | +`; |
| 95 | +
|
| 96 | +exports[`Feature Schematic should create all files of a feature with an entity 3`] = ` |
| 97 | +"import { reducer, initialState } from './foo.reducer'; |
| 98 | +
|
| 99 | +describe('Foo Reducer', () => { |
| 100 | + describe('unknown action', () => { |
| 101 | + it('should return the previous state', () => { |
| 102 | + const action = {} as any; |
| 103 | +
|
| 104 | + const result = reducer(initialState, action); |
| 105 | +
|
| 106 | + expect(result).toBe(initialState); |
| 107 | + }); |
| 108 | + }); |
| 109 | +}); |
| 110 | +" |
| 111 | +`; |
| 112 | +
|
| 113 | +exports[`Feature Schematic should create all files of a feature with an entity 4`] = ` |
| 114 | +"import { Injectable } from '@angular/core'; |
| 115 | +import { Actions, createEffect, ofType } from '@ngrx/effects'; |
| 116 | +
|
| 117 | +import { concatMap } from 'rxjs/operators'; |
| 118 | +import { Observable, EMPTY } from 'rxjs'; |
| 119 | +import { FooActions } from './foo.actions'; |
| 120 | +
|
| 121 | +@Injectable() |
| 122 | +export class FooEffects { |
| 123 | +
|
| 124 | +
|
| 125 | + loadFoos$ = createEffect(() => { |
| 126 | + return this.actions$.pipe( |
| 127 | +
|
| 128 | + ofType(FooActions.loadFoos), |
| 129 | + /** An EMPTY observable only emits completion. Replace with your own observable API request */ |
| 130 | + concatMap(() => EMPTY as Observable<{ type: string }>) |
| 131 | + ); |
| 132 | + }); |
| 133 | +
|
| 134 | + constructor(private actions$: Actions) {} |
| 135 | +} |
| 136 | +" |
| 137 | +`; |
| 138 | +
|
| 139 | +exports[`Feature Schematic should create all files of a feature with an entity 5`] = ` |
| 140 | +"import { TestBed } from '@angular/core/testing'; |
| 141 | +import { provideMockActions } from '@ngrx/effects/testing'; |
| 142 | +import { Observable } from 'rxjs'; |
| 143 | +
|
| 144 | +import { FooEffects } from './foo.effects'; |
| 145 | +
|
| 146 | +describe('FooEffects', () => { |
| 147 | + let actions$: Observable<any>; |
| 148 | + let effects: FooEffects; |
| 149 | +
|
| 150 | + beforeEach(() => { |
| 151 | + TestBed.configureTestingModule({ |
| 152 | + providers: [ |
| 153 | + FooEffects, |
| 154 | + provideMockActions(() => actions$) |
| 155 | + ] |
| 156 | + }); |
| 157 | +
|
| 158 | + effects = TestBed.inject(FooEffects); |
| 159 | + }); |
| 160 | +
|
| 161 | + it('should be created', () => { |
| 162 | + expect(effects).toBeTruthy(); |
| 163 | + }); |
| 164 | +}); |
| 165 | +" |
| 166 | +`; |
| 167 | +
|
| 168 | +exports[`Feature Schematic should create all files of a feature with an entity 6`] = ` |
| 169 | +"export interface Foo { |
| 170 | + id: string; |
| 171 | +} |
| 172 | +" |
| 173 | +`; |
| 174 | +
|
3 | 175 | exports[`Feature Schematic should have all api actions in reducer if api flag enabled 1`] = `
|
4 | 176 | "import { createFeature, createReducer, on } from '@ngrx/store';
|
5 | 177 | import { FooActions } from './foo.actions';
|
|
0 commit comments