Skip to content

Commit d4dfa35

Browse files
authored
test: Add visual coverage for Input focus states (#5127)
1 parent 10501b2 commit d4dfa35

2 files changed

Lines changed: 79 additions & 1 deletion

File tree

‎pages/input/focus-states.page.tsx‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import React from 'react';
4+
5+
import Box from '~components/box';
6+
import Input from '~components/input';
7+
import SpaceBetween from '~components/space-between';
8+
9+
import { SimplePage } from '../app/templates';
10+
11+
function Section({ caption, children }: { caption: string; children: React.ReactNode }) {
12+
return (
13+
<SpaceBetween size="xxs">
14+
<Box variant="small">{caption}</Box>
15+
{children}
16+
</SpaceBetween>
17+
);
18+
}
19+
20+
export default function InputFocusStatesPage() {
21+
return (
22+
<SimplePage title="Input focus states" screenshotArea={{ disableAnimations: true }}>
23+
<Section caption="readonly">
24+
<Input data-testid="readonly" ariaLabel="readonly" readOnly={true} value="Read-only value" />
25+
</Section>
26+
<Section caption="native-invalid">
27+
<Input
28+
data-testid="native-invalid"
29+
ariaLabel="native-invalid"
30+
type="email"
31+
value="not-an-email"
32+
onChange={() => {}}
33+
/>
34+
</Section>
35+
<Section caption="suffix">
36+
<Input data-testid="suffix" ariaLabel="suffix" value="42" suffix="USD" onChange={() => {}} />
37+
</Section>
38+
<Section caption="prefix">
39+
<Input data-testid="prefix" ariaLabel="prefix" value="42" prefix="$" onChange={() => {}} />
40+
</Section>
41+
</SimplePage>
42+
);
43+
}

‎test/definitions/visual/input.ts‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import { TestSuite } from '../types';
3+
import { TestDefinition, TestSuite } from '../types';
4+
5+
const focusStatesPath = 'input/focus-states';
6+
const inputSelector = (testId: string) => `[data-testid="${testId}"] input`;
7+
// Pointer target outside any input: the page heading.
8+
const headingSelector = 'h1';
49

510
const suite: TestSuite = {
611
description: 'Input',
@@ -21,6 +26,36 @@ const suite: TestSuite = {
2126
path: 'input/inline-label-permutations',
2227
screenshotType: 'permutations',
2328
},
29+
{
30+
description: 'focus states - rest',
31+
path: focusStatesPath,
32+
screenshotType: 'screenshotArea',
33+
},
34+
// Focus is produced with page.click(): the input's focus styles are plain CSS :focus/:focus-within,
35+
// which a dispatched focusin event (page.focusInputs()) does not trigger. Only one element can hold
36+
// focus, so each input gets its own focused entry.
37+
...['readonly', 'native-invalid', 'suffix', 'prefix'].flatMap(
38+
testId =>
39+
[
40+
{
41+
description: `focus states - focused ${testId}`,
42+
path: focusStatesPath,
43+
screenshotType: 'screenshotArea',
44+
setup: async ({ page }) => {
45+
await page.click(inputSelector(testId));
46+
},
47+
},
48+
{
49+
description: `focus states - focused ${testId}, pointer away`,
50+
path: focusStatesPath,
51+
screenshotType: 'screenshotArea',
52+
setup: async ({ page }) => {
53+
await page.click(inputSelector(testId));
54+
await page.hoverElement(headingSelector);
55+
},
56+
},
57+
] as TestDefinition[]
58+
),
2459
],
2560
};
2661

0 commit comments

Comments
 (0)