-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
924a6a7
commit d30ee27
Showing
6 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
37 changes: 37 additions & 0 deletions
37
packages/kit-headless/src/components/switch/switch.driver.ts
This file contains 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,37 @@ | ||
import { type Locator, type Page } from '@playwright/test'; | ||
type OpenKeys = 'ArrowUp' | 'Enter' | 'Space' | 'ArrowDown'; | ||
export type DriverLocator = Locator | Page; | ||
|
||
export function createTestDriver<T extends DriverLocator>(rootLocator: T) { | ||
const getRoot = () => { | ||
return rootLocator; | ||
}; | ||
|
||
const getTrigger = () => { | ||
return getRoot().locator('[data-value]') | ||
}; | ||
|
||
const getTriggerlaBle = () => { | ||
return getRoot().locator('[data-switch-lable]') | ||
} | ||
|
||
const openListbox = async (key: OpenKeys | 'click') => { | ||
await getTrigger().focus(); | ||
|
||
if (key !== 'click') { | ||
await getTrigger().press(key); | ||
} else { | ||
await getTrigger().click(); | ||
} | ||
|
||
}; | ||
|
||
return { | ||
...rootLocator, | ||
locator: rootLocator, | ||
getRoot, | ||
getTrigger, | ||
openListbox, | ||
getTriggerlaBle | ||
}; | ||
} |
This file contains 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,41 @@ | ||
import { type Page, test, expect } from '@playwright/test'; | ||
import { createTestDriver } from './switch.driver'; | ||
|
||
declare global { | ||
interface Window { | ||
onChangeTriggered: boolean; | ||
onChangeHandler: () => void; | ||
} | ||
} | ||
async function setup(page: Page, exampleName: string) { | ||
await page.goto(`/headless/switch/${exampleName}`); | ||
|
||
const driver = createTestDriver(page.locator('[data-qui-switch]')); | ||
|
||
return { | ||
driver, | ||
}; | ||
} | ||
|
||
test.describe('Mouse Behavior', () => { | ||
test(`GIVEN a hero switch | ||
WHEN toggled | ||
THEN the checked property should correctly reflect the toggle state`, async ({ page }) => { | ||
const { driver: d } = await setup(page, 'hero'); | ||
await expect(d.getTrigger()).not.toBeChecked(); | ||
await expect(d.getTrigger()).toHaveAttribute('data-checked', 'flase'); | ||
await d.getTrigger().click(); | ||
await expect(d.getTrigger()).toHaveAttribute('data-checked', 'true'); | ||
await expect(d.getTrigger()).toBeChecked() | ||
}) | ||
|
||
test(`GIVEN a hero switch | ||
WHEN clicked | ||
THEN the onChange callback should be triggered`, async ({ page }) => { | ||
const { driver: d } = await setup(page, 'hero'); | ||
await expect(d.getTriggerlaBle()).toHaveText('0') | ||
await d.getTrigger().click(); | ||
await expect(d.getTriggerlaBle()).toHaveText('1') | ||
}) | ||
|
||
}) |