2024-02-08 22:52:46 +00:00
|
|
|
'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();
|
2024-03-18 19:14:23 +00:00
|
|
|
userOptionsEnabled.set( 'minerva-theme', 'night' );
|
2024-02-08 22:52:46 +00:00
|
|
|
const userOptionsDisabled = new Map();
|
2024-03-18 19:14:23 +00:00
|
|
|
userOptionsDisabled.set( 'minerva-theme', 'day' );
|
2024-02-08 22:52:46 +00:00
|
|
|
const userOptionsAutomatic = new Map();
|
2024-03-18 19:14:23 +00:00
|
|
|
userOptionsAutomatic.set( 'minerva-theme', 'os' );
|
2024-02-08 22:52:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
};
|
2024-06-03 12:06:43 +00:00
|
|
|
window.matchMedia = () => ( {
|
|
|
|
matches: true
|
|
|
|
} );
|
2024-02-08 22:52:46 +00:00
|
|
|
expect( reportIfNightModeWasDisabledOnPage( nightModeDisabledDoc ) ).toBe( true );
|
2024-06-03 12:06:43 +00:00
|
|
|
window.matchMedia = () => ( {
|
|
|
|
matches: false
|
|
|
|
} );
|
2024-02-08 22:52:46 +00:00
|
|
|
expect( reportIfNightModeWasDisabledOnPage( nightModeDisabledDoc ) ).toBe( false );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'reads from cookie for anons', () => {
|
|
|
|
global.mw = {
|
|
|
|
msg,
|
|
|
|
notify,
|
|
|
|
cookie: {
|
2024-03-18 19:14:23 +00:00
|
|
|
get: () => 'skin-theme-clientpref-night'
|
2024-02-08 22:52:46 +00:00
|
|
|
},
|
|
|
|
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 );
|
|
|
|
} );
|
|
|
|
} );
|