mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-11 22:06:07 +00:00
5d6b866890
The classes: - skin-night-mode-clientpref-0 - skin-night-mode-clientpref-1 - skin-night-mode-clientpref-2 is being replaced with - skin-theme-clientpref-day - skin-theme-clientpref-night - skin-theme-clientpref-os - Moved $forceNightMode to be a text parameter (dat|night|os) - Keep adding the old classes to the html element, to give the ability of gradual deployment The preference is renamed from minerva-night-mode to minerva-theme (a follow up to consider migrating existing values will follow). The query string minervanightmode continues to behave the same but now accepts other values such as day, night and os. Bug: T359983 Change-Id: Ia253de68f94236e7fe2219b736dd6084c64ce838
101 lines
2.6 KiB
JavaScript
101 lines
2.6 KiB
JavaScript
'use strict';
|
|
const reportIfNightModeWasDisabledOnPage = require(
|
|
'../../../resources/skins.minerva.scripts/reportIfNightModeWasDisabledOnPage.js'
|
|
);
|
|
const nightModeDisabledDoc = document.createElement( 'html' );
|
|
nightModeDisabledDoc.setAttribute( 'class', 'skin-night-mode-page-disabled' );
|
|
|
|
const userOptionsEnabled = new Map();
|
|
userOptionsEnabled.set( 'minerva-theme', 'night' );
|
|
const userOptionsDisabled = new Map();
|
|
userOptionsDisabled.set( 'minerva-theme', 'day' );
|
|
const userOptionsAutomatic = new Map();
|
|
userOptionsAutomatic.set( 'minerva-theme', 'os' );
|
|
|
|
const notify = () => {};
|
|
const msg = () => {};
|
|
|
|
describe( 'reportIfNightModeWasDisabledOnPage.js', () => {
|
|
it( 'returns false if no skin-night-mode-page-disabled class is on the document element', () => {
|
|
global.mw = {};
|
|
expect( reportIfNightModeWasDisabledOnPage( document.createElement( 'html' ) ) ).toBe( false );
|
|
} );
|
|
|
|
it( 'shows notification for logged in users with night mode preferred, reading from options', () => {
|
|
global.mw = {
|
|
msg,
|
|
notify,
|
|
user: {
|
|
isNamed: () => true,
|
|
options: userOptionsEnabled
|
|
}
|
|
};
|
|
expect( reportIfNightModeWasDisabledOnPage( nightModeDisabledDoc ) ).toBe( true );
|
|
} );
|
|
|
|
it( 'shows no notification for logged in users with night mode disabled, reading from options', () => {
|
|
global.mw = {
|
|
msg,
|
|
notify,
|
|
user: {
|
|
isNamed: () => true,
|
|
options: userOptionsDisabled
|
|
}
|
|
};
|
|
expect( reportIfNightModeWasDisabledOnPage( nightModeDisabledDoc ) ).toBe( false );
|
|
} );
|
|
|
|
it( 'respects automatic mode when displaying a notification for logged in users', () => {
|
|
global.mw = {
|
|
msg,
|
|
notify,
|
|
user: {
|
|
isNamed: () => true,
|
|
options: userOptionsAutomatic
|
|
}
|
|
};
|
|
window.matchMedia = () => {
|
|
return {
|
|
matches: true
|
|
};
|
|
};
|
|
expect( reportIfNightModeWasDisabledOnPage( nightModeDisabledDoc ) ).toBe( true );
|
|
window.matchMedia = () => {
|
|
return {
|
|
matches: false
|
|
};
|
|
};
|
|
expect( reportIfNightModeWasDisabledOnPage( nightModeDisabledDoc ) ).toBe( false );
|
|
} );
|
|
|
|
it( 'reads from cookie for anons', () => {
|
|
global.mw = {
|
|
msg,
|
|
notify,
|
|
cookie: {
|
|
get: () => 'skin-theme-clientpref-night'
|
|
},
|
|
user: {
|
|
isNamed: () => false,
|
|
options: userOptionsDisabled
|
|
}
|
|
};
|
|
expect( reportIfNightModeWasDisabledOnPage( nightModeDisabledDoc ) ).toBe( true );
|
|
} );
|
|
|
|
it( 'reads from cookie for anons, can handle unset cookie', () => {
|
|
global.mw = {
|
|
msg,
|
|
notify,
|
|
cookie: {
|
|
get: () => null
|
|
},
|
|
user: {
|
|
isNamed: () => false,
|
|
options: userOptionsDisabled
|
|
}
|
|
};
|
|
expect( reportIfNightModeWasDisabledOnPage( nightModeDisabledDoc ) ).toBe( false );
|
|
} );
|
|
} );
|