-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(elements/ino-switch): migrate stencil e2e tests to playwright (
#1356) Part of #1258 ## Proposed Changes - migrate existing stencil e2e tests to jest spec tests - add some playwright tests
- Loading branch information
Showing
3 changed files
with
82 additions
and
54 deletions.
There are no files selected for viewing
54 changes: 0 additions & 54 deletions
54
packages/elements/src/components/ino-switch/ino-switch.e2e.ts
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
packages/elements/src/components/ino-switch/ino-switch.spec.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,58 @@ | ||
import { newSpecPage, SpecPage } from '@stencil/core/testing'; | ||
import { Switch } from './ino-switch'; | ||
import { listenForEvent } from '../../util/test-utils'; | ||
|
||
describe('InoSwitch', () => { | ||
let page: SpecPage; | ||
let inoSwitch: HTMLInoSwitchElement; | ||
|
||
beforeEach(async () => { | ||
page = await newSpecPage({ | ||
components: [Switch], | ||
html: `<ino-switch></ino-switch>`, | ||
}); | ||
inoSwitch = page.body.querySelector('ino-switch'); | ||
}); | ||
|
||
it('should fire checkedChange event on click', async () => { | ||
const { eventSpy } = listenForEvent(page, 'checkedChange'); | ||
expect(eventSpy).not.toHaveBeenCalled(); | ||
inoSwitch.click(); | ||
await page.waitForChanges(); | ||
expect(eventSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should fire checkedChange event with true if the checked property is not set', async () => { | ||
const { assertEventDetails } = listenForEvent(page, 'checkedChange'); | ||
inoSwitch.click(); | ||
await page.waitForChanges(); | ||
assertEventDetails(true); | ||
}); | ||
|
||
it('should fire checkedChange event with true if the checked property is set to false', async () => { | ||
const { assertEventDetails } = listenForEvent(page, 'checkedChange'); | ||
inoSwitch.setAttribute('checked', 'false'); | ||
await page.waitForChanges(); | ||
inoSwitch.click(); | ||
await page.waitForChanges(); | ||
assertEventDetails(true); | ||
}); | ||
|
||
it('should fire checkedChange event with false if the checked property is set to true', async () => { | ||
const { assertEventDetails } = listenForEvent(page, 'checkedChange'); | ||
inoSwitch.setAttribute('checked', 'true'); | ||
await page.waitForChanges(); | ||
inoSwitch.click(); | ||
await page.waitForChanges(); | ||
assertEventDetails(false); | ||
}); | ||
|
||
it('should not fire a checkedChange event if disabled is true', async () => { | ||
const { eventSpy } = listenForEvent(page, 'checkedChange'); | ||
inoSwitch.setAttribute('disabled', 'true'); | ||
await page.waitForChanges(); | ||
inoSwitch.click(); | ||
await page.waitForChanges(); | ||
expect(eventSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/storybook/src/stories/ino-switch/ino-switch.spec.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,24 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { goToStory } from '../test-utils'; | ||
|
||
test.describe('ino-switch', () => { | ||
test('should be checked', async ({ page }) => { | ||
await goToStory(page, ['Input', 'ino-switch', 'default']); | ||
const inoSwitch = page.locator('ino-switch'); | ||
const input = inoSwitch.locator('input[type=hidden]'); | ||
|
||
await expect(input).toHaveJSProperty('checked', false); | ||
await inoSwitch.click(); | ||
await expect(input).toHaveJSProperty('checked', true); | ||
}); | ||
|
||
test('should be stay unchecked if disabled', async ({ page }) => { | ||
await goToStory(page, ['Input', 'ino-switch', 'disabled']); | ||
const inoSwitch = page.locator('ino-switch'); | ||
const input = inoSwitch.locator('input[type=hidden]'); | ||
|
||
await expect(input).toHaveJSProperty('checked', false); | ||
await inoSwitch.click(); | ||
await expect(input).toHaveJSProperty('checked', false); | ||
}); | ||
}); |