Skip to content

Commit

Permalink
refactor(elements/ino-card): migrate stencil e2e tests to spec test (#…
Browse files Browse the repository at this point in the history
…1261)

* migrate e2e tests to spec tests

* run formatter

* implement pr feedback

* fix format

* implement PR feedback
  • Loading branch information
BenPag authored Mar 1, 2024
1 parent 7b24065 commit 968c154
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 51 deletions.
45 changes: 0 additions & 45 deletions packages/elements/src/components/ino-card/ino-card.e2e.ts

This file was deleted.

28 changes: 28 additions & 0 deletions packages/elements/src/components/ino-card/ino-card.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { newSpecPage, SpecPage } from '@stencil/core/testing';
import { Card } from './ino-card';
import { listenForEvent } from '../../util/test-utils';

const INO_CARD = `<ino-card></ino-card>`;
const CARD_SELECTOR = 'ino-card';

describe('InoCard', () => {
let page: SpecPage;
let card: HTMLInoCardElement;

beforeEach(async () => {
page = await newSpecPage({
components: [Card],
html: INO_CARD,
});
card = page.body.querySelector(CARD_SELECTOR);
});

it('should emit a clickEl event upon interacting with the card', async () => {
const { eventSpy } = listenForEvent(page, 'click');

card.click();
await page.waitForChanges();

expect(eventSpy).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test.describe('ino-accordion', () => {
});

test('can be expanded properly', async ({ page }) => {
await goToStory(page, ['structure', 'ino-accordion', 'default']);
await goToStory(page, ['Structure', 'ino-accordion', 'default']);

const title = page.getByText('Accordion Title');
const text = page.getByText('Lorem ipsum dolor sit amet');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test.describe('ino-button', () => {
let inoButton: Locator;

test.beforeEach(async ({ page }) => {
await goToStory(page, ['buttons', 'ino-button', 'default']);
await goToStory(page, ['Buttons', 'ino-button', 'default']);
inoButton = page.locator('ino-button');
});

Expand Down
17 changes: 17 additions & 0 deletions packages/storybook/src/stories/ino-card/ino-card.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, Locator, test } from '@playwright/test';
import { goToStory, setAttribute } from '../test-utils';

test.describe('ino-card', () => {
let inoCard: Locator;

test.beforeEach(async ({ page }) => {
await goToStory(page, ['Structure', 'ino-card', 'default']);
inoCard = page.locator('ino-card');
});

test('should render with check mark if selected', async () => {
await setAttribute(inoCard, 'selected', 'true');
const check_mark = inoCard.locator('.ino-card__checkmark');
await expect(check_mark).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test.describe('ino-checkbox', () => {
});

test('can be toggled properly', async ({ page }) => {
await goToStory(page, ['input', 'ino-checkbox', 'default']);
await goToStory(page, ['Input', 'ino-checkbox', 'default']);

await expect(checkbox).toBeChecked();

Expand All @@ -19,7 +19,7 @@ test.describe('ino-checkbox', () => {
});

test('disabling prevents a change of checked', async ({ page }) => {
await goToStory(page, ['input', 'ino-checkbox', 'disabled']);
await goToStory(page, ['Input', 'ino-checkbox', 'disabled']);

await expect(checkbox).toBeChecked();
await expect(checkbox).toBeDisabled();
Expand Down
6 changes: 4 additions & 2 deletions packages/storybook/src/stories/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Locator, Page } from '@playwright/test';

type StoryDescription = [string, string, string]; // ['input', 'ino-checkbox', 'default']
type StoryDescription = [StoryCategory, string, string]; // ['input', 'ino-checkbox', 'default']

export async function goToStory(
page: Page,
storyDescription: StoryDescription,
) {
const [category, name, story] = storyDescription;

await page.goto(`/iframe.html?id=${category}-${name}--${story}`);
await page.goto(
`/iframe.html?id=${category.toLowerCase()}-${name}--${story}`,
);
}

export function setAttribute(el: Locator, attrName: string, value: string) {
Expand Down
6 changes: 6 additions & 0 deletions packages/storybook/src/types/storyCategory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare type StoryCategory =
| 'Structure'
| 'Input'
| 'Graphic'
| 'Buttons'
| 'Notification';

0 comments on commit 968c154

Please sign in to comment.