Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/site/components/withNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const WithNavBar: FC = () => {
const toggleCurrentTheme = () =>
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');

const themeToggleAriaLabel =
resolvedTheme === 'dark'
Comment thread
avivkeller marked this conversation as resolved.
? t('components.common.themeToggle.light')
: t('components.common.themeToggle.dark');

const changeLanguage = (locale: SimpleLocaleConfig) =>
replace(pathname!, { locale: locale.code });

Expand All @@ -63,7 +68,7 @@ const WithNavBar: FC = () => {

<ThemeToggle
onClick={toggleCurrentTheme}
aria-label={t('components.common.themeToggle.label')}
aria-label={themeToggleAriaLabel}
/>

<LanguageDropdown
Expand Down
20 changes: 17 additions & 3 deletions apps/site/tests/e2e/general-behavior.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const locators = {
navLinksLocator: `[aria-label="${englishLocale.components.containers.navBar.controls.toggle}"] + div`,
// Global UI controls
languageDropdownName: englishLocale.components.common.languageDropdown.label,
themeToggleName: englishLocale.components.common.themeToggle.label,
// default light theme
Comment thread
ShubhamOulkar marked this conversation as resolved.
Outdated
themeToggleName: englishLocale.components.common.themeToggle.light,

// Search components (from Orama library)
searchButtonTag: 'orama-button',
Expand All @@ -22,7 +23,9 @@ const locators = {
};

const getTheme = (page: Page) =>
page.evaluate(() => document.documentElement.dataset.theme);
page.evaluate(
() => document.documentElement.dataset.theme as 'light' | 'dark'
);

const openLanguageMenu = async (page: Page) => {
const button = page.getByRole('button', {
Expand Down Expand Up @@ -70,11 +73,22 @@ test.describe('Node.js Website', () => {
await expect(themeToggle).toBeVisible();

const initialTheme = await getTheme(page);
const initialAriaLabel = await themeToggle.getAttribute('aria-label');
expect(initialAriaLabel).toBe(
englishLocale.components.common.themeToggle[initialTheme]
Comment thread
ShubhamOulkar marked this conversation as resolved.
Outdated
);

await themeToggle.click();

const newTheme = await getTheme(page);
expect(newTheme).not.toEqual(initialTheme);
const newAriaLabel = await themeToggle.getAttribute('aria-label');

expect(newTheme).not.toBe(initialTheme);
expect(['light', 'dark']).toContain(newTheme);

expect(newAriaLabel).toBe(
englishLocale.components.common.themeToggle[newTheme]
);
});

test('should persist theme across page navigation', async ({ page }) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@
"label": "Choose Language"
},
"themeToggle": {
"label": "Toggle Dark Mode"
"light": "Switch to Light Mode",
"dark": "Switch to Dark Mode"
}
},
"metabar": {
Expand Down