Skip to content

Commit

Permalink
Fixed tests (#2203)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Aug 29, 2024
1 parent 6dd4af7 commit 1dfc531
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/components/src/theme/ThemeUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import {
ThemePreloadColorVariable,
ThemeRegistrationData,
THEME_CACHE_LOCAL_STORAGE_KEY,
THEME_KEY_OVERRIDE_QUERY_PARAM,
} from './ThemeModel';
import {
calculatePreloadStyleContent,
createCssVariableResolver,
extractDistinctCssVariableExpressions,
getActiveThemes,
getDefaultBaseThemes,
getDefaultSelectedThemeKey,
getExpressionRanges,
getThemeKey,
getThemePreloadData,
Expand Down Expand Up @@ -239,6 +241,44 @@ describe('getActiveThemes', () => {
});
});

describe('getDefaultSelectedThemeKey', () => {
const origLocation = window.location;

beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete window.location;
window.location = {
search: '',
} as unknown as Location;
});

afterEach(() => {
window.location = origLocation;
});

it.each([
['overrideKey', 'preloadKey', 'overrideKey'],
[undefined, 'preloadKey', 'preloadKey'],
[undefined, undefined, DEFAULT_DARK_THEME_KEY],
])(
'should coalesce overide key -> preload key -> default key: %s, %s, %s',
(overrideKey, preloadKey, expected) => {
if (overrideKey != null) {
window.location.search = `?${THEME_KEY_OVERRIDE_QUERY_PARAM}=${overrideKey}`;
}

localStorage.setItem(
THEME_CACHE_LOCAL_STORAGE_KEY,
JSON.stringify({ themeKey: preloadKey })
);

const actual = getDefaultSelectedThemeKey();
expect(actual).toEqual(expected);
}
);
});

describe('getExpressionRanges', () => {
const testCases = [
['Single expression', '#ffffff', [[0, 6]]],
Expand Down

0 comments on commit 1dfc531

Please sign in to comment.