mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-25 05:22:57 +00:00
883c8c1aca
Change-Id: I055517998ed06fccdf50ec31251ea6aa9040abb5
62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
import nextState from '../../../src/reducers/nextState';
|
|
|
|
QUnit.module( 'reducers/nextState' );
|
|
|
|
QUnit.test( 'with scalar values', ( assert ) => {
|
|
const tests = [
|
|
{
|
|
before: {},
|
|
updates: {},
|
|
after: {}
|
|
},
|
|
{
|
|
before: { unchanged: true, changed: false },
|
|
updates: { new: true, changed: true },
|
|
after: { unchanged: true, changed: true, new: true }
|
|
},
|
|
{
|
|
before: { a: { b: { unchanged: true, changed: false } } },
|
|
updates: { a: { b: { new: true, changed: true } } },
|
|
after: { a: { b: { unchanged: true, changed: true, new: true } } }
|
|
}
|
|
];
|
|
for ( const i in tests ) {
|
|
const test = tests[ i ];
|
|
assert.deepEqual(
|
|
nextState( test.before, test.updates ),
|
|
test.after,
|
|
'Test case #' + i
|
|
);
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'original state object should not change', ( assert ) => {
|
|
const state = {},
|
|
after = nextState( state, { changed: true } );
|
|
assert.deepEqual(
|
|
state,
|
|
{},
|
|
'original state is unchanged'
|
|
);
|
|
assert.deepEqual(
|
|
after,
|
|
{ changed: true },
|
|
'new state is different'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'Element instances should not be cloned', ( assert ) => {
|
|
const element = document.createElement( 'a' ),
|
|
newElement = document.createElement( 'b' ),
|
|
state = { element },
|
|
after = nextState( state, { element: newElement } );
|
|
assert.strictEqual(
|
|
state.element, element,
|
|
'original state is unchanged'
|
|
);
|
|
assert.strictEqual(
|
|
after.element, newElement,
|
|
'Element instance was not cloned'
|
|
);
|
|
} );
|