Skip to content

Commit 93fcf56

Browse files
dummdidummbrandonroberts
authored andcommitted
feat(store-devtools): add support for persist, lock, pause (#955)
Closes #853, #919
1 parent 8a5e041 commit 93fcf56

File tree

10 files changed

+583
-148
lines changed

10 files changed

+583
-148
lines changed
Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,101 @@
11
import { ActionReducer, Action } from '@ngrx/store';
2-
import { StoreDevtoolsConfig } from '../';
2+
import {
3+
createConfig,
4+
StoreDevtoolsConfig,
5+
noMonitor,
6+
DEFAULT_NAME,
7+
} from '../src/config';
8+
9+
const defaultFeatures = {
10+
pause: true,
11+
lock: true,
12+
persist: true,
13+
export: true,
14+
import: 'custom',
15+
jump: true,
16+
skip: true,
17+
reorder: true,
18+
dispatch: true,
19+
test: true,
20+
};
321

422
describe('StoreDevtoolsOptions', () => {
5-
it('can be initialized with name', () => {
6-
const options = new StoreDevtoolsConfig();
7-
options.name = 'my instance';
8-
expect(options.name).toBe('my instance');
23+
it('creates default options with empty object given', () => {
24+
const config = createConfig({});
25+
expect(config).toEqual({
26+
maxAge: false,
27+
monitor: noMonitor,
28+
actionSanitizer: undefined,
29+
stateSanitizer: undefined,
30+
name: DEFAULT_NAME,
31+
serialize: false,
32+
logOnly: false,
33+
features: defaultFeatures,
34+
});
935
});
1036

11-
it('can be initialized with actionSanitizer', () => {
12-
const options = new StoreDevtoolsConfig();
13-
function sanitizer(action: Action, id: number): Action {
37+
it('creates options that contain passed in options', () => {
38+
function stateSanitizer(state: any, index: number): any {
39+
return state;
40+
}
41+
function actionSanitizer(action: Action, id: number): Action {
1442
return action;
1543
}
16-
options.actionSanitizer = sanitizer;
17-
expect(options.actionSanitizer).toEqual(sanitizer);
44+
const config = createConfig({
45+
maxAge: 20,
46+
actionSanitizer,
47+
stateSanitizer,
48+
name: 'ABC',
49+
serialize: true,
50+
features: {
51+
test: true,
52+
},
53+
});
54+
expect(config).toEqual({
55+
maxAge: 20,
56+
monitor: noMonitor,
57+
actionSanitizer,
58+
stateSanitizer,
59+
name: 'ABC',
60+
serialize: true,
61+
logOnly: false,
62+
features: {
63+
test: true,
64+
},
65+
});
1866
});
1967

20-
it('can be initialized with stateSanitizer', () => {
21-
const options = new StoreDevtoolsConfig();
22-
function stateSanitizer(state: any, index: number): any {
23-
return state;
24-
}
25-
options.stateSanitizer = stateSanitizer;
26-
expect(options.stateSanitizer).toEqual(stateSanitizer);
68+
it('can be initialized with a function returning options', () => {
69+
const config = createConfig(() => ({ maxAge: 15 }));
70+
expect(config).toEqual({
71+
maxAge: 15,
72+
monitor: noMonitor,
73+
actionSanitizer: undefined,
74+
stateSanitizer: undefined,
75+
name: DEFAULT_NAME,
76+
serialize: false,
77+
logOnly: false,
78+
features: defaultFeatures,
79+
});
80+
});
81+
82+
it('logOnly will set features', () => {
83+
const config = createConfig({
84+
logOnly: true,
85+
});
86+
expect(config).toEqual({
87+
maxAge: false,
88+
monitor: noMonitor,
89+
actionSanitizer: undefined,
90+
stateSanitizer: undefined,
91+
name: DEFAULT_NAME,
92+
serialize: false,
93+
logOnly: true,
94+
features: {
95+
pause: true,
96+
export: true,
97+
test: true,
98+
},
99+
});
27100
});
28101
});

0 commit comments

Comments
 (0)