mediawiki-skins-Vector/tests/jest/skins.vector.clientPreferences.test.js
Jon Robson 8c49b1eb49 Client preferences supports toggle switches
Bug: T350418
Change-Id: I359924874e7232eaee73b7dc3678b9e8e26794ac
2024-01-19 12:56:27 -08:00

60 lines
1.7 KiB
JavaScript

const clientPreferences = require( '../../resources/skins.vector.clientPreferences/clientPreferences.js' );
let cp;
describe( 'clientPreferences', () => {
beforeEach( () => {
document.body.innerHTML = '';
cp = document.createElement( 'div' );
cp.id = 'cp';
document.body.appendChild( cp );
mw.requestIdleCallback = ( callback ) => callback();
mw.user.clientPrefs = {
get: jest.fn( () => '1' )
};
const portlet = document.createElement( 'div' );
mw.util.addPortlet = jest.fn( () => portlet );
mw.util.addPortletLink = jest.fn( () => {
const li = document.createElement( 'li' );
const a = document.createElement( 'a' );
li.appendChild( a );
portlet.appendChild( li );
return li;
} );
mw.message = jest.fn( ( key ) => ( {
text: () => `msg:${ key }`,
exists: () => true
} ) );
} );
test( 'render empty', () => {
return clientPreferences.render( '#cp', {} ).then( () => {
expect( cp.innerHTML ).toMatchSnapshot();
} );
} );
test( 'render font size', () => {
document.documentElement.setAttribute( 'class', 'vector-feature-custom-font-size-clientpref-2' );
return clientPreferences.render( '#cp', {
'vector-feature-custom-font-size': {
options: [ '0', '1', '2' ],
preferenceKey: 'vector-font-size'
}
} ).then( () => {
expect( cp.innerHTML ).toMatchSnapshot();
} );
} );
test( 'render toggle', () => {
document.documentElement.setAttribute( 'class', 'expandAll-clientpref-1' );
return clientPreferences.render( '#cp', {
expandAll: {
options: [ '0', '1' ],
preferenceKey: 'expandAll',
type: 'switch'
}
} ).then( () => {
expect( cp.innerHTML ).toMatchSnapshot();
} );
} );
} );