mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.5 KiB
72 lines
1.5 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { State } from './state';
|
|
|
|
describe('State', () => {
|
|
let state: State<any>;
|
|
|
|
beforeEach(() => {
|
|
state = new State<any>({});
|
|
});
|
|
|
|
it('should update state with new value', () => {
|
|
let updateCount = 0;
|
|
|
|
state.changes.subscribe(() => {
|
|
updateCount++;
|
|
});
|
|
|
|
const updated = state.next({ value: 1 });
|
|
|
|
expect(updateCount).toEqual(2);
|
|
expect(updated).toBeTruthy();
|
|
});
|
|
|
|
it('should reset state with new value', () => {
|
|
let updateCount = 0;
|
|
|
|
state.changes.subscribe(() => {
|
|
updateCount++;
|
|
});
|
|
|
|
const updated = state.resetState({ value: 1 });
|
|
|
|
expect(updateCount).toEqual(2);
|
|
expect(updated).toBeTruthy();
|
|
});
|
|
|
|
it('should not update state when nothing changed', () => {
|
|
let updateCount = 0;
|
|
|
|
state.changes.subscribe(() => {
|
|
updateCount++;
|
|
});
|
|
|
|
state.next({ value: 1 });
|
|
|
|
const updated = state.next({ value: 1 });
|
|
|
|
expect(updateCount).toEqual(2);
|
|
expect(updated).toBeFalsy();
|
|
});
|
|
|
|
it('should not reset state when nothing changed', () => {
|
|
let updateCount = 0;
|
|
|
|
state.changes.subscribe(() => {
|
|
updateCount++;
|
|
});
|
|
|
|
state.resetState({ value: 1 });
|
|
|
|
const updated = state.resetState({ value: 1 });
|
|
|
|
expect(updateCount).toEqual(2);
|
|
expect(updated).toBeFalsy();
|
|
});
|
|
});
|