Skip to content

Commit

Permalink
Transform Action jest tests into playwright (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbriza committed Mar 6, 2025
1 parent 630333f commit aecdb83
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 52 deletions.
52 changes: 0 additions & 52 deletions src/components/TextLink/__tests__/Link.test.jsx

This file was deleted.

103 changes: 103 additions & 0 deletions src/components/TextLink/__tests__/TextLink.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import React from 'react';
import {
expect,
test,
} from '@playwright/experimental-ct-react';
import { propTests } from '../../../../tests/playwright';
import { TextLinkForTest } from './TextLink.story';

test.describe('TextLink', () => {
const testHref = '/test/custom/uri';

test.describe('visual', () => {
[
...propTests.labelPropTest,
].forEach(({
name,
onBeforeTest,
props,
}) => {
test(name, async ({
mount,
page,
}) => {
if (onBeforeTest) {
await onBeforeTest(page);
}

const component = await mount(
<TextLinkForTest
{...props}
/>,
);

const screenshot = await component.screenshot();
expect(screenshot).toMatchSnapshot();
});
});
});

test.describe('non-visual', () => {
test('href', async ({ mount }) => {
const component = await mount(
<TextLinkForTest href={testHref} />,
);

await expect(component).toHaveAttribute('href', testHref);
});
});

test.describe('functionality', () => {
test('calls native redirect when clicked on', async ({ mount }) => {
const component = await mount(<TextLinkForTest href={testHref} />);
const page = component.page();

await Promise.all([
page.waitForURL(testHref),
component.click(),
]);

expect(page.url()).toContain(testHref);
});

test('calls native redirect when enter pressed', async ({ mount }) => {
const component = await mount(<TextLinkForTest href={testHref} />);
const page = component.page();

await Promise.all([
page.waitForURL(testHref),
component.press('Enter'),
]);

expect(page.url()).toContain(testHref);
});

test('calls onClick when clicked', async ({ mount }) => {
let clicked = false;
const component = await mount(
<TextLinkForTest
onClick={() => {
clicked = true;
}}
/>,
);
await component.click();

expect(clicked).toBeTruthy();
});

test('calls onClick when Enter pressed', async ({ mount }) => {
let clicked = false;
const component = await mount(
<TextLinkForTest
onClick={() => {
clicked = true;
}}
/>,
);

await component.press('Enter');
expect(clicked).toBeTruthy();
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/components/TextLink/__tests__/TextLink.story.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import type { AnchorHTMLAttributes } from 'react';
import { TextLink } from '..';

// Types for story component will be improved when we have full TypeScript support
type TextLinkForTestProps = AnchorHTMLAttributes<HTMLAnchorElement>;

export const TextLinkForTest = ({
...props
}: TextLinkForTestProps) => (
<TextLink
href="/test/uri"
label="Link"
{...props}
/>
);

0 comments on commit aecdb83

Please sign in to comment.