@ngxs/store 3.8.1-dev.master-98beeea → 3.8.1-dev.master-22c3643

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.
Files changed (65) hide show
  1. package/package.json +2 -1
  2. package/schematics/collection.json +36 -0
  3. package/schematics/src/actions/actions.factory.d.ts +3 -0
  4. package/schematics/src/actions/actions.factory.js +22 -0
  5. package/schematics/src/actions/actions.factory.js.map +1 -0
  6. package/schematics/src/actions/files/__name__.actions.ts__template__ +4 -0
  7. package/schematics/src/actions/schema.json +28 -0
  8. package/schematics/src/ng-add/ng-add.factory.d.ts +3 -0
  9. package/schematics/src/ng-add/ng-add.factory.js +84 -0
  10. package/schematics/src/ng-add/ng-add.factory.js.map +1 -0
  11. package/schematics/src/ng-add/schema.json +72 -0
  12. package/schematics/src/starter-kit/files/store/auth/auth.actions.ts__template__ +7 -0
  13. package/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ +46 -0
  14. package/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ +45 -0
  15. package/schematics/src/starter-kit/files/store/dashboard/index.ts__template__ +11 -0
  16. package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.actions.ts__template__ +13 -0
  17. package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.spec.ts__template__ +77 -0
  18. package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.ts__template__ +60 -0
  19. package/schematics/src/starter-kit/files/store/dashboard/states/user/user.actions.ts__template__ +6 -0
  20. package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ +54 -0
  21. package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ +40 -0
  22. package/schematics/src/starter-kit/files/store/store.config.ts__template__ +38 -0
  23. package/schematics/src/starter-kit/files/store/store.module.ts__template__ +22 -0
  24. package/schematics/src/starter-kit/schema.json +18 -0
  25. package/schematics/src/starter-kit/starter-kit.factory.d.ts +3 -0
  26. package/schematics/src/starter-kit/starter-kit.factory.js +12 -0
  27. package/schematics/src/starter-kit/starter-kit.factory.js.map +1 -0
  28. package/schematics/src/state/files/__name__.state.spec.ts__template__ +22 -0
  29. package/schematics/src/state/files/__name__.state.ts__template__ +20 -0
  30. package/schematics/src/state/schema.json +33 -0
  31. package/schematics/src/state/state.factory.d.ts +3 -0
  32. package/schematics/src/state/state.factory.js +20 -0
  33. package/schematics/src/state/state.factory.js.map +1 -0
  34. package/schematics/src/store/files/__name__.actions.ts__template__ +4 -0
  35. package/schematics/src/store/files/__name__.state.spec.ts__template__ +24 -0
  36. package/schematics/src/store/files/__name__.state.ts__template__ +27 -0
  37. package/schematics/src/store/schema.json +33 -0
  38. package/schematics/src/store/store.factory.d.ts +3 -0
  39. package/schematics/src/store/store.factory.js +20 -0
  40. package/schematics/src/store/store.factory.js.map +1 -0
  41. package/schematics/src/utils/common/lib.config.d.ts +10 -0
  42. package/schematics/src/utils/common/lib.config.js +15 -0
  43. package/schematics/src/utils/common/lib.config.js.map +1 -0
  44. package/schematics/src/utils/common/project-files.config.d.ts +3 -0
  45. package/schematics/src/utils/common/project-files.config.js +7 -0
  46. package/schematics/src/utils/common/project-files.config.js.map +1 -0
  47. package/schematics/src/utils/common/properties.d.ts +1 -0
  48. package/schematics/src/utils/common/properties.js +8 -0
  49. package/schematics/src/utils/common/properties.js.map +1 -0
  50. package/schematics/src/utils/config.d.ts +119 -0
  51. package/schematics/src/utils/config.js +21 -0
  52. package/schematics/src/utils/config.js.map +1 -0
  53. package/schematics/src/utils/generate-utils.d.ts +4 -0
  54. package/schematics/src/utils/generate-utils.js +14 -0
  55. package/schematics/src/utils/generate-utils.js.map +1 -0
  56. package/schematics/src/utils/interfaces/package.interface.d.ts +7 -0
  57. package/schematics/src/utils/interfaces/package.interface.js +3 -0
  58. package/schematics/src/utils/interfaces/package.interface.js.map +1 -0
  59. package/schematics/src/utils/normalize-options.d.ts +9 -0
  60. package/schematics/src/utils/normalize-options.js +24 -0
  61. package/schematics/src/utils/normalize-options.js.map +1 -0
  62. package/schematics/src/utils/project.d.ts +17 -0
  63. package/schematics/src/utils/project.js +32 -0
  64. package/schematics/src/utils/project.js.map +1 -0
  65. package/schematics/src/utils/versions.json +3 -0
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@ngxs/store",
3
- "version": "3.8.1-dev.master-98beeea",
3
+ "version": "3.8.1-dev.master-22c3643",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "@angular/core": ">=12.0.0 <17.0.0",
8
8
  "rxjs": ">=6.5.5"
9
9
  },
10
+ "schematics": "./schematics/collection.json",
10
11
  "module": "fesm2015/ngxs-store.mjs",
11
12
  "es2020": "fesm2020/ngxs-store.mjs",
12
13
  "esm2020": "esm2020/ngxs-store.mjs",
@@ -0,0 +1,36 @@
1
+ {
2
+ "extends": ["@schematics/angular"],
3
+ "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
4
+ "schematics": {
5
+ "store": {
6
+ "factory": "./src/store/store.factory#store",
7
+ "description": "Create a NGXS full store",
8
+ "aliases": ["ngxs-store"],
9
+ "schema": "./src/store/schema.json"
10
+ },
11
+ "state": {
12
+ "factory": "./src/state/state.factory#state",
13
+ "description": "Create a NGXS state",
14
+ "aliases": ["ngxs-state"],
15
+ "schema": "./src/state/schema.json"
16
+ },
17
+ "actions": {
18
+ "factory": "./src/actions/actions.factory#actions",
19
+ "description": "Create a NGXS actions",
20
+ "aliases": ["ngxs-actions"],
21
+ "schema": "./src/actions/schema.json"
22
+ },
23
+ "starter-kit": {
24
+ "factory": "./src/starter-kit/starter-kit.factory#starterKit",
25
+ "description": "Create a NGXS starter kit with simple or best practice type",
26
+ "aliases": ["ngxs-sk"],
27
+ "schema": "./src/starter-kit/schema.json"
28
+ },
29
+ "ng-add": {
30
+ "factory": "./src/ng-add/ng-add.factory#ngAdd",
31
+ "description": "Add Ngxs Store and plugins in package.json",
32
+ "aliases": ["ngxs-init"],
33
+ "schema": "./src/ng-add/schema.json"
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,3 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ import { ActionsSchema } from './actions.schema';
3
+ export declare function actions(options: ActionsSchema): Rule;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.actions = void 0;
4
+ const schematics_1 = require("@angular-devkit/schematics");
5
+ const generate_utils_1 = require("../utils/generate-utils");
6
+ const properties_1 = require("../utils/common/properties");
7
+ const normalize_options_1 = require("../utils/normalize-options");
8
+ const path_1 = require("path");
9
+ function actions(options) {
10
+ if ((0, properties_1.isEmpty)(options.name)) {
11
+ throw new schematics_1.SchematicsException('Invalid options, "name" is required.');
12
+ }
13
+ const normalizedOptions = (0, normalize_options_1.normalizeBaseOptions)(options);
14
+ const path = options.flat
15
+ ? normalizedOptions.path
16
+ : (0, path_1.join)(normalizedOptions.path, normalizedOptions.name);
17
+ return (0, generate_utils_1.generateFiles)((0, schematics_1.url)('./files'), path, {
18
+ name: normalizedOptions.name
19
+ });
20
+ }
21
+ exports.actions = actions;
22
+ //# sourceMappingURL=actions.factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.factory.js","sourceRoot":"","sources":["../../../../../packages/store/schematics/src/actions/actions.factory.ts"],"names":[],"mappings":";;;AAAA,2DAA4E;AAE5E,4DAAwD;AACxD,2DAAqD;AACrD,kEAAkE;AAClE,+BAA4B;AAE5B,SAAgB,OAAO,CAAC,OAAsB;IAC5C,IAAI,IAAA,oBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,gCAAmB,CAAC,sCAAsC,CAAC,CAAC;KACvE;IAED,MAAM,iBAAiB,GAAG,IAAA,wCAAoB,EAAC,OAAO,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI;QACvB,CAAC,CAAC,iBAAiB,CAAC,IAAI;QACxB,CAAC,CAAC,IAAA,WAAI,EAAC,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAEzD,OAAO,IAAA,8BAAa,EAAC,IAAA,gBAAG,EAAC,SAAS,CAAC,EAAE,IAAI,EAAE;QACzC,IAAI,EAAE,iBAAiB,CAAC,IAAI;KAC7B,CAAC,CAAC;AACL,CAAC;AAbD,0BAaC"}
@@ -0,0 +1,4 @@
1
+ export class <%= classify(name) %>Action {
2
+ public static readonly type = '[<%= classify(name) %>] Add item';
3
+ constructor(public payload: any) { }
4
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "SchematicsNgxsActions",
4
+ "title": "Ngxs Actions Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "description": "The name of the actions.",
9
+ "type": "string",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the actions?"
15
+ },
16
+ "path": {
17
+ "type": "string",
18
+ "format": "path",
19
+ "description": "The path to create the actions."
20
+ },
21
+ "flat": {
22
+ "type": "boolean",
23
+ "default": false,
24
+ "description": "Flag to indicate if a dir is created."
25
+ }
26
+ },
27
+ "required": ["name"]
28
+ }
@@ -0,0 +1,3 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ import { NgxsPackageSchema } from './ng-add.schema';
3
+ export declare function ngAdd(options: NgxsPackageSchema): Rule;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ngAdd = void 0;
4
+ const schematics_1 = require("@angular-devkit/schematics");
5
+ const tasks_1 = require("@angular-devkit/schematics/tasks");
6
+ const ts = require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript");
7
+ const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
8
+ const change_1 = require("@schematics/angular/utility/change");
9
+ const dependencies_1 = require("@schematics/angular/utility/dependencies");
10
+ const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
11
+ const lib_config_1 = require("../utils/common/lib.config");
12
+ const project_1 = require("../utils/project");
13
+ const versions = require('./../utils/versions.json');
14
+ function ngAdd(options) {
15
+ return (0, schematics_1.chain)([
16
+ addNgxsPackageToPackageJson(options),
17
+ addDeclarationToNgModule(options),
18
+ options.skipInstall ? (0, schematics_1.noop)() : runNpmPackageInstall()
19
+ ]);
20
+ }
21
+ exports.ngAdd = ngAdd;
22
+ function addNgxsPackageToPackageJson(options) {
23
+ return (host, context) => {
24
+ const ngxsStoreVersion = versions['@ngxs/store'];
25
+ if (!ngxsStoreVersion) {
26
+ throw new schematics_1.SchematicsException('Could not resolve the version of "@ngxs/store"');
27
+ }
28
+ Object.values(lib_config_1.LIBRARIES)
29
+ .filter(lib => { var _a; return (_a = options.plugins) === null || _a === void 0 ? void 0 : _a.includes(lib); })
30
+ .forEach(name => {
31
+ const packageExists = (0, dependencies_1.getPackageJsonDependency)(host, name);
32
+ if (packageExists === null) {
33
+ (0, dependencies_1.addPackageJsonDependency)(host, {
34
+ type: dependencies_1.NodeDependencyType.Default,
35
+ name,
36
+ version: ngxsStoreVersion
37
+ });
38
+ context.logger.info(`✅️ Added "${name}" into ${dependencies_1.NodeDependencyType.Default}`);
39
+ }
40
+ else {
41
+ context.logger.warn(`✅️ "${name}" already exists in the ${dependencies_1.NodeDependencyType.Default}`);
42
+ }
43
+ });
44
+ return host;
45
+ };
46
+ }
47
+ function runNpmPackageInstall() {
48
+ return (_, context) => {
49
+ context.addTask(new tasks_1.NodePackageInstallTask());
50
+ context.logger.info(`🔍 Installing packages...`);
51
+ };
52
+ }
53
+ function addDeclarationToNgModule(options) {
54
+ return (host) => {
55
+ const project = (0, project_1.getProject)(host, { project: options.project });
56
+ if (typeof project === 'undefined' || project === null) {
57
+ const message = options.project
58
+ ? `Project "${options.project}" does not exist.`
59
+ : 'Could not determine the project to update.';
60
+ throw new schematics_1.SchematicsException(message);
61
+ }
62
+ const modulePath = (0, ng_ast_utils_1.getAppModulePath)(host, `${project.root}/src/main.ts`);
63
+ if (typeof modulePath === 'undefined') {
64
+ throw new schematics_1.SchematicsException(`Module path for project "${options.project}" does not exist.`);
65
+ }
66
+ const importPath = '@ngxs/store';
67
+ const moduleImport = 'NgxsModule.forRoot([], { developmentMode: /** !environment.production */ false, selectorOptions: { suppressErrors: false, injectContainerState: false } })';
68
+ const sourceBuffer = host.read(modulePath);
69
+ if (sourceBuffer !== null) {
70
+ const sourceText = sourceBuffer.toString();
71
+ const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
72
+ const changes = (0, ast_utils_1.addImportToModule)(source, modulePath, moduleImport, importPath);
73
+ const recorder = host.beginUpdate(modulePath);
74
+ for (const change of changes) {
75
+ if (change instanceof change_1.InsertChange) {
76
+ recorder.insertLeft(change.pos, change.toAdd);
77
+ }
78
+ }
79
+ host.commitUpdate(recorder);
80
+ }
81
+ return host;
82
+ };
83
+ }
84
+ //# sourceMappingURL=ng-add.factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ng-add.factory.js","sourceRoot":"","sources":["../../../../../packages/store/schematics/src/ng-add/ng-add.factory.ts"],"names":[],"mappings":";;;AAAA,2DAOoC;AACpC,4DAA0E;AAC1E,qGAAqG;AACrG,qEAA0E;AAC1E,+DAAkE;AAClE,2EAIkD;AAClD,2EAA4E;AAE5E,2DAAuD;AACvD,8CAA8C;AAI9C,MAAM,QAAQ,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAErD,SAAgB,KAAK,CAAC,OAA0B;IAC9C,OAAO,IAAA,kBAAK,EAAC;QACX,2BAA2B,CAAC,OAAO,CAAC;QACpC,wBAAwB,CAAC,OAAO,CAAC;QACjC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAA,iBAAI,GAAE,CAAC,CAAC,CAAC,oBAAoB,EAAE;KACtD,CAAC,CAAC;AACL,CAAC;AAND,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AI,MAAM,YAAY,qBAAY,EAAE;oBAClC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;iBAC/C;aACF;YACD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;SAC7B;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,72 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "SchematicsNgxsNgAdd",
4
+ "title": "Ngxs NgAdd Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "skipInstall": {
8
+ "type": "boolean",
9
+ "description": "The flag for skipping packages installation.",
10
+ "default": false,
11
+ "x-prompt": "Do you want to skip packages installation?"
12
+ },
13
+ "plugins": {
14
+ "type": "array",
15
+ "description": "Additional plugins to be added to the workspace.",
16
+ "minItems": 0,
17
+ "maxItems": 7,
18
+ "items": {
19
+ "type": "string",
20
+ "enum": [
21
+ "@ngxs/devtools-plugin",
22
+ "@ngxs/form-plugin",
23
+ "@ngxs/hmr-plugin",
24
+ "@ngxs/logger-plugin",
25
+ "@ngxs/router-plugin",
26
+ "@ngxs/storage-plugin",
27
+ "@ngxs/websocket-plugin"
28
+ ]
29
+ },
30
+ "default": [],
31
+ "x-prompt": {
32
+ "message": "Choose any other @ngxs plugins you would like to add to the workspace.",
33
+ "type": "list",
34
+ "items": [
35
+ {
36
+ "value": "@ngxs/devtools-plugin",
37
+ "label": "Ngxs developer tools plugin"
38
+ },
39
+ {
40
+ "value": "@ngxs/form-plugin",
41
+ "label": "Ngxs form plugin"
42
+ },
43
+ {
44
+ "value": "@ngxs/hmr-plugin",
45
+ "label": "Ngxs HMR plugin"
46
+ },
47
+ {
48
+ "value": "@ngxs/logger-plugin",
49
+ "label": "Ngxs logger plugin"
50
+ },
51
+ {
52
+ "value": "@ngxs/router-plugin",
53
+ "label": "Ngxs router plugin"
54
+ },
55
+ {
56
+ "value": "@ngxs/storage-plugin",
57
+ "label": "Ngxs storage plugin"
58
+ },
59
+ {
60
+ "value": "@ngxs/websocket-plugin",
61
+ "label": "Ngxs websocket plugin"
62
+ }
63
+ ]
64
+ }
65
+ },
66
+ "project": {
67
+ "type": "string",
68
+ "description": "The name of the project."
69
+ }
70
+ },
71
+ "required": []
72
+ }
@@ -0,0 +1,7 @@
1
+ import { AuthenticationStateModel } from './auth.state';
2
+
3
+ export class SetAuthData {
4
+ public static readonly type = '[Auth] Auth data';
5
+
6
+ constructor(public payload: AuthenticationStateModel) {}
7
+ }
@@ -0,0 +1,46 @@
1
+ import { NgxsModule, Store } from '@ngxs/store';
2
+ import { async, TestBed } from '@angular/core/testing';
3
+ import { AuthenticationStateModel, AuthStateModule } from './auth.state';
4
+ import { SetAuthData } from './auth.actions';
5
+
6
+ describe('[TEST]: AuthStore', () => {
7
+ let store: Store;
8
+
9
+ beforeEach(async(() => {
10
+ TestBed.configureTestingModule({
11
+ imports: [NgxsModule.forRoot([AuthStateModule])]
12
+ })
13
+ .compileComponents()
14
+ .then();
15
+ store = TestBed.get(Store);
16
+ }));
17
+
18
+ it('Should be correct dispatch and value is empty', () => {
19
+ const Authentication: AuthenticationStateModel = {
20
+ id: '',
21
+ firstName: '',
22
+ lastName: '',
23
+ fullName: '',
24
+ email: '',
25
+ roles: []
26
+ };
27
+ store.dispatch(new SetAuthData(Authentication));
28
+ const actual = store.selectSnapshot<AuthenticationStateModel>(AuthStateModule.getAuthData);
29
+ expect(actual).toEqual(Authentication);
30
+ });
31
+
32
+ it('Should be correct dispatch and next value is correct completed', () => {
33
+ const authentication: AuthenticationStateModel = {
34
+ id: '12',
35
+ firstName: 'Adam',
36
+ lastName: 'Gordon',
37
+ fullName: 'Adam Gordon',
38
+ email: 'agordon@google.com',
39
+ roles: ['ADMIN']
40
+ };
41
+
42
+ store.dispatch(new SetAuthData(authentication));
43
+ const actual = store.selectSnapshot<AuthenticationStateModel>(AuthStateModule.getAuthData);
44
+ expect(actual).toEqual(authentication);
45
+ });
46
+ });
@@ -0,0 +1,45 @@
1
+ import { Action, Selector, State, StateContext } from '@ngxs/store';
2
+ import { SetAuthData } from './auth.actions';
3
+
4
+ export interface AuthenticationStateModel {
5
+ id: string;
6
+ firstName: string;
7
+ lastName: string;
8
+ fullName: string;
9
+ email: string;
10
+ roles: string[];
11
+ }
12
+
13
+ @State<AuthenticationStateModel>({
14
+ name: 'authStateModule',
15
+ defaults: {
16
+ id: '',
17
+ firstName: '',
18
+ lastName: '',
19
+ fullName: '',
20
+ email: '',
21
+ roles: []
22
+ }
23
+ })
24
+ export class AuthStateModule {
25
+ @Selector()
26
+ public static getAuthData(state: AuthenticationStateModel): AuthenticationStateModel {
27
+ return AuthStateModule.getInstanceState(state);
28
+ }
29
+
30
+ private static setInstanceState(state: AuthenticationStateModel): AuthenticationStateModel {
31
+ return { ...state };
32
+ }
33
+
34
+ private static getInstanceState(state: AuthenticationStateModel): AuthenticationStateModel {
35
+ return { ...state };
36
+ }
37
+
38
+ @Action(SetAuthData)
39
+ public setAuthData(
40
+ { setState }: StateContext<AuthenticationStateModel>,
41
+ { payload }: SetAuthData
42
+ ) {
43
+ setState(AuthStateModule.setInstanceState(payload));
44
+ }
45
+ }
@@ -0,0 +1,11 @@
1
+ import { State } from '@ngxs/store';
2
+ import { DictionaryState } from './states/dictionary/dictionary.state';
3
+ import { UserState } from './states/user/user.state';
4
+
5
+ export const DashboardStates = [DictionaryState, UserState];
6
+
7
+ @State({
8
+ name: 'dashboardStateModule',
9
+ children: DashboardStates
10
+ })
11
+ export class DashboardStateModule {}
@@ -0,0 +1,13 @@
1
+ import { DictionaryStateModel } from './dictionary.state';
2
+
3
+ export class SetDictionaryData {
4
+ public static readonly type = '[Dictionary] Set dictionary data action';
5
+
6
+ constructor(public payload: DictionaryStateModel) {}
7
+ }
8
+
9
+ export class DictionaryReset {
10
+ public static readonly type = '[Dictionary] Reset dictionary action';
11
+
12
+ constructor() {}
13
+ }
@@ -0,0 +1,77 @@
1
+ import { NgxsModule, Store } from '@ngxs/store';
2
+ import { async, TestBed } from '@angular/core/testing';
3
+ import { DictionaryState, DictionaryStateModel } from './dictionary.state';
4
+ import { DictionaryReset, SetDictionaryData } from './dictionary.actions';
5
+
6
+ const data = [
7
+ {
8
+ id: '323',
9
+ departmentCode: '2392',
10
+ departmentName: 'Main office',
11
+ mainCuratorUserId: 'admin',
12
+ mainCuratorName: 'Adam Gordon',
13
+ backupCuratorUserId: 'manager',
14
+ backupCuratorName: 'Alexander Chester'
15
+ },
16
+ {
17
+ id: '322',
18
+ departmentCode: '2999',
19
+ departmentName: 'New York office',
20
+ mainCuratorUserId: 'manager',
21
+ mainCuratorName: 'Alexander Chester',
22
+ backupCuratorUserId: 'manager',
23
+ backupCuratorName: 'Amanda Brian'
24
+ }
25
+ ];
26
+
27
+ describe('[TEST]: Dictionary state', () => {
28
+ let store: Store;
29
+
30
+ beforeEach(async(() => {
31
+ TestBed.configureTestingModule({
32
+ imports: [NgxsModule.forRoot([DictionaryState])]
33
+ })
34
+ .compileComponents()
35
+ .then();
36
+ store = TestBed.get(Store);
37
+ }));
38
+
39
+ it('Should be correct dispatch and dictionary is empty', () => {
40
+ const dictionary: DictionaryStateModel = {
41
+ content: [],
42
+ page: 0,
43
+ size: 0,
44
+ totalPages: 0,
45
+ totalElements: 0
46
+ };
47
+ store.dispatch(new SetDictionaryData(dictionary));
48
+ const actual = store.selectSnapshot(DictionaryState.getDictionaryState);
49
+ expect(actual).toEqual(dictionary);
50
+ });
51
+
52
+ it('Should be state is filled DictionaryStateModel', () => {
53
+ const dictionary: DictionaryStateModel = {
54
+ content: data,
55
+ page: 0,
56
+ size: 20,
57
+ totalPages: 2,
58
+ totalElements: 1
59
+ };
60
+ store.dispatch(new SetDictionaryData(dictionary));
61
+ const actual = store.selectSnapshot(DictionaryState.getDictionaryState);
62
+ expect(actual).toEqual(dictionary);
63
+ });
64
+
65
+ it('should be reset state', function () {
66
+ const dictionary: DictionaryStateModel = {
67
+ content: [],
68
+ page: 0,
69
+ size: 0,
70
+ totalPages: 0,
71
+ totalElements: 0
72
+ };
73
+ store.dispatch(new DictionaryReset());
74
+ const actual = store.selectSnapshot(DictionaryState.getDictionaryState);
75
+ expect(actual).toEqual(dictionary);
76
+ });
77
+ });
@@ -0,0 +1,60 @@
1
+ import { Action, Selector, State, StateContext } from '@ngxs/store';
2
+ import { DictionaryReset, SetDictionaryData } from './dictionary.actions';
3
+
4
+ export interface DictionaryStateModel {
5
+ content: any[];
6
+ page: number;
7
+ size: number;
8
+ totalPages: number;
9
+ totalElements: number;
10
+ }
11
+
12
+ @State<DictionaryStateModel>({
13
+ name: 'dictionary',
14
+ defaults: {
15
+ content: [],
16
+ page: 0,
17
+ size: 0,
18
+ totalPages: 0,
19
+ totalElements: 0
20
+ }
21
+ })
22
+ export class DictionaryState {
23
+ @Selector()
24
+ public static getDictionaryState(state: DictionaryStateModel): DictionaryStateModel {
25
+ return DictionaryState.getInstanceState(state);
26
+ }
27
+
28
+ @Selector()
29
+ public static getDictionaryContent(state: DictionaryStateModel) {
30
+ return state.content;
31
+ }
32
+
33
+ private static setInstanceState(state: DictionaryStateModel): DictionaryStateModel {
34
+ return { ...state };
35
+ }
36
+
37
+ private static getInstanceState(state: DictionaryStateModel): DictionaryStateModel {
38
+ return { ...state };
39
+ }
40
+
41
+ @Action(SetDictionaryData)
42
+ public setTasks(
43
+ { setState }: StateContext<DictionaryStateModel>,
44
+ { payload }: SetDictionaryData
45
+ ) {
46
+ setState(DictionaryState.setInstanceState(payload));
47
+ }
48
+
49
+ @Action(DictionaryReset)
50
+ public resetTasks({ setState }: StateContext<DictionaryStateModel>) {
51
+ const initialState = {
52
+ content: [],
53
+ page: 0,
54
+ size: 0,
55
+ totalPages: 0,
56
+ totalElements: 0
57
+ };
58
+ setState(initialState);
59
+ }
60
+ }
@@ -0,0 +1,6 @@
1
+ import { PersonStateModel } from './user.state';
2
+
3
+ export class SetUser {
4
+ public static readonly type = '[SetUser] action';
5
+ constructor(public payload: PersonStateModel) {}
6
+ }
@@ -0,0 +1,54 @@
1
+ import { NgxsModule, Store } from '@ngxs/store';
2
+ import { async, TestBed } from '@angular/core/testing';
3
+ import { PersonStateModel, UserState } from './user.state';
4
+ import { SetUser } from './user.actions';
5
+
6
+ describe('[TEST]: User state', () => {
7
+ let store: Store;
8
+
9
+ beforeEach(async(() => {
10
+ TestBed.configureTestingModule({
11
+ imports: [NgxsModule.forRoot([UserState])]
12
+ })
13
+ .compileComponents()
14
+ .then();
15
+ store = TestBed.get(Store);
16
+ }));
17
+
18
+ it('Should be state is PersonStateModel', () => {
19
+ const person: PersonStateModel = {
20
+ userId: '',
21
+ departmentCode: '',
22
+ departmentName: '',
23
+ email: '',
24
+ firstName: '',
25
+ lastName: '',
26
+ fullName: '',
27
+ positionId: '',
28
+ positionName: ''
29
+ };
30
+ store.dispatch(new SetUser(person));
31
+ const actual = store.selectSnapshot(({ user }) => user);
32
+
33
+ expect(actual).toEqual(person);
34
+ });
35
+
36
+ it('Should be state is filled PersonStateModel', () => {
37
+ const person: PersonStateModel = {
38
+ userId: '12',
39
+ departmentCode: '2392',
40
+ departmentName: 'Main office',
41
+ email: 'agordon@google.com',
42
+ firstName: 'Adam',
43
+ lastName: 'Gordon',
44
+ fullName: 'Adam Gordon',
45
+ positionId: '102003',
46
+ positionName: 'admin'
47
+ };
48
+
49
+ store.dispatch(new SetUser(person));
50
+ const actual = store.selectSnapshot<PersonStateModel>(({ user }) => user);
51
+
52
+ expect(actual).toEqual(person);
53
+ });
54
+ });
@@ -0,0 +1,40 @@
1
+ import { Action, Selector, State, StateContext } from '@ngxs/store';
2
+ import { SetUser } from './user.actions';
3
+
4
+ export interface PersonStateModel {
5
+ userId: string;
6
+ email: string;
7
+ firstName: string;
8
+ lastName: string;
9
+ fullName: string;
10
+ positionId: string;
11
+ positionName: string;
12
+ departmentCode: string;
13
+ departmentName: string;
14
+ }
15
+
16
+ @State<PersonStateModel>({
17
+ name: 'user',
18
+ defaults: {
19
+ userId: '',
20
+ email: '',
21
+ firstName: '',
22
+ lastName: '',
23
+ fullName: '',
24
+ positionId: '',
25
+ positionName: '',
26
+ departmentCode: '',
27
+ departmentName: ''
28
+ }
29
+ })
30
+ export class UserState {
31
+ @Selector()
32
+ public static getUser(state: PersonStateModel): PersonStateModel {
33
+ return state;
34
+ }
35
+
36
+ @Action(SetUser)
37
+ public setUser(ctx: StateContext<PersonStateModel>, { payload }: SetUser) {
38
+ ctx.setState(payload);
39
+ }
40
+ }