2022-02-21 21:03:07 +00:00
|
|
|
const mustache = require( 'mustache' );
|
|
|
|
const fs = require( 'fs' );
|
|
|
|
const stickyHeaderTemplate = fs.readFileSync( 'includes/templates/StickyHeader.mustache', 'utf8' );
|
|
|
|
const buttonTemplate = fs.readFileSync( 'includes/templates/Button.mustache', 'utf8' );
|
2023-04-25 16:53:19 +00:00
|
|
|
const iconTemplate = fs.readFileSync( 'includes/templates/Icon.mustache', 'utf8' );
|
2023-04-10 19:31:50 +00:00
|
|
|
const sticky = require( '../../resources/skins.vector.js/stickyHeader.js' );
|
2022-11-02 23:00:04 +00:00
|
|
|
const { userLinksHTML, dropdownPartials } = require( './userLinksData.js' );
|
2022-02-21 21:03:07 +00:00
|
|
|
|
|
|
|
const defaultButtonsTemplateData = [ {
|
|
|
|
href: '#',
|
|
|
|
id: 'ca-talk-sticky-header',
|
2023-04-25 16:53:19 +00:00
|
|
|
icon: 'speechBubbles',
|
|
|
|
class: 'mw-ui-button mw-ui-quiet mw-ui-icon-element sticky-header-icon',
|
|
|
|
'array-attributes': [ {
|
|
|
|
key: 'data-event-name',
|
|
|
|
value: 'talk-sticky-header'
|
|
|
|
}, {
|
|
|
|
key: 'tabindex',
|
|
|
|
value: '-1'
|
|
|
|
} ]
|
2022-02-21 21:03:07 +00:00
|
|
|
}, {
|
|
|
|
href: '#',
|
|
|
|
id: 'ca-history-sticky-header',
|
2023-04-25 16:53:19 +00:00
|
|
|
icon: 'history',
|
|
|
|
class: 'mw-ui-button mw-ui-quiet mw-ui-icon-element sticky-header-icon',
|
|
|
|
'array-attributes': [ {
|
|
|
|
key: 'data-event-name',
|
|
|
|
value: 'history-sticky-header'
|
|
|
|
}, {
|
|
|
|
key: 'tabindex',
|
|
|
|
value: '-1'
|
|
|
|
} ]
|
2022-02-21 21:03:07 +00:00
|
|
|
}, {
|
|
|
|
href: '#',
|
|
|
|
id: 'ca-watchstar-sticky-header',
|
2023-04-25 16:53:19 +00:00
|
|
|
icon: 'star',
|
|
|
|
class: 'mw-ui-button mw-ui-quiet mw-ui-icon-element sticky-header-icon mw-watchlink',
|
|
|
|
'array-attributes': [ {
|
|
|
|
key: 'data-event-name',
|
|
|
|
value: 'watch-sticky-header'
|
|
|
|
}, {
|
|
|
|
key: 'tabindex',
|
|
|
|
value: '-1'
|
|
|
|
} ]
|
2022-02-21 21:03:07 +00:00
|
|
|
} ];
|
|
|
|
|
|
|
|
const editButtonsTemplateData = [ {
|
|
|
|
href: '#',
|
|
|
|
id: 'ca-ve-edit-sticky-header',
|
2023-04-25 16:53:19 +00:00
|
|
|
icon: 'edit',
|
|
|
|
class: 'mw-ui-button mw-ui-quiet mw-ui-icon-element sticky-header-icon',
|
|
|
|
'array-attributes': [ {
|
|
|
|
key: 'data-event-name',
|
|
|
|
value: 've-edit-sticky-header'
|
|
|
|
}, {
|
|
|
|
key: 'tabindex',
|
|
|
|
value: '-1'
|
|
|
|
} ]
|
2022-02-21 21:03:07 +00:00
|
|
|
}, {
|
|
|
|
href: '#',
|
|
|
|
id: 'ca-edit-sticky-header',
|
2023-04-25 16:53:19 +00:00
|
|
|
icon: 'wikiText',
|
|
|
|
class: 'mw-ui-button mw-ui-quiet mw-ui-icon-element sticky-header-icon',
|
|
|
|
'array-attributes': [ {
|
|
|
|
key: 'data-event-name',
|
|
|
|
value: 'wikitext-edit-sticky-header'
|
|
|
|
}, {
|
|
|
|
key: 'tabindex',
|
|
|
|
value: '-1'
|
|
|
|
} ]
|
2022-02-21 21:03:07 +00:00
|
|
|
}, {
|
|
|
|
href: '#',
|
|
|
|
id: 'ca-viewsource-sticky-header',
|
2023-04-25 16:53:19 +00:00
|
|
|
icon: 'star',
|
|
|
|
class: 'mw-ui-button mw-ui-quiet mw-ui-icon-element sticky-header-icon',
|
|
|
|
'array-attributes': [ {
|
|
|
|
key: 'data-event-name',
|
|
|
|
value: 'editLock'
|
|
|
|
}, {
|
|
|
|
key: 'tabindex',
|
|
|
|
value: '-1'
|
|
|
|
} ]
|
2022-02-21 21:03:07 +00:00
|
|
|
} ];
|
|
|
|
|
|
|
|
const templateData = {
|
2023-02-27 21:58:49 +00:00
|
|
|
'data-toc': {
|
|
|
|
'array-sections': []
|
|
|
|
},
|
2023-01-06 01:21:22 +00:00
|
|
|
'data-sticky-header-toc-dropdown': {
|
2022-10-20 21:32:07 +00:00
|
|
|
id: 'vector-sticky-header-toc',
|
2022-07-01 20:19:57 +00:00
|
|
|
class: 'mw-portlet mw-portlet-sticky-header-toc vector-sticky-header-toc',
|
|
|
|
'html-items': '',
|
|
|
|
'html-vector-menu-checkbox-attributes': 'tabindex="-1"',
|
|
|
|
'html-vector-menu-heading-attributes': 'tabindex="-1"',
|
|
|
|
'heading-class': 'mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-listBullet'
|
|
|
|
},
|
2023-04-25 16:53:19 +00:00
|
|
|
'array-buttons': [ {
|
2022-02-21 21:03:07 +00:00
|
|
|
label: '0 languages',
|
2023-04-25 16:53:19 +00:00
|
|
|
id: 'p-lang-btn-sticky-header',
|
|
|
|
class: 'mw-ui-button mw-ui-quiet mw-interlanguage-selector',
|
|
|
|
'array-attributes': [ {
|
|
|
|
key: 'data-event-name',
|
|
|
|
value: 'ui.dropdown-p-lang-btn-sticky-header'
|
|
|
|
}, {
|
|
|
|
key: 'tabindex',
|
|
|
|
value: '-1'
|
|
|
|
} ]
|
2023-01-30 15:33:57 +00:00
|
|
|
} ],
|
2022-02-21 21:03:07 +00:00
|
|
|
'data-button-start': {
|
|
|
|
label: 'search',
|
2023-04-25 16:53:19 +00:00
|
|
|
icon: 'search',
|
|
|
|
class: 'mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element vector-sticky-header-search-toggle',
|
|
|
|
'array-attributes': [ {
|
|
|
|
key: 'data-event-name',
|
|
|
|
value: 'ui.vector-sticky-search-form.icon'
|
|
|
|
}, {
|
|
|
|
key: 'tabindex',
|
|
|
|
value: '-1'
|
|
|
|
} ]
|
2022-02-21 21:03:07 +00:00
|
|
|
},
|
|
|
|
'data-search': {},
|
2023-04-25 16:53:19 +00:00
|
|
|
'array-icon-buttons': defaultButtonsTemplateData.concat( editButtonsTemplateData )
|
2022-02-21 21:03:07 +00:00
|
|
|
};
|
|
|
|
|
2022-10-20 21:32:07 +00:00
|
|
|
const renderedHTML = mustache.render(
|
|
|
|
stickyHeaderTemplate, templateData, Object.assign( {}, dropdownPartials, {
|
|
|
|
Button: buttonTemplate,
|
2023-04-25 16:53:19 +00:00
|
|
|
Icon: iconTemplate,
|
2022-10-20 21:32:07 +00:00
|
|
|
SearchBox: '<div> </div>' // ignore SearchBox for this test
|
|
|
|
} ) );
|
2022-02-21 21:03:07 +00:00
|
|
|
|
|
|
|
beforeEach( () => {
|
|
|
|
document.body.innerHTML = renderedHTML;
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'Sticky header renders', () => {
|
|
|
|
expect( document.body.innerHTML ).toMatchSnapshot();
|
|
|
|
} );
|
2022-02-18 16:47:44 +00:00
|
|
|
|
|
|
|
describe( 'sticky header', () => {
|
2023-02-16 17:06:22 +00:00
|
|
|
test( 'prepareUserLinksDropdown removes gadgets from dropdown', async () => {
|
2022-02-18 16:47:44 +00:00
|
|
|
const menu = document.createElement( 'div' );
|
2022-02-21 21:03:07 +00:00
|
|
|
menu.innerHTML = userLinksHTML;
|
2023-02-16 17:06:22 +00:00
|
|
|
const userLinksDropdown = /** @type {Element} */ ( menu.querySelector( '#' + sticky.USER_LINKS_DROPDOWN_ID ) );
|
|
|
|
const newMenu = sticky.prepareUserLinksDropdown( userLinksDropdown );
|
2022-02-18 16:47:44 +00:00
|
|
|
// check classes have been updated and removed.
|
2023-02-16 17:06:22 +00:00
|
|
|
expect( userLinksDropdown.querySelectorAll( '.user-links-collapsible-item' ).length > 0 ).toBeTruthy();
|
|
|
|
expect( userLinksDropdown.querySelectorAll( '.mw-list-item-js' ).length > 0 ).toBeTruthy();
|
2022-02-18 16:47:44 +00:00
|
|
|
expect( newMenu.querySelectorAll( '.user-links-collapsible-item' ).length ).toBe( 0 );
|
|
|
|
expect( newMenu.querySelectorAll( '.mw-list-item-js' ).length ).toBe( 0 );
|
|
|
|
} );
|
|
|
|
} );
|