-
Notifications
You must be signed in to change notification settings - Fork 21
[BOOKINGSG-9309][GZ] migrate language switcher to linaria css #1172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ghazwan-gt
wants to merge
11
commits into
pre-release/v4
Choose a base branch
from
BOOKINGSG-9309/language-switcher
base: pre-release/v4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a13dd81
[BOOKINGSG-9309][GZ] add visual test
ghazwanmuhammad 2f87d3f
[BOOKINGSG-9309][GZ] remove keyboard navigation from e2e
ghazwanmuhammad 26b1027
[BOOKINGSG-9309][GZ] rename styles filename
ghazwanmuhammad e483cb3
[BOOKINGSG-9309][GZ] migrated props interpolation
ghazwanmuhammad d5c1991
[BOOKINGSG-9309][GZ] migrated to linaria css
ghazwanmuhammad e6a673d
[BOOKINGSG-9309][GZ] rename internal component locators
ghazwanmuhammad 5605c15
[BOOKINGSG-9309][GZ] separate dropdown panel to be on its own
ghazwanmuhammad 8a31afc
[BOOKINGSG-9309][GZ] reorder csr component list
ghazwanmuhammad 44569c1
[BOOKINGSG-9309][GZ] remove default value for default
ghazwanmuhammad 414595e
[BOOKINGSG-9309][GZ] restructure e2e test and add dark mode
ghazwanmuhammad 33d0434
[BOOKINGSG-9309][GZ] add escape key to assert dropdown is collapsed
ghazwanmuhammad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
e2e/nextjs-app/src/app/components/language-switcher/dropdown-default.e2e.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| LanguageSwitcher, | ||
| type LanguageSwitcherCode, | ||
| } from "@lifesg/react-design-system/language-switcher"; | ||
| import { useState } from "react"; | ||
|
|
||
| export default function Story() { | ||
| const [language, setLanguage] = useState<LanguageSwitcherCode | undefined>( | ||
| undefined | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="story-row-container"> | ||
| <LanguageSwitcher | ||
| data-testid="language-switcher" | ||
| variant="dropdown" | ||
| selectedLanguage={language} | ||
| onSelectLanguage={setLanguage} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
22 changes: 22 additions & 0 deletions
22
e2e/nextjs-app/src/app/components/language-switcher/dropdown-preselected.e2e.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| LanguageSwitcher, | ||
| type LanguageSwitcherCode, | ||
| } from "@lifesg/react-design-system/language-switcher"; | ||
| import { useState } from "react"; | ||
|
|
||
| export default function Story() { | ||
| const [language, setLanguage] = useState<LanguageSwitcherCode>("zh"); | ||
|
|
||
| return ( | ||
| <div className="story-row-container"> | ||
| <LanguageSwitcher | ||
| data-testid="language-switcher" | ||
| variant="dropdown" | ||
| selectedLanguage={language} | ||
| onSelectLanguage={setLanguage} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
24 changes: 24 additions & 0 deletions
24
e2e/nextjs-app/src/app/components/language-switcher/link-default.e2e.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| LanguageSwitcher, | ||
| type LanguageSwitcherCode, | ||
| } from "@lifesg/react-design-system/language-switcher"; | ||
| import { useState } from "react"; | ||
|
|
||
| export default function Story() { | ||
| const [language, setLanguage] = useState<LanguageSwitcherCode | undefined>( | ||
| undefined | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="story-row-container"> | ||
| <LanguageSwitcher | ||
| data-testid="language-switcher" | ||
| variant="link-container" | ||
| selectedLanguage={language} | ||
| onSelectLanguage={setLanguage} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
e2e/nextjs-app/src/app/components/language-switcher/link-preselected.e2e.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| LanguageSwitcher, | ||
| type LanguageSwitcherCode, | ||
| } from "@lifesg/react-design-system/language-switcher"; | ||
| import { useState } from "react"; | ||
|
|
||
| export default function Story() { | ||
| const [language, setLanguage] = useState<LanguageSwitcherCode>("ta"); | ||
|
|
||
| return ( | ||
| <div className="story-row-container"> | ||
| <LanguageSwitcher | ||
| data-testid="language-switcher" | ||
| variant="link-container" | ||
| selectedLanguage={language} | ||
| onSelectLanguage={setLanguage} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
Binary file added
BIN
+2.04 KB
...-switcher/__screenshots__/chromium/LanguageSwitcher-Dropdown-Default--mount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.4 KB
...e-switcher/__screenshots__/chromium/LanguageSwitcher-Dropdown-Default--open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.08 KB
...__screenshots__/chromium/LanguageSwitcher-Dropdown-Default-Dark-Mode--mount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.6 KB
.../__screenshots__/chromium/LanguageSwitcher-Dropdown-Default-Dark-Mode--open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.84 KB
...tcher/__screenshots__/chromium/LanguageSwitcher-Dropdown-Preselected--mount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.35 KB
...uage-switcher/__screenshots__/chromium/LanguageSwitcher-Link-Default--mount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.35 KB
...-switcher/__screenshots__/chromium/LanguageSwitcher-Link-Preselected--mount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 changes: 180 additions & 0 deletions
180
e2e/tests/components/language-switcher/language-switcher.e2e.spec.ts
|
qroll marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| import { test as base, expect, Locator, Page } from "@playwright/test"; | ||
| import { AbstractStoryPage, compareScreenshot } from "../../utils"; | ||
|
|
||
| class StoryPage extends AbstractStoryPage { | ||
| protected readonly component = "language-switcher"; | ||
|
|
||
| public readonly locators: { | ||
| internal: { | ||
| trigger: Locator; | ||
| panel: Locator; | ||
| }; | ||
| languageSwitcher: Locator; | ||
| }; | ||
|
|
||
| constructor(page: Page) { | ||
| super(page); | ||
|
|
||
| this.locators = { | ||
| internal: { | ||
| trigger: page.getByTestId("language-switcher--trigger"), | ||
| panel: page.getByTestId("language-switcher--panel"), | ||
| }, | ||
| languageSwitcher: page.getByTestId("language-switcher"), | ||
| }; | ||
| } | ||
|
|
||
| public getDropdownOption(name: string) { | ||
| return this.page.getByRole("option", { name }); | ||
| } | ||
|
|
||
| public getLinkButton(name: string) { | ||
| return this.page.getByRole("button", { name, exact: true }); | ||
| } | ||
| } | ||
|
|
||
| const test = base.extend<{ story: StoryPage }>({ | ||
| story: async ({ page }, use) => { | ||
| const story = new StoryPage(page); | ||
| await use(story); | ||
| }, | ||
| }); | ||
|
|
||
| test.describe("LanguageSwitcher", () => { | ||
| test.describe("Dropdown", () => { | ||
| test.describe("", () => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("dropdown-default"); | ||
| }); | ||
|
|
||
| test("Default", async ({ story }) => { | ||
| await compareScreenshot(story, "mount", { | ||
| locator: story.locators.languageSwitcher, | ||
| }); | ||
|
|
||
| await expect(story.locators.languageSwitcher) | ||
| .toMatchAriaSnapshot(` | ||
| - combobox "Choose language / 选择语言 / Pilih bahasa / மொழியை தேர்ந்தெடுக்கவும், English" | ||
| `); | ||
|
|
||
| await story.locators.internal.trigger.click(); | ||
| await compareScreenshot(story, "open", { | ||
| fullscreen: true, | ||
| }); | ||
|
|
||
| await expect(story.locators.languageSwitcher) | ||
| .toMatchAriaSnapshot(` | ||
| - combobox "Choose language / 选择语言 / Pilih bahasa / மொழியை தேர்ந்தெடுக்கவும், English" [expanded] | ||
| - listbox "Choose language / 选择语言 / Pilih bahasa / மொழியை தேர்ந்தெடுக்கவும்": | ||
| - option "English" [selected] | ||
| - option "中文" | ||
| - option "Melayu" | ||
| - option "தமிழ்" | ||
| `); | ||
| }); | ||
|
|
||
| test("Keyboard Interaction", async ({ story }) => { | ||
| await story.locators.internal.trigger.focus(); | ||
| await story.page.keyboard.press("Enter"); | ||
| await expect(story.locators.internal.panel).toBeVisible(); | ||
|
|
||
| await story.page.keyboard.press("ArrowDown"); | ||
| await expect(story.getDropdownOption("中文")).toBeFocused(); | ||
|
|
||
| await story.page.keyboard.press("End"); | ||
| await expect(story.getDropdownOption("தமிழ்")).toBeFocused(); | ||
|
|
||
| await story.page.keyboard.press("Home"); | ||
| await expect(story.getDropdownOption("English")).toBeFocused(); | ||
|
|
||
| await story.page.keyboard.press("ArrowDown"); | ||
| await story.page.keyboard.press("Enter"); | ||
| await expect(story.locators.internal.panel).not.toBeVisible(); | ||
| await expect(story.locators.internal.trigger).toContainText( | ||
| "中文" | ||
| ); | ||
|
|
||
| await story.page.keyboard.press("Enter"); | ||
| await expect(story.locators.internal.panel).toBeVisible(); | ||
| await story.page.keyboard.press("Escape"); | ||
| await expect(story.locators.internal.panel).not.toBeVisible(); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe("", () => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("dropdown-default", { mode: "dark" }); | ||
| }); | ||
|
|
||
| test("Default Dark Mode", async ({ story }) => { | ||
| await compareScreenshot(story, "mount", { | ||
| locator: story.locators.languageSwitcher, | ||
| }); | ||
|
|
||
| await story.locators.internal.trigger.click(); | ||
| await compareScreenshot(story, "open", { | ||
| fullscreen: true, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe("", () => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("dropdown-preselected"); | ||
| }); | ||
|
|
||
| test("Preselected", async ({ story }) => { | ||
| await expect(story.locators.internal.trigger).toContainText( | ||
| "中文" | ||
| ); | ||
|
|
||
| await compareScreenshot(story, "mount", { | ||
| locator: story.locators.languageSwitcher, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe("Link", () => { | ||
| test.describe("", () => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("link-default"); | ||
| }); | ||
|
|
||
| test("Default", async ({ story }) => { | ||
| await expect(story.locators.languageSwitcher) | ||
| .toMatchAriaSnapshot(` | ||
| - group "Choose language / 选择语言 / Pilih bahasa / மொழியை தேர்ந்தெடுக்கவும்": | ||
| - listitem: | ||
| - button "English" [pressed] | ||
| - listitem: | ||
| - button "中文" | ||
| - listitem: | ||
| - button "Melayu" | ||
| - listitem: | ||
| - button "தமிழ்" | ||
| `); | ||
|
|
||
| await compareScreenshot(story, "mount", { | ||
| locator: story.locators.languageSwitcher, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe("", () => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("link-preselected"); | ||
| }); | ||
|
|
||
| test("Preselected", async ({ story }) => { | ||
| const tamil = story.getLinkButton("தமிழ்"); | ||
|
|
||
| await expect(tamil).toHaveAttribute("aria-pressed", "true"); | ||
|
|
||
| await compareScreenshot(story, "mount", { | ||
| locator: story.locators.languageSwitcher, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { css } from "@linaria/core"; | ||
|
|
||
| import { Border, Colour, Font, Radius, Spacing } from "../theme"; | ||
|
|
||
| export const tokens = { | ||
| width: "--fds-internal-languageSwitcher-dropdown-width", | ||
| } as const; | ||
|
|
||
| export const dropdownPanel = css` | ||
| ${tokens.width}: initial; | ||
|
|
||
| width: var(${tokens.width}); | ||
| border-radius: ${Radius["sm"]}; | ||
| border: ${Border["width-010"]} ${Border["solid"]} ${Colour["border"]}; | ||
| background: ${Colour["bg"]}; | ||
| overflow: hidden; | ||
| `; | ||
|
|
||
| export const dropdownList = css` | ||
| list-style: none; | ||
| margin: 0; | ||
| padding: ${Spacing["spacing-8"]}; | ||
| `; | ||
|
|
||
| export { | ||
| baseIndicatorStyle, | ||
| selectedIndicator, | ||
| } from "../shared/dropdown-list/dropdown-list.styles"; | ||
|
|
||
| export const dropdownItem = css` | ||
| align-items: center; | ||
| ${Font["body-md-regular"]} | ||
| color: ${Colour["text"]}; | ||
|
|
||
| &:hover { | ||
| background: ${Colour["bg-hover-subtle"]}; | ||
| } | ||
| `; | ||
|
|
||
| export const dropdownItemSelected = css` | ||
| background: transparent; | ||
| color: ${Colour["text-selected"]}; | ||
|
|
||
| &:hover { | ||
| background: ${Colour["bg-hover"]}; | ||
| } | ||
| `; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.