Skip to content

Commit 2f42043

Browse files
author
Eric Olkowski
committed
Updated validator assertion
1 parent f229105 commit 2f42043

File tree

2 files changed

+35
-73
lines changed

2 files changed

+35
-73
lines changed

packages/react-core/src/components/DatePicker/__tests__/DatePicker.test.tsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test('Does not render aria-invalid input when multiple validators return empty s
1616

1717
const rangeValidator = (_date: Date) => '';
1818
const rangeValidatorB = (_date: Date) => '';
19-
const { asFragment } = render(<DatePicker value="2020-03-17" validators={[rangeValidator, rangeValidatorB]} />);
19+
render(<DatePicker value="2020-03-17" validators={[rangeValidator, rangeValidatorB]} />);
2020

2121
await user.click(screen.getByRole('textbox'));
2222
await user.click(document.body);
@@ -28,11 +28,40 @@ test('Does not render helper text when multiple validators return empty strings'
2828

2929
const rangeValidator = (_date: Date) => '';
3030
const rangeValidatorB = (_date: Date) => '';
31-
const { asFragment } = render(<DatePicker value="2020-03-17" validators={[rangeValidator, rangeValidatorB]} />);
31+
render(<DatePicker value="2020-03-17" validators={[rangeValidator, rangeValidatorB]} />);
3232

3333
await user.click(screen.getByRole('textbox'));
3434
await user.click(document.body);
35-
expect(asFragment()).toMatchSnapshot();
35+
36+
expect(screen.queryByText(': error status;')).not.toBeInTheDocument();
37+
});
38+
39+
test('Renders helper text when at least 1 validator returns a string', async () => {
40+
const user = userEvent.setup();
41+
42+
const rangeValidator = (_date: Date) => 'Some error.';
43+
const rangeValidatorB = (_date: Date) => '';
44+
render(<DatePicker value="2020-03-17" validators={[rangeValidator, rangeValidatorB]} />);
45+
46+
await user.click(screen.getByRole('textbox'));
47+
await user.click(document.body);
48+
49+
expect(screen.getByText('Some error.')).toBeVisible();
50+
expect(screen.getByText(': error status;')).toBeInTheDocument();
51+
});
52+
53+
test('Renders helper text when more than 1 validator returns a string', async () => {
54+
const user = userEvent.setup();
55+
56+
const rangeValidator = (_date: Date) => 'Some error.';
57+
const rangeValidatorB = (_date: Date) => 'Another error.';
58+
render(<DatePicker value="2020-03-17" validators={[rangeValidator, rangeValidatorB]} />);
59+
60+
await user.click(screen.getByRole('textbox'));
61+
await user.click(document.body);
62+
63+
expect(screen.getByText('Some error. Another error.')).toBeVisible();
64+
expect(screen.getByText(': error status;')).toBeInTheDocument();
3665
});
3766

3867
test('Error state can be cleared from outside', async () => {

packages/react-core/src/components/DatePicker/__tests__/__snapshots__/DatePicker.test.tsx.snap

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Does not render helper text when multiple validators return empty strings 1`] = `
4-
<DocumentFragment>
5-
<div
6-
class="pf-v6-c-date-picker"
7-
style="--pf-v6-c-date-picker__input--c-form-control--width-chars: 10;"
8-
>
9-
<div
10-
class="pf-v6-c-date-picker__input"
11-
>
12-
<div
13-
class="pf-v6-c-input-group"
14-
>
15-
<div
16-
class="pf-v6-c-input-group__item"
17-
>
18-
<span
19-
class="pf-v6-c-form-control"
20-
>
21-
<input
22-
aria-invalid="false"
23-
aria-label="Date picker"
24-
data-ouia-component-id="OUIA-Generated-TextInputBase-3"
25-
data-ouia-component-type="PF6/TextInput"
26-
data-ouia-safe="true"
27-
placeholder="YYYY-MM-DD"
28-
type="text"
29-
value="2020-03-17"
30-
/>
31-
</span>
32-
</div>
33-
<div
34-
class="pf-v6-c-input-group__item"
35-
>
36-
<button
37-
aria-haspopup="dialog"
38-
aria-label="Toggle date picker"
39-
class="pf-v6-c-button pf-m-control"
40-
data-ouia-component-id="OUIA-Generated-Button-control-3"
41-
data-ouia-component-type="PF6/Button"
42-
data-ouia-safe="true"
43-
type="button"
44-
>
45-
<span
46-
class="pf-v6-c-button__icon"
47-
>
48-
<svg
49-
aria-hidden="true"
50-
class="pf-v6-svg"
51-
fill="currentColor"
52-
height="1em"
53-
role="img"
54-
viewBox="0 0 448 512"
55-
width="1em"
56-
>
57-
<path
58-
d="M148 288h-40c-6.6 0-12-5.4-12-12v-40c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12zm108-12v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm96 0v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm-96 96v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm-96 0v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm192 0v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm96-260v352c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V112c0-26.5 21.5-48 48-48h48V12c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h128V12c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h48c26.5 0 48 21.5 48 48zm-48 346V160H48v298c0 3.3 2.7 6 6 6h340c3.3 0 6-2.7 6-6z"
59-
/>
60-
</svg>
61-
</span>
62-
</button>
63-
</div>
64-
</div>
65-
</div>
66-
</div>
67-
</DocumentFragment>
68-
`;
69-
703
exports[`With popover opened 1`] = `
714
<DocumentFragment>
725
<div
@@ -88,7 +21,7 @@ exports[`With popover opened 1`] = `
8821
<input
8922
aria-invalid="false"
9023
aria-label="Date picker"
91-
data-ouia-component-id="OUIA-Generated-TextInputBase-5"
24+
data-ouia-component-id="OUIA-Generated-TextInputBase-7"
9225
data-ouia-component-type="PF6/TextInput"
9326
data-ouia-safe="true"
9427
placeholder="YYYY-MM-DD"
@@ -104,7 +37,7 @@ exports[`With popover opened 1`] = `
10437
aria-haspopup="dialog"
10538
aria-label="Toggle date picker"
10639
class="pf-v6-c-button pf-m-control"
107-
data-ouia-component-id="OUIA-Generated-Button-control-5"
40+
data-ouia-component-id="OUIA-Generated-Button-control-7"
10841
data-ouia-component-type="PF6/Button"
10942
data-ouia-safe="true"
11043
type="button"
@@ -252,7 +185,7 @@ exports[`With popover opened 1`] = `
252185
<input
253186
aria-invalid="false"
254187
aria-label="Select year"
255-
data-ouia-component-id="OUIA-Generated-TextInputBase-6"
188+
data-ouia-component-id="OUIA-Generated-TextInputBase-8"
256189
data-ouia-component-type="PF6/TextInput"
257190
data-ouia-safe="true"
258191
type="number"

0 commit comments

Comments
 (0)