2017-07-28 17:32:46 +00:00
|
|
|
import settings from '../../../src/reducers/settings';
|
2018-07-13 15:12:49 +00:00
|
|
|
import actionTypes from '../../../src/actionTypes';
|
2017-02-01 11:09:42 +00:00
|
|
|
|
|
|
|
QUnit.module( 'reducers/settings' );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '@@INIT', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const state = settings( undefined, { type: '@@INIT' } );
|
2017-02-01 11:09:42 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
shouldShow: false,
|
2023-10-19 21:12:09 +00:00
|
|
|
previewTypesEnabled: {},
|
2017-02-01 11:09:42 +00:00
|
|
|
showHelp: false,
|
|
|
|
shouldShowFooterLink: false
|
2018-05-08 19:48:17 +00:00
|
|
|
},
|
|
|
|
'The initial state doesn\'t show, doesn\'t show help, and doesn\'t show a footer link.'
|
2017-02-01 11:09:42 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2021-05-07 11:18:51 +00:00
|
|
|
QUnit.test( 'BOOT with a single disabled popup type', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const action = {
|
2018-07-13 15:12:49 +00:00
|
|
|
type: actionTypes.BOOT,
|
2021-04-07 10:23:05 +00:00
|
|
|
initiallyEnabled: { page: false },
|
2021-05-07 11:18:51 +00:00
|
|
|
user: { isAnon: true }
|
2017-02-01 11:09:42 +00:00
|
|
|
};
|
|
|
|
assert.deepEqual(
|
2023-10-19 21:12:09 +00:00
|
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
|
|
true,
|
2018-05-08 19:48:17 +00:00
|
|
|
'The boot state shows a footer link.'
|
2017-02-01 11:09:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
action.user.isAnon = false;
|
|
|
|
assert.deepEqual(
|
2023-10-19 21:12:09 +00:00
|
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
|
|
false,
|
2017-02-01 11:09:42 +00:00
|
|
|
'If the user is logged in, then it doesn\'t signal that the footer link should be shown.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2021-05-07 11:18:51 +00:00
|
|
|
QUnit.test( 'BOOT with multiple popup types', ( assert ) => {
|
|
|
|
const action = {
|
|
|
|
type: actionTypes.BOOT,
|
|
|
|
initiallyEnabled: { page: true, reference: null },
|
|
|
|
user: { isAnon: true }
|
|
|
|
};
|
|
|
|
assert.deepEqual(
|
2023-10-19 21:12:09 +00:00
|
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
|
|
false,
|
2021-05-07 11:18:51 +00:00
|
|
|
'Footer link ignores unavailable popup types.'
|
|
|
|
);
|
|
|
|
|
|
|
|
action.initiallyEnabled.reference = true;
|
|
|
|
assert.deepEqual(
|
2023-10-19 21:12:09 +00:00
|
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
|
|
false,
|
2021-05-07 11:18:51 +00:00
|
|
|
'Footer link is pointless when there is nothing to enable.'
|
|
|
|
);
|
|
|
|
|
|
|
|
action.initiallyEnabled.reference = false;
|
|
|
|
assert.deepEqual(
|
2023-10-19 21:12:09 +00:00
|
|
|
settings( {}, action ).shouldShowFooterLink,
|
|
|
|
true,
|
2021-05-07 11:18:51 +00:00
|
|
|
'Footer link appears when at least one popup type is disabled.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2023-10-19 21:12:09 +00:00
|
|
|
QUnit.test( 'REGISTER_SETTING that is disabled by default reveals footer link', ( assert ) => {
|
|
|
|
const REGISTER_SETTING_FOO_DISABLED = {
|
|
|
|
type: actionTypes.REGISTER_SETTING,
|
|
|
|
name: 'foo',
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
const newState = settings( {
|
|
|
|
previewTypesEnabled: {},
|
|
|
|
shouldShowFooterLink: false
|
|
|
|
}, REGISTER_SETTING_FOO_DISABLED );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
newState.shouldShowFooterLink,
|
|
|
|
true,
|
|
|
|
'if one setting is registered as disabled, then the footer link is revealed.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'REGISTER_SETTING that is enabled by default should not show footer link', ( assert ) => {
|
|
|
|
const REGISTER_SETTING_FOO_ENABLED = {
|
|
|
|
type: actionTypes.REGISTER_SETTING,
|
|
|
|
name: 'foo',
|
|
|
|
enabled: true
|
|
|
|
};
|
|
|
|
const newState = settings( {
|
|
|
|
previewTypesEnabled: {},
|
|
|
|
shouldShowFooterLink: false
|
|
|
|
}, REGISTER_SETTING_FOO_ENABLED );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
newState.previewTypesEnabled.foo,
|
|
|
|
true,
|
|
|
|
'previewTypesEnabled is updated'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'SETTINGS_SHOW', ( assert ) => {
|
2017-02-01 11:09:42 +00:00
|
|
|
assert.deepEqual(
|
2018-07-13 15:12:49 +00:00
|
|
|
settings( {}, { type: actionTypes.SETTINGS_SHOW } ),
|
2017-02-01 11:09:42 +00:00
|
|
|
{
|
|
|
|
shouldShow: true,
|
|
|
|
showHelp: false
|
|
|
|
},
|
|
|
|
'It should mark the settings dialog as ready to be shown, with no help.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'SETTINGS_HIDE', ( assert ) => {
|
2017-02-01 11:09:42 +00:00
|
|
|
assert.deepEqual(
|
2018-07-13 15:12:49 +00:00
|
|
|
settings( {}, { type: actionTypes.SETTINGS_HIDE } ),
|
2017-02-01 11:09:42 +00:00
|
|
|
{
|
|
|
|
shouldShow: false,
|
|
|
|
showHelp: false
|
|
|
|
},
|
|
|
|
'It should mark the settings dialog as ready to be closed, and hide help.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2021-04-22 16:35:50 +00:00
|
|
|
QUnit.test( 'SETTINGS_CHANGE with page previews only', ( assert ) => {
|
2021-03-31 08:51:54 +00:00
|
|
|
const action = ( oldValue, newValue ) => {
|
2017-02-01 11:09:42 +00:00
|
|
|
return {
|
2018-07-13 15:12:49 +00:00
|
|
|
type: actionTypes.SETTINGS_CHANGE,
|
2021-04-15 07:20:00 +00:00
|
|
|
oldValue: { page: oldValue },
|
|
|
|
newValue: { page: newValue }
|
2017-02-01 11:09:42 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
settings( {}, action( false, false ) ),
|
|
|
|
{ shouldShow: false },
|
|
|
|
'It should just hide the settings dialog when enabled state stays the same.'
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
settings( {}, action( true, true ) ),
|
|
|
|
{ shouldShow: false },
|
|
|
|
'It should just hide the settings dialog when enabled state stays the same.'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
settings( {}, action( false, true ) ),
|
|
|
|
{
|
|
|
|
shouldShow: false,
|
|
|
|
showHelp: false,
|
|
|
|
shouldShowFooterLink: false
|
|
|
|
},
|
|
|
|
'It should hide the settings dialog and help when we enable.'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
settings( {}, action( true, false ) ),
|
|
|
|
{
|
|
|
|
shouldShow: true,
|
|
|
|
showHelp: true,
|
|
|
|
shouldShowFooterLink: true
|
|
|
|
},
|
|
|
|
'It should keep the settings showing and show the help when we disable.'
|
|
|
|
);
|
2021-04-22 16:35:50 +00:00
|
|
|
} );
|
2017-02-01 11:09:42 +00:00
|
|
|
|
2021-04-22 16:35:50 +00:00
|
|
|
QUnit.test( 'SETTINGS_CHANGE with two preview types', ( assert ) => {
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'All are disabled but nothing changed',
|
|
|
|
false, false, false, false,
|
|
|
|
{ shouldShow: false }
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'All are enabled but nothing changed',
|
|
|
|
true, true, true, true,
|
|
|
|
{ shouldShow: false }
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'One is enabled but nothing changed',
|
|
|
|
false, false, true, true,
|
|
|
|
{ shouldShow: false }
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Only one got disabled',
|
|
|
|
true, true, true, false,
|
|
|
|
{ shouldShow: true, showHelp: true, shouldShowFooterLink: true }
|
|
|
|
],
|
2021-05-07 11:18:51 +00:00
|
|
|
[
|
|
|
|
'One got disabled, the other enabled',
|
|
|
|
false, true, true, false,
|
|
|
|
{ shouldShow: true, showHelp: true, shouldShowFooterLink: true }
|
|
|
|
],
|
2021-04-22 16:35:50 +00:00
|
|
|
[
|
|
|
|
'Both got disabled',
|
|
|
|
true, false, true, false,
|
|
|
|
{ shouldShow: true, showHelp: true, shouldShowFooterLink: true }
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Only one got enabled',
|
|
|
|
false, false, false, true,
|
|
|
|
{ shouldShow: false, showHelp: false, shouldShowFooterLink: true }
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Both got enabled',
|
|
|
|
false, true, false, true,
|
|
|
|
{ shouldShow: false, showHelp: false, shouldShowFooterLink: false }
|
|
|
|
]
|
2021-05-07 11:18:51 +00:00
|
|
|
].forEach( ( [
|
|
|
|
message,
|
|
|
|
pageBefore,
|
|
|
|
pageAfter,
|
|
|
|
referenceBefore,
|
|
|
|
referenceAfter,
|
|
|
|
expected
|
|
|
|
] ) => {
|
2021-04-22 16:35:50 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
settings( {}, {
|
|
|
|
type: actionTypes.SETTINGS_CHANGE,
|
2021-05-07 11:18:51 +00:00
|
|
|
oldValue: { page: pageBefore, reference: referenceBefore },
|
|
|
|
newValue: { page: pageAfter, reference: referenceAfter }
|
2021-04-22 16:35:50 +00:00
|
|
|
} ),
|
2021-05-07 11:18:51 +00:00
|
|
|
expected,
|
|
|
|
message
|
2021-04-22 16:35:50 +00:00
|
|
|
);
|
|
|
|
} );
|
2017-02-01 11:09:42 +00:00
|
|
|
} );
|