Skip to content

Commit

Permalink
refactor(elements/ino-switch): migrate stencil e2e tests to playwright (
Browse files Browse the repository at this point in the history
#1356)

Part of #1258 

## Proposed Changes

- migrate existing stencil e2e tests to jest spec tests
- add some playwright tests
  • Loading branch information
BenPag authored Apr 5, 2024
1 parent 005f54f commit 11ac034
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 54 deletions.
54 changes: 0 additions & 54 deletions packages/elements/src/components/ino-switch/ino-switch.e2e.ts

This file was deleted.

58 changes: 58 additions & 0 deletions packages/elements/src/components/ino-switch/ino-switch.spec.ts
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 packages/storybook/src/stories/ino-switch/ino-switch.spec.ts
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);
});
});

0 comments on commit 11ac034

Please sign in to comment.