@ngxs/store 3.8.2-dev.master-0fd1fe5 → 3.8.2-dev.master-a75608e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ +16 -8
- package/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ +2 -0
- package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.spec.ts__template__ +22 -8
- package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.ts__template__ +2 -0
- package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ +14 -8
- package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ +2 -0
- package/schematics/src/state/files/__name__.state.spec.ts__template__ +9 -7
- package/schematics/src/state/files/__name__.state.ts__template__ +2 -0
- package/schematics/src/store/files/__name__.state.spec.ts__template__ +6 -5
- package/schematics/src/store/files/__name__.state.ts__template__ +2 -0
- package/schematics/src/utils/versions.json +1 -1
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { NgxsModule, Store } from '@ngxs/store';
|
|
2
|
-
import {
|
|
2
|
+
import { TestBed } from '@angular/core/testing';
|
|
3
3
|
import { AuthenticationStateModel, AuthState } from './auth.state';
|
|
4
4
|
import { SetAuthData } from './auth.actions';
|
|
5
5
|
|
|
6
6
|
describe('[TEST]: AuthStore', () => {
|
|
7
7
|
let store: Store;
|
|
8
8
|
|
|
9
|
-
beforeEach(
|
|
9
|
+
beforeEach(() => {
|
|
10
10
|
TestBed.configureTestingModule({
|
|
11
|
-
imports: [NgxsModule.forRoot([AuthState])]
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}));
|
|
11
|
+
imports: [NgxsModule.forRoot([AuthState])],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
store = TestBed.inject(Store);
|
|
15
|
+
});
|
|
17
16
|
|
|
18
17
|
it('Should be correct dispatch and value is empty', () => {
|
|
18
|
+
// Arrange
|
|
19
19
|
const Authentication: AuthenticationStateModel = {
|
|
20
20
|
id: '',
|
|
21
21
|
firstName: '',
|
|
@@ -24,12 +24,17 @@ describe('[TEST]: AuthStore', () => {
|
|
|
24
24
|
email: '',
|
|
25
25
|
roles: []
|
|
26
26
|
};
|
|
27
|
+
|
|
28
|
+
// Act
|
|
27
29
|
store.dispatch(new SetAuthData(Authentication));
|
|
28
30
|
const actual = store.selectSnapshot<AuthenticationStateModel>(AuthState.getAuthData);
|
|
31
|
+
|
|
32
|
+
// Assert
|
|
29
33
|
expect(actual).toEqual(Authentication);
|
|
30
34
|
});
|
|
31
35
|
|
|
32
36
|
it('Should be correct dispatch and next value is correct completed', () => {
|
|
37
|
+
// Arrange
|
|
33
38
|
const authentication: AuthenticationStateModel = {
|
|
34
39
|
id: '12',
|
|
35
40
|
firstName: 'Adam',
|
|
@@ -39,8 +44,11 @@ describe('[TEST]: AuthStore', () => {
|
|
|
39
44
|
roles: ['ADMIN']
|
|
40
45
|
};
|
|
41
46
|
|
|
47
|
+
// Act
|
|
42
48
|
store.dispatch(new SetAuthData(authentication));
|
|
43
49
|
const actual = store.selectSnapshot<AuthenticationStateModel>(AuthState.getAuthData);
|
|
50
|
+
|
|
51
|
+
// Assert
|
|
44
52
|
expect(actual).toEqual(authentication);
|
|
45
53
|
});
|
|
46
54
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
1
2
|
import { Action, Selector, State, StateContext } from '@ngxs/store';
|
|
2
3
|
import { SetAuthData } from './auth.actions';
|
|
3
4
|
|
|
@@ -21,6 +22,7 @@ export interface AuthenticationStateModel {
|
|
|
21
22
|
roles: []
|
|
22
23
|
}
|
|
23
24
|
})
|
|
25
|
+
@Injectable()
|
|
24
26
|
export class AuthState {
|
|
25
27
|
@Selector()
|
|
26
28
|
public static getAuthData(state: AuthenticationStateModel): AuthenticationStateModel {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NgxsModule, Store } from '@ngxs/store';
|
|
2
|
-
import {
|
|
2
|
+
import { TestBed } from '@angular/core/testing';
|
|
3
3
|
import { DictionaryState, DictionaryStateModel } from './dictionary.state';
|
|
4
4
|
import { DictionaryReset, SetDictionaryData } from './dictionary.actions';
|
|
5
5
|
|
|
@@ -27,16 +27,16 @@ const data = [
|
|
|
27
27
|
describe('[TEST]: Dictionary state', () => {
|
|
28
28
|
let store: Store;
|
|
29
29
|
|
|
30
|
-
beforeEach(
|
|
30
|
+
beforeEach(() => {
|
|
31
31
|
TestBed.configureTestingModule({
|
|
32
|
-
imports: [NgxsModule.forRoot([DictionaryState])]
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}));
|
|
32
|
+
imports: [NgxsModule.forRoot([DictionaryState])],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
store = TestBed.inject(Store);
|
|
36
|
+
});
|
|
38
37
|
|
|
39
38
|
it('Should be correct dispatch and dictionary is empty', () => {
|
|
39
|
+
// Arrange
|
|
40
40
|
const dictionary: DictionaryStateModel = {
|
|
41
41
|
content: [],
|
|
42
42
|
page: 0,
|
|
@@ -44,12 +44,17 @@ describe('[TEST]: Dictionary state', () => {
|
|
|
44
44
|
totalPages: 0,
|
|
45
45
|
totalElements: 0
|
|
46
46
|
};
|
|
47
|
+
|
|
48
|
+
// Act
|
|
47
49
|
store.dispatch(new SetDictionaryData(dictionary));
|
|
48
50
|
const actual = store.selectSnapshot(DictionaryState.getDictionaryState);
|
|
51
|
+
|
|
52
|
+
// Assert
|
|
49
53
|
expect(actual).toEqual(dictionary);
|
|
50
54
|
});
|
|
51
55
|
|
|
52
56
|
it('Should be state is filled DictionaryStateModel', () => {
|
|
57
|
+
// Arrange
|
|
53
58
|
const dictionary: DictionaryStateModel = {
|
|
54
59
|
content: data,
|
|
55
60
|
page: 0,
|
|
@@ -57,12 +62,17 @@ describe('[TEST]: Dictionary state', () => {
|
|
|
57
62
|
totalPages: 2,
|
|
58
63
|
totalElements: 1
|
|
59
64
|
};
|
|
65
|
+
|
|
66
|
+
// Act
|
|
60
67
|
store.dispatch(new SetDictionaryData(dictionary));
|
|
61
68
|
const actual = store.selectSnapshot(DictionaryState.getDictionaryState);
|
|
69
|
+
|
|
70
|
+
// Assert
|
|
62
71
|
expect(actual).toEqual(dictionary);
|
|
63
72
|
});
|
|
64
73
|
|
|
65
74
|
it('should be reset state', function () {
|
|
75
|
+
// Arrange
|
|
66
76
|
const dictionary: DictionaryStateModel = {
|
|
67
77
|
content: [],
|
|
68
78
|
page: 0,
|
|
@@ -70,8 +80,12 @@ describe('[TEST]: Dictionary state', () => {
|
|
|
70
80
|
totalPages: 0,
|
|
71
81
|
totalElements: 0
|
|
72
82
|
};
|
|
83
|
+
|
|
84
|
+
// Act
|
|
73
85
|
store.dispatch(new DictionaryReset());
|
|
74
86
|
const actual = store.selectSnapshot(DictionaryState.getDictionaryState);
|
|
87
|
+
|
|
88
|
+
// Assert
|
|
75
89
|
expect(actual).toEqual(dictionary);
|
|
76
90
|
});
|
|
77
91
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
1
2
|
import { Action, Selector, State, StateContext } from '@ngxs/store';
|
|
2
3
|
import { DictionaryReset, SetDictionaryData } from './dictionary.actions';
|
|
3
4
|
|
|
@@ -19,6 +20,7 @@ export interface DictionaryStateModel {
|
|
|
19
20
|
totalElements: 0
|
|
20
21
|
}
|
|
21
22
|
})
|
|
23
|
+
@Injectable()
|
|
22
24
|
export class DictionaryState {
|
|
23
25
|
@Selector()
|
|
24
26
|
public static getDictionaryState(state: DictionaryStateModel): DictionaryStateModel {
|
package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { NgxsModule, Store } from '@ngxs/store';
|
|
2
|
-
import {
|
|
2
|
+
import { TestBed } from '@angular/core/testing';
|
|
3
3
|
import { UserStateModel, UserState } from './user.state';
|
|
4
4
|
import { SetUser } from './user.actions';
|
|
5
5
|
|
|
6
6
|
describe('[TEST]: User state', () => {
|
|
7
7
|
let store: Store;
|
|
8
8
|
|
|
9
|
-
beforeEach(
|
|
9
|
+
beforeEach(() => {
|
|
10
10
|
TestBed.configureTestingModule({
|
|
11
|
-
imports: [NgxsModule.forRoot([UserState])]
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}));
|
|
11
|
+
imports: [NgxsModule.forRoot([UserState])],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
store = TestBed.inject(Store);
|
|
15
|
+
});
|
|
17
16
|
|
|
18
17
|
it('Should be state is UserStateModel', () => {
|
|
18
|
+
// Arrange
|
|
19
19
|
const user: UserStateModel = {
|
|
20
20
|
userId: '',
|
|
21
21
|
departmentCode: '',
|
|
@@ -27,13 +27,17 @@ describe('[TEST]: User state', () => {
|
|
|
27
27
|
positionId: '',
|
|
28
28
|
positionName: ''
|
|
29
29
|
};
|
|
30
|
+
|
|
31
|
+
// Act
|
|
30
32
|
store.dispatch(new SetUser(user));
|
|
31
33
|
const actual = store.selectSnapshot(({ user }) => user);
|
|
32
34
|
|
|
35
|
+
// Assert
|
|
33
36
|
expect(actual).toEqual(user);
|
|
34
37
|
});
|
|
35
38
|
|
|
36
39
|
it('Should be state is filled UserStateModel', () => {
|
|
40
|
+
// Arrange
|
|
37
41
|
const user: UserStateModel = {
|
|
38
42
|
userId: '12',
|
|
39
43
|
departmentCode: '2392',
|
|
@@ -46,9 +50,11 @@ describe('[TEST]: User state', () => {
|
|
|
46
50
|
positionName: 'admin'
|
|
47
51
|
};
|
|
48
52
|
|
|
53
|
+
// Act
|
|
49
54
|
store.dispatch(new SetUser(user));
|
|
50
55
|
const actual = store.selectSnapshot<UserStateModel>(({ user }) => user);
|
|
51
56
|
|
|
57
|
+
// Assert
|
|
52
58
|
expect(actual).toEqual(user);
|
|
53
59
|
});
|
|
54
60
|
});
|
package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
1
2
|
import { Action, Selector, State, StateContext } from '@ngxs/store';
|
|
2
3
|
import { SetUser } from './user.actions';
|
|
3
4
|
|
|
@@ -27,6 +28,7 @@ export interface UserStateModel {
|
|
|
27
28
|
departmentName: ''
|
|
28
29
|
}
|
|
29
30
|
})
|
|
31
|
+
@Injectable()
|
|
30
32
|
export class UserState {
|
|
31
33
|
@Selector()
|
|
32
34
|
public static getUser(state: UserStateModel): UserStateModel {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { TestBed
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
2
|
import { NgxsModule, Store } from '@ngxs/store';
|
|
3
3
|
import { <%= classify(name) %>State, <%= classify(name) %>StateModel } from './<%= dasherize(name) %>.state';
|
|
4
4
|
|
|
5
5
|
describe('<%= classify(name) %> state', () => {
|
|
6
6
|
let store: Store;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
TestBed.configureTestingModule({
|
|
10
|
+
imports: [NgxsModule.forRoot([<%= classify(name) %>State])]
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
store = TestBed.inject(Store);
|
|
14
|
+
});
|
|
13
15
|
|
|
14
16
|
it('should create an empty state', () => {
|
|
15
17
|
const actual = store.selectSnapshot(<%= classify(name) %>State.getState);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
1
2
|
import { State, Selector } from '@ngxs/store';
|
|
2
3
|
|
|
3
4
|
export interface <%= classify(name) %>StateModel {
|
|
@@ -10,6 +11,7 @@ export interface <%= classify(name) %>StateModel {
|
|
|
10
11
|
items: []
|
|
11
12
|
}
|
|
12
13
|
})
|
|
14
|
+
@Injectable()
|
|
13
15
|
export class <%= classify(name) %>State {
|
|
14
16
|
|
|
15
17
|
@Selector()
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { TestBed
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
2
|
import { NgxsModule, Store } from '@ngxs/store';
|
|
3
3
|
import { <%= classify(name) %>State, <%= classify(name) %>StateModel } from './<%= dasherize(name) %>.state';
|
|
4
4
|
import { <%= classify(name) %>Action } from './<%= dasherize(name) %>.actions';
|
|
5
5
|
|
|
6
6
|
describe('<%= classify(name) %> store', () => {
|
|
7
7
|
let store: Store;
|
|
8
|
-
beforeEach(
|
|
8
|
+
beforeEach(() => {
|
|
9
9
|
TestBed.configureTestingModule({
|
|
10
10
|
imports: [NgxsModule.forRoot([<%= classify(name) %>State])]
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
store = TestBed.inject(Store);
|
|
14
|
+
});
|
|
14
15
|
|
|
15
16
|
it('should create an action and add an item', () => {
|
|
16
17
|
const expected: <%= classify(name) %>StateModel = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
1
2
|
import { State, Action, Selector, StateContext } from '@ngxs/store';
|
|
2
3
|
import { <%= classify(name) %>Action } from './<%= dasherize(name) %>.actions';
|
|
3
4
|
|
|
@@ -11,6 +12,7 @@ export interface <%= classify(name) %>StateModel {
|
|
|
11
12
|
items: []
|
|
12
13
|
}
|
|
13
14
|
})
|
|
15
|
+
@Injectable()
|
|
14
16
|
export class <%= classify(name) %>State {
|
|
15
17
|
|
|
16
18
|
@Selector()
|