Skip to content

Commit 0af3d81

Browse files
committed
fix: failing ut
1 parent f20984a commit 0af3d81

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

packages/blade/src/components/TimePicker/__tests__/TimePicker.test.stories.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ TimePicker12HourFormat.play = async () => {
7979
await expect(inputScope.queryByText('02')).toBeVisible(); // 2 PM in input
8080
await expect(inputScope.queryByText('30')).toBeVisible(); // 30 minutes in input
8181
// Find the visible PM element (not the hidden placeholder)
82-
// Use a more specific approach - look for PM text in the time input container
82+
// Use getAllByText since there are multiple PM elements (placeholder + value)
8383
const timeInputContainer = inputScope.getByRole('combobox');
84-
const pmElement = within(timeInputContainer).getByText('PM');
85-
await expect(pmElement).toBeVisible(); // PM in input (actual value, not placeholder)
84+
const pmElements = within(timeInputContainer).getAllByText('PM');
85+
const visiblePmElement = pmElements.find((el) => el.style.pointerEvents !== 'none');
86+
expect(visiblePmElement).toBeDefined(); // Ensure we found a visible element
87+
await expect(visiblePmElement).toBeVisible(); // PM in input (actual value, not placeholder)
8688

8789
await userEvent.click(input);
8890
await sleep(400);
@@ -121,8 +123,8 @@ TimePicker24HourFormat.play = async () => {
121123
const pmElements = inputScope.queryAllByText('PM');
122124
const visibleAmElements = amElements.filter((el) => el.offsetHeight > 0);
123125
const visiblePmElements = pmElements.filter((el) => el.offsetHeight > 0);
124-
expect(visibleAmElements).toHaveLength(0);
125-
expect(visiblePmElements).toHaveLength(0);
126+
await expect(visibleAmElements).toHaveLength(0);
127+
await expect(visiblePmElements).toHaveLength(0);
126128

127129
await userEvent.click(input);
128130
await sleep(400);
@@ -275,10 +277,12 @@ TimePickerControlledState.play = async () => {
275277
await expect(inputScope.queryByText('10')).toBeVisible();
276278
await expect(inputScope.queryByText('30')).toBeVisible();
277279
// Find the visible AM element (not the hidden placeholder)
278-
// Use a more specific approach - look for AM text in the time input container
280+
// Use getAllByText since there are multiple AM elements (placeholder + value)
279281
const timeInputContainer = inputScope.getByRole('combobox');
280-
const amElement = within(timeInputContainer).getByText('AM');
281-
await expect(amElement).toBeVisible(); // AM in input (actual value, not placeholder)
282+
const amElements = within(timeInputContainer).getAllByText('AM');
283+
const visibleAmElement = amElements.find((el) => el.style.pointerEvents !== 'none');
284+
expect(visibleAmElement).toBeDefined(); // Ensure we found a visible element
285+
await expect(visibleAmElement).toBeVisible(); // AM in input (actual value, not placeholder)
282286

283287
// Click change time button
284288
const changeButton = getByRole('button', { name: 'Change Time' });
@@ -293,10 +297,12 @@ TimePickerControlledState.play = async () => {
293297
await expect(inputScope2.queryByText('03')).toBeVisible();
294298
await expect(inputScope2.queryByText('45')).toBeVisible();
295299
// Find the visible PM element (not the hidden placeholder)
296-
// Use a more specific approach - look for PM text in the time input container
300+
// Use getAllByText since there are multiple PM elements (placeholder + value)
297301
const timeInputContainer2 = inputScope2.getByRole('combobox');
298-
const pmElement2 = within(timeInputContainer2).getByText('PM');
299-
await expect(pmElement2).toBeVisible(); // PM in input (actual value, not placeholder)
302+
const pmElements2 = within(timeInputContainer2).getAllByText('PM');
303+
const visiblePmElement2 = pmElements2.find((el) => el.style.pointerEvents !== 'none');
304+
expect(visiblePmElement2).toBeDefined(); // Ensure we found a visible element
305+
await expect(visiblePmElement2).toBeVisible(); // PM in input (actual value, not placeholder)
300306

301307
// Verify dropdown also shows correct values
302308
};
@@ -318,7 +324,7 @@ TimePickerDisabled.play = async () => {
318324
const input = getByRole('combobox');
319325

320326
// Verify the input is actually disabled
321-
expect(input).toHaveAttribute('aria-disabled', 'true');
327+
await expect(input).toHaveAttribute('aria-disabled', 'true');
322328

323329
await userEvent.click(input);
324330
await sleep(400);

0 commit comments

Comments
 (0)