mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-11 15:27:04 +00:00
efb7b3d872
The save action has been implemented, and it is listened to by the canonical enabled state in the previews reducer, and by the settings reducer to perform UI changes. The enabled state of the application has been kept in the preview reducer as the canonical source of truth. See supporting changes for documentation about the decision. Actions: * Introduce new action SETTINGS_CHANGE with the enabled status * Trigger that action when clicking Save in the settings dialog Reducers: * Listen to SETTINGS_CHANGE in the preview reducer to update enabled status * On the settings reducer * Handle the SETTINGS_CHANGE action * Add showHelp flag to determine if the help should be showing Change listeners: * Switch to compare past vs present changes in the implementation * Handle showing and hiding the help Supporting changes: * On the rendered settings dialog: * Change #hide to actually just hide and remove legacy if statement * Add #toggleHelp method to show or hide the help dialog * Add doc/adr/0003-keep-enabled-state-only-in-preview-reducer.md to support the decision of making the saveSettings action creator return a Redux.Thunk and keeping the enabled state just in the preview reducer. * Add NB to actions#saveSettings explaining and linking to the document Follow commits soon: * Persist the settings change to local storage when it changes, and unify with the preview change listener Change-Id: I80dc5f29fbe6286f2e3e3b50d909894bc5041ccd
186 lines
3.4 KiB
JavaScript
186 lines
3.4 KiB
JavaScript
( function ( mw, $ ) {
|
|
|
|
QUnit.module( 'ext.popups/reducers#preview', {
|
|
setup: function () {
|
|
this.el = $( '<a>' );
|
|
}
|
|
} );
|
|
|
|
QUnit.test( '@@INIT', function ( assert ) {
|
|
var state = mw.popups.reducers.preview( undefined, { type: '@@INIT' } );
|
|
|
|
assert.expect( 1 );
|
|
|
|
assert.deepEqual(
|
|
state,
|
|
{
|
|
enabled: undefined,
|
|
activeLink: undefined,
|
|
activeEvent: undefined,
|
|
shouldShow: false,
|
|
isUserDwelling: false
|
|
}
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'BOOT', function ( assert ) {
|
|
var action = {
|
|
type: 'BOOT',
|
|
user: {
|
|
isInCondition: true
|
|
}
|
|
};
|
|
|
|
assert.expect( 1 );
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.preview( {}, action ),
|
|
{
|
|
enabled: true
|
|
},
|
|
'It should set whether or not previews are enabled.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'SETTINGS_CHANGE', function ( assert ) {
|
|
var action = {
|
|
type: 'SETTINGS_CHANGE',
|
|
enabled: true
|
|
};
|
|
|
|
assert.expect( 1 );
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.preview( {}, action ),
|
|
{
|
|
enabled: true
|
|
},
|
|
'It should set whether or not previews are enabled when settings change.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'LINK_DWELL', function ( assert ) {
|
|
var action = {
|
|
type: 'LINK_DWELL',
|
|
el: this.el,
|
|
event: {}
|
|
};
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.preview( {}, action ),
|
|
{
|
|
activeLink: action.el,
|
|
activeEvent: action.event,
|
|
shouldShow: false
|
|
},
|
|
'It should set active link and event as well as interaction info and hide the preview.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'LINK_ABANDON_END', function ( assert ) {
|
|
var action = {
|
|
type: 'LINK_ABANDON_END',
|
|
el: this.el
|
|
},
|
|
state = {
|
|
activeLink: this.el
|
|
};
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.preview( state, action ),
|
|
{
|
|
activeLink: undefined,
|
|
activeEvent: undefined,
|
|
fetchResponse: undefined,
|
|
shouldShow: false
|
|
},
|
|
'It should hide the preview and reset the interaction info.'
|
|
);
|
|
|
|
// ---
|
|
|
|
state = {
|
|
activeLink: this.el,
|
|
isUserDwelling: true
|
|
};
|
|
|
|
assert.equal(
|
|
mw.popups.reducers.preview( state, action ),
|
|
state,
|
|
'It should NOOP if the user is dwelling on the preview.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'FETCH_END', function ( assert ) {
|
|
var state = {
|
|
activeLink: this.el
|
|
},
|
|
action = {
|
|
type: 'FETCH_END',
|
|
el: this.el,
|
|
result: {}
|
|
};
|
|
|
|
assert.expect( 2 );
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.preview( state, action ),
|
|
{
|
|
activeLink: state.activeLink, // Previous state.
|
|
|
|
fetchResponse: action.result,
|
|
shouldShow: true
|
|
},
|
|
'It should store the result and signal that a preview should be rendered.'
|
|
);
|
|
|
|
// ---
|
|
|
|
state = {
|
|
activeLink: $( '<a>' )
|
|
};
|
|
action = {
|
|
type: 'FETCH_END',
|
|
el: this.el,
|
|
result: {}
|
|
};
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.preview( state, action ),
|
|
state,
|
|
'It should NOOP if the user has interacted with another link since the request was dispatched via the gateway.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'PREVIEW_DWELL', function ( assert ) {
|
|
var action = {
|
|
type: 'PREVIEW_DWELL'
|
|
};
|
|
|
|
assert.expect( 1 );
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.preview( {}, action ),
|
|
{
|
|
isUserDwelling: true
|
|
},
|
|
'It should mark the preview as being dwelled on.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'PREVIEW_ABANDON_START', function ( assert ) {
|
|
var action = {
|
|
type: 'PREVIEW_ABANDON_START'
|
|
};
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.preview( {}, action ),
|
|
{
|
|
isUserDwelling: false
|
|
},
|
|
'It should mark the preview having been abandoned.'
|
|
);
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|