-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-devtools): add support for persist, lock, pause (#955)
- Loading branch information
1 parent
8a5e041
commit 93fcf56
Showing
10 changed files
with
583 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.