2022-10-10 17:09:45 +08:00
|
|
|
/* eslint-disable jest/no-disabled-tests */
|
2022-08-14 19:57:43 +08:00
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
import process from 'process';
|
|
|
|
import { SbPage } from './util';
|
|
|
|
|
|
|
|
const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
|
2022-10-10 17:09:45 +08:00
|
|
|
const templateName = process.env.STORYBOOK_TEMPLATE_NAME || '';
|
2022-08-14 19:57:43 +08:00
|
|
|
|
|
|
|
test.describe('addon-interactions', () => {
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
await page.goto(storybookUrl);
|
2022-08-24 22:06:49 -04:00
|
|
|
await new SbPage(page).waitUntilLoaded();
|
2022-08-14 19:57:43 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// FIXME: skip xxx
|
|
|
|
test('should have interactions', async ({ page }) => {
|
2022-10-10 17:09:45 +08:00
|
|
|
// templateName is e.g. 'Vue-CLI (Default JS)'
|
|
|
|
test.skip(
|
2022-10-24 14:57:37 +02:00
|
|
|
// eslint-disable-next-line jest/valid-title
|
|
|
|
/^(lit)/i.test(`${templateName}`),
|
2022-10-10 17:09:45 +08:00
|
|
|
`Skipping ${templateName}, which does not support addon-interactions`
|
|
|
|
);
|
|
|
|
|
2022-08-14 19:57:43 +08:00
|
|
|
const sbPage = new SbPage(page);
|
|
|
|
|
2022-10-27 22:53:41 +11:00
|
|
|
await sbPage.navigateToStory('example/page', 'logged-in');
|
2022-08-14 19:57:43 +08:00
|
|
|
await sbPage.viewAddonPanel('Interactions');
|
|
|
|
|
|
|
|
const welcome = await sbPage.previewRoot().locator('.welcome');
|
|
|
|
await expect(welcome).toContainText('Welcome, Jane Doe!');
|
|
|
|
|
|
|
|
const interactionsTab = await page.locator('#tabbutton-interactions');
|
|
|
|
await expect(interactionsTab).toContainText(/(1)/);
|
|
|
|
await expect(interactionsTab).toBeVisible();
|
|
|
|
|
|
|
|
const panel = sbPage.panelContent();
|
2022-11-29 13:01:09 +01:00
|
|
|
await expect(panel).toContainText(/Pass/);
|
2022-08-14 19:57:43 +08:00
|
|
|
await expect(panel).toContainText(/userEvent.click/);
|
|
|
|
await expect(panel).toBeVisible();
|
|
|
|
|
|
|
|
const done = await panel.locator('[data-testid=icon-done]');
|
|
|
|
await expect(done).toBeVisible();
|
|
|
|
});
|
2022-11-29 13:01:09 +01:00
|
|
|
|
|
|
|
test('should step through interactions', async ({ page }) => {
|
|
|
|
// templateName is e.g. 'Vue-CLI (Default JS)'
|
|
|
|
test.skip(
|
|
|
|
// eslint-disable-next-line jest/valid-title
|
|
|
|
/^(lit)/i.test(`${templateName}`),
|
|
|
|
`Skipping ${templateName}, which does not support addon-interactions`
|
|
|
|
);
|
|
|
|
|
|
|
|
const sbPage = new SbPage(page);
|
|
|
|
|
|
|
|
await sbPage.navigateToStory('addons/interactions/basics', 'type-and-clear');
|
|
|
|
await sbPage.viewAddonPanel('Interactions');
|
|
|
|
|
2022-11-29 13:06:22 +01:00
|
|
|
// Test initial state - Interactions have run, count is correct and values are as expected
|
2022-11-29 13:01:09 +01:00
|
|
|
const formInput = await sbPage.previewRoot().locator('#interaction-test-form input');
|
|
|
|
await expect(formInput).toHaveValue('final value');
|
|
|
|
|
|
|
|
const interactionsTab = await page.locator('#tabbutton-interactions');
|
|
|
|
await expect(interactionsTab).toContainText(/(3)/);
|
|
|
|
await expect(interactionsTab).toBeVisible();
|
|
|
|
|
|
|
|
const panel = sbPage.panelContent();
|
|
|
|
const runStatusBadge = await panel.locator('[aria-label="Status of the test run"]');
|
|
|
|
await expect(runStatusBadge).toContainText(/Pass/);
|
2022-11-30 14:24:25 +01:00
|
|
|
await expect(panel).toContainText(/value: "initial value"/);
|
|
|
|
await expect(panel).toContainText(/value: ""/);
|
|
|
|
await expect(panel).toContainText(/value: "final value"/);
|
2022-11-29 13:01:09 +01:00
|
|
|
await expect(panel).toBeVisible();
|
|
|
|
|
2022-11-29 13:06:22 +01:00
|
|
|
// Test interactions debugger - Stepping through works, count is correct and values are as expected
|
2022-11-29 13:01:09 +01:00
|
|
|
const interactionsRow = await panel.locator('[aria-label="Interaction step"]');
|
|
|
|
|
|
|
|
await interactionsRow.first().isVisible();
|
|
|
|
|
|
|
|
await expect(await interactionsRow.count()).toEqual(3);
|
|
|
|
const firstInteraction = interactionsRow.first();
|
|
|
|
await firstInteraction.click();
|
|
|
|
|
|
|
|
await expect(runStatusBadge).toContainText(/Runs/);
|
|
|
|
await expect(formInput).toHaveValue('initial value');
|
|
|
|
|
|
|
|
const goForwardBtn = await panel.locator('[aria-label="Go forward"]');
|
|
|
|
await goForwardBtn.click();
|
|
|
|
await expect(formInput).toHaveValue('');
|
|
|
|
await goForwardBtn.click();
|
|
|
|
await expect(formInput).toHaveValue('final value');
|
|
|
|
|
|
|
|
await expect(runStatusBadge).toContainText(/Pass/);
|
|
|
|
|
2022-11-29 13:06:22 +01:00
|
|
|
// Test rerun state (from addon panel) - Interactions have rerun, count is correct and values are as expected
|
2022-11-29 13:01:09 +01:00
|
|
|
const rerunInteractionButton = await panel.locator('[aria-label="Rerun"]');
|
|
|
|
await rerunInteractionButton.click();
|
|
|
|
await interactionsRow.first().isVisible();
|
2022-12-02 10:29:13 +01:00
|
|
|
await interactionsRow.nth(1).isVisible();
|
|
|
|
await interactionsRow.nth(2).isVisible();
|
2022-11-29 13:03:47 +01:00
|
|
|
await expect(interactionsTab).toContainText(/(3)/);
|
2022-12-02 10:29:13 +01:00
|
|
|
await expect(interactionsTab).toBeVisible();
|
2022-11-29 13:01:09 +01:00
|
|
|
|
2022-11-29 13:06:22 +01:00
|
|
|
// Test remount state (from toolbar) - Interactions have rerun, count is correct and values are as expected
|
2022-11-29 13:01:09 +01:00
|
|
|
const remountComponentButton = await page.locator('[title="Remount component"]');
|
|
|
|
await remountComponentButton.click();
|
|
|
|
await interactionsRow.first().isVisible();
|
2022-12-02 10:29:13 +01:00
|
|
|
await interactionsRow.nth(1).isVisible();
|
|
|
|
await interactionsRow.nth(2).isVisible();
|
2022-11-29 13:03:47 +01:00
|
|
|
await expect(interactionsTab).toContainText(/(3)/);
|
2022-12-02 10:29:13 +01:00
|
|
|
await expect(interactionsTab).toBeVisible();
|
2022-11-29 13:01:09 +01:00
|
|
|
});
|
2022-08-14 19:57:43 +08:00
|
|
|
});
|