Skip to content

Commit 8ae8682

Browse files
committed
Transform Action jest tests into playwright (#592)
1 parent 630333f commit 8ae8682

File tree

4 files changed

+96
-52
lines changed

4 files changed

+96
-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,84 @@
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+
test.describe('visual', () => {
11+
[
12+
...propTests.labelPropTest
13+
].forEach(({
14+
name,
15+
onBeforeTest,
16+
props,
17+
}) => {
18+
test(name, async ({
19+
mount,
20+
page
21+
}) => {
22+
if (onBeforeTest) {
23+
await onBeforeTest(page);
24+
}
25+
26+
const component = await mount(
27+
<TextLinkForTest
28+
{...props}
29+
/>
30+
);
31+
32+
const screenshot = await component.screenshot();
33+
expect(screenshot).toMatchSnapshot();
34+
});
35+
});
36+
})
37+
38+
test.describe('non-visual', () => {
39+
test('href', async ({ mount }) => {
40+
const component = await mount(
41+
<TextLinkForTest
42+
href='/test/uri'
43+
label='test-label'
44+
/>
45+
)
46+
47+
await expect(component).toHaveAttribute('href', '/test/uri');
48+
});
49+
})
50+
51+
test.describe('functionality', () => {
52+
test('calls onClick when clicked', async ({mount}) => {
53+
let clicked = false;
54+
const component = await mount(
55+
<TextLinkForTest
56+
href='/test/uri'
57+
label='test-label'
58+
onClick={() => {
59+
clicked = true;
60+
}}
61+
/>,
62+
);
63+
await component.click();
64+
65+
expect(clicked).toBeTruthy();
66+
});
67+
68+
test('calls onClick when Enter pressed', async ({ mount }) => {
69+
let clicked = false;
70+
const component = await mount(
71+
<TextLinkForTest
72+
href='/test/uri'
73+
label='test-label'
74+
onClick={() => {
75+
clicked = true;
76+
}}
77+
/>,
78+
);
79+
await component.press('Enter');
80+
81+
expect(clicked).toBeTruthy();
82+
});
83+
})
84+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 {...props}/>
12+
);

0 commit comments

Comments
 (0)