Skip to content

Commit 24b48f6

Browse files
lukasbrizabedrich-schindler
authored andcommitted
Transform Action jest tests into playwright (#592)
1 parent 630333f commit 24b48f6

File tree

4 files changed

+119
-52
lines changed

4 files changed

+119
-52
lines changed

src/components/TextLink/__tests__/Link.test.jsx

-52
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import React from 'react';
2+
import {
3+
expect,
4+
test,
5+
} from '@playwright/experimental-ct-react';
6+
import { propTests } from '../../../../tests/playwright';
7+
import { TextLinkForTest } from './TextLink.story';
8+
9+
test.describe('TextLink', () => {
10+
const testHref = '/test/custom/uri';
11+
12+
test.describe('visual', () => {
13+
[
14+
...propTests.labelPropTest,
15+
].forEach(({
16+
name,
17+
onBeforeTest,
18+
props,
19+
}) => {
20+
test(name, async ({
21+
mount,
22+
page,
23+
}) => {
24+
if (onBeforeTest) {
25+
await onBeforeTest(page);
26+
}
27+
28+
const component = await mount(
29+
<TextLinkForTest
30+
{...props}
31+
/>,
32+
);
33+
34+
const screenshot = await component.screenshot();
35+
expect(screenshot).toMatchSnapshot();
36+
});
37+
});
38+
});
39+
40+
test.describe('non-visual', () => {
41+
test('href', async ({ mount }) => {
42+
const component = await mount(
43+
<TextLinkForTest href={testHref} />,
44+
);
45+
46+
await expect(component).toHaveAttribute('href', testHref);
47+
});
48+
});
49+
50+
test.describe('functionality', () => {
51+
test('calls native redirect when clicked on', async ({ mount }) => {
52+
const component = await mount(<TextLinkForTest href={testHref} />);
53+
const page = component.page();
54+
55+
await Promise.all([
56+
page.waitForURL(testHref),
57+
component.click(),
58+
]);
59+
60+
expect(page.url()).toContain(testHref);
61+
});
62+
63+
test('calls native redirect when Enter pressed', async ({ mount }) => {
64+
const component = await mount(<TextLinkForTest href={testHref} />);
65+
const page = component.page();
66+
67+
await Promise.all([
68+
page.waitForURL(testHref),
69+
component.press('Enter'),
70+
]);
71+
72+
expect(page.url()).toContain(testHref);
73+
});
74+
75+
test('calls onClick when clicked', async ({ mount }) => {
76+
let clicked = false;
77+
const component = await mount(
78+
<TextLinkForTest
79+
onClick={() => {
80+
clicked = true;
81+
}}
82+
/>,
83+
);
84+
await component.click();
85+
86+
expect(clicked).toBeTruthy();
87+
});
88+
89+
test('calls onClick when Enter pressed', async ({ mount }) => {
90+
let clicked = false;
91+
const component = await mount(
92+
<TextLinkForTest
93+
onClick={() => {
94+
clicked = true;
95+
}}
96+
/>,
97+
);
98+
await component.press('Enter');
99+
100+
expect(clicked).toBeTruthy();
101+
});
102+
});
103+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import type { AnchorHTMLAttributes } from 'react';
3+
import { TextLink } from '..';
4+
5+
// Types for story component will be improved when we have full TypeScript support
6+
type TextLinkForTestProps = AnchorHTMLAttributes<HTMLAnchorElement>;
7+
8+
export const TextLinkForTest = ({
9+
...props
10+
}: TextLinkForTestProps) => (
11+
<TextLink
12+
href="/test/uri"
13+
label="Link"
14+
{...props}
15+
/>
16+
);

0 commit comments

Comments
 (0)