Skip to content

Commit cd48467

Browse files
committed
test(scripts): update palette query
1 parent 3709bba commit cd48467

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

core/scripts/testing/scripts.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,19 @@
5757
* Values can be `light`, `dark`, `high-contrast`,
5858
* or `high-contrast-dark`. Default to `light` for tests.
5959
*/
60-
const paletteQuery = window.location.search.match(/palette=([a-z]+)/);
61-
const paletteHash = window.location.hash.match(/palette=([a-z]+)/);
60+
const validPalettes = ['light', 'dark', 'high-contrast', 'high-contrast-dark'];
61+
const paletteQuery = window.location.search.match(/palette=([a-z-]+)/);
62+
const paletteHash = window.location.hash.match(/palette=([a-z-]+)/);
6263
const darkClass = document.body?.classList.contains('ion-palette-dark') ? 'dark' : null;
64+
const highContrastClass = document.body?.classList.contains('ion-palette-high-contrast') ? 'high-contrast' : null;
65+
const highContrastDarkClass = darkClass && highContrastClass ? 'high-contrast-dark' : null;
6366

64-
const paletteName = paletteQuery?.[1] || paletteHash?.[1] || darkClass || 'light';
67+
let paletteName = paletteQuery?.[1] || paletteHash?.[1] || highContrastDarkClass || darkClass || highContrastClass || 'light';
68+
69+
if (!validPalettes.includes(paletteName)) {
70+
paletteName = 'light';
71+
console.warn(`Invalid palette name: ${paletteName}. Falling back to 'light' palette.`);
72+
}
6573

6674
if (paletteName !== 'light') {
6775
const linkTag = document.createElement('link');

0 commit comments

Comments
 (0)