Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Devtools): Support for persist, lock, pause #955

Merged
merged 12 commits into from
Aug 24, 2018
Merged
107 changes: 90 additions & 17 deletions modules/store-devtools/spec/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,101 @@
import { ActionReducer, Action } from '@ngrx/store';
import { StoreDevtoolsConfig } from '../';
import {
createConfig,
StoreDevtoolsConfig,
noMonitor,
DEFAULT_NAME,
} from '../src/config';

const defaultFeatures = {
pause: true,
lock: true,
persist: true,
export: true,
import: 'custom',
jump: true,
skip: true,
reorder: true,
dispatch: true,
test: true,
};

describe('StoreDevtoolsOptions', () => {
it('can be initialized with name', () => {
const options = new StoreDevtoolsConfig();
options.name = 'my instance';
expect(options.name).toBe('my instance');
it('creates default options with empty object given', () => {
const config = createConfig({});
expect(config).toEqual({
maxAge: false,
monitor: noMonitor,
actionSanitizer: undefined,
stateSanitizer: undefined,
name: DEFAULT_NAME,
serialize: false,
logOnly: false,
features: defaultFeatures,
});
});

it('can be initialized with actionSanitizer', () => {
const options = new StoreDevtoolsConfig();
function sanitizer(action: Action, id: number): Action {
it('creates options that contain passed in options', () => {
function stateSanitizer(state: any, index: number): any {
return state;
}
function actionSanitizer(action: Action, id: number): Action {
return action;
}
options.actionSanitizer = sanitizer;
expect(options.actionSanitizer).toEqual(sanitizer);
const config = createConfig({
maxAge: 20,
actionSanitizer,
stateSanitizer,
name: 'ABC',
serialize: true,
features: {
test: true,
},
});
expect(config).toEqual({
maxAge: 20,
monitor: noMonitor,
actionSanitizer,
stateSanitizer,
name: 'ABC',
serialize: true,
logOnly: false,
features: {
test: true,
},
});
});

it('can be initialized with stateSanitizer', () => {
const options = new StoreDevtoolsConfig();
function stateSanitizer(state: any, index: number): any {
return state;
}
options.stateSanitizer = stateSanitizer;
expect(options.stateSanitizer).toEqual(stateSanitizer);
it('can be initialized with a function returning options', () => {
const config = createConfig(() => ({ maxAge: 15 }));
expect(config).toEqual({
maxAge: 15,
monitor: noMonitor,
actionSanitizer: undefined,
stateSanitizer: undefined,
name: DEFAULT_NAME,
serialize: false,
logOnly: false,
features: defaultFeatures,
});
});

it('logOnly will set features', () => {
const config = createConfig({
logOnly: true,
});
expect(config).toEqual({
maxAge: false,
monitor: noMonitor,
actionSanitizer: undefined,
stateSanitizer: undefined,
name: DEFAULT_NAME,
serialize: false,
logOnly: true,
features: {
pause: true,
export: true,
test: true,
},
});
});
});
Loading