Skip to content

Commit f20984a

Browse files
committed
fix: failing test
1 parent b2cfaad commit f20984a

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22
import type { StoryFn, Meta } from '@storybook/react';
3-
import { TimePicker } from './TimePicker';
3+
import { TimePicker } from '~components/TimePicker';
44
import { Box } from '~components/Box';
55
import { Text, Code } from '~components/Typography';
66
import { Button } from '~components/Button';

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ TimePicker12HourFormat.play = async () => {
7878
// Should display 2:30 PM in the input initially
7979
await expect(inputScope.queryByText('02')).toBeVisible(); // 2 PM in input
8080
await expect(inputScope.queryByText('30')).toBeVisible(); // 30 minutes in input
81-
await expect(inputScope.getAllByText('PM')[0]).toBeVisible(); // PM in input (actual value, not placeholder)
81+
// Find the visible PM element (not the hidden placeholder)
82+
// Use a more specific approach - look for PM text in the time input container
83+
const timeInputContainer = inputScope.getByRole('combobox');
84+
const pmElement = within(timeInputContainer).getByText('PM');
85+
await expect(pmElement).toBeVisible(); // PM in input (actual value, not placeholder)
8286

8387
await userEvent.click(input);
8488
await sleep(400);
@@ -112,8 +116,13 @@ TimePicker24HourFormat.play = async () => {
112116
await expect(inputScope.queryByText('14')).toBeVisible(); // 14 hours in input
113117
await expect(inputScope.queryByText('30')).toBeVisible(); // 30 minutes in input
114118
// AM/PM should not be in input for 24h format
115-
await expect(inputScope.queryByText('AM')).not.toBeInTheDocument();
116-
await expect(inputScope.queryByText('PM')).not.toBeInTheDocument();
119+
// Check that no visible AM/PM elements exist (not just hidden placeholders)
120+
const amElements = inputScope.queryAllByText('AM');
121+
const pmElements = inputScope.queryAllByText('PM');
122+
const visibleAmElements = amElements.filter((el) => el.offsetHeight > 0);
123+
const visiblePmElements = pmElements.filter((el) => el.offsetHeight > 0);
124+
expect(visibleAmElements).toHaveLength(0);
125+
expect(visiblePmElements).toHaveLength(0);
117126

118127
await userEvent.click(input);
119128
await sleep(400);
@@ -265,7 +274,11 @@ TimePickerControlledState.play = async () => {
265274
// Should start with 10:30 AM in input
266275
await expect(inputScope.queryByText('10')).toBeVisible();
267276
await expect(inputScope.queryByText('30')).toBeVisible();
268-
await expect(inputScope.getAllByText('AM')[0]).toBeVisible(); // AM in input (actual value, not placeholder)
277+
// Find the visible AM element (not the hidden placeholder)
278+
// Use a more specific approach - look for AM text in the time input container
279+
const timeInputContainer = inputScope.getByRole('combobox');
280+
const amElement = within(timeInputContainer).getByText('AM');
281+
await expect(amElement).toBeVisible(); // AM in input (actual value, not placeholder)
269282

270283
// Click change time button
271284
const changeButton = getByRole('button', { name: 'Change Time' });
@@ -279,7 +292,11 @@ TimePickerControlledState.play = async () => {
279292
// Should now show 3:45 PM in input
280293
await expect(inputScope2.queryByText('03')).toBeVisible();
281294
await expect(inputScope2.queryByText('45')).toBeVisible();
282-
await expect(inputScope2.getAllByText('PM')[0]).toBeVisible(); // PM in input (actual value, not placeholder)
295+
// Find the visible PM element (not the hidden placeholder)
296+
// Use a more specific approach - look for PM text in the time input container
297+
const timeInputContainer2 = inputScope2.getByRole('combobox');
298+
const pmElement2 = within(timeInputContainer2).getByText('PM');
299+
await expect(pmElement2).toBeVisible(); // PM in input (actual value, not placeholder)
283300

284301
// Verify dropdown also shows correct values
285302
};
@@ -300,6 +317,9 @@ TimePickerDisabled.play = async () => {
300317
const { getByRole } = within(document.body);
301318
const input = getByRole('combobox');
302319

320+
// Verify the input is actually disabled
321+
expect(input).toHaveAttribute('aria-disabled', 'true');
322+
303323
await userEvent.click(input);
304324
await sleep(400);
305325

0 commit comments

Comments
 (0)