Skip to content

Commit

Permalink
feat(components): split up tests to avoid timout
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-parker committed Jan 14, 2025
1 parent e6c1b0c commit 2538257
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
5 changes: 4 additions & 1 deletion components/src/preact/textInput/text-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ const TextSelector = ({
if (inputValue === undefined || inputValue === null || inputValue === '') {
return true;
}
return item === inputValue;
return (
item?.toLowerCase().includes(inputValue?.toLowerCase() || '') ||
item?.toLowerCase().includes(inputValue?.toLowerCase() || '')
);
}

const {
Expand Down
44 changes: 36 additions & 8 deletions components/src/web-components/input/gs-text-input.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const Default: StoryObj<Required<TextInputProps>> = {
},
};

export const FiresEvent: StoryObj<Required<TextInputProps>> = {
export const FiresEventNoValidInput: StoryObj<Required<TextInputProps>> = {
...Default,
play: async ({ canvasElement, step }) => {
const canvas = await withinShadowRoot(canvasElement, 'gs-text-input');
Expand Down Expand Up @@ -126,19 +126,47 @@ export const FiresEvent: StoryObj<Required<TextInputProps>> = {
host: null,
});
});
},
args: {
...Default.args,
initialValue: '',
},
};

export const FiresEventValidInput: StoryObj<Required<TextInputProps>> = {
...Default,
play: async ({ canvasElement, step }) => {
const canvas = await withinShadowRoot(canvasElement, 'gs-text-input');

const inputField = () => canvas.getByPlaceholderText('Enter host name');
const listenerMock = fn();
await step('Setup event listener mock', async () => {
canvasElement.addEventListener('gs-text-input-changed', listenerMock);
});

await step('wait until data is loaded', async () => {
await waitFor(() => {
return expect(inputField()).toBeEnabled();
});
});

await step('Enter a valid host name', async () => {
await userEvent.type(inputField(), 'Homo s');

const dropdownOption = await canvas.findByText('Homo sapiens');
await userEvent.click(dropdownOption);
});

await expect(listenerMock).toHaveBeenCalledWith(
expect.objectContaining({
detail: {
host: 'Homo',
},
}),
);
await step('Verify event is fired with correct detail', async () => {
await waitFor(() => {
expect(listenerMock).toHaveBeenCalledWith(
expect.objectContaining({
detail: {
host: 'Homo sapiens',
},
}),
);
});
});
},
args: {
Expand Down

0 comments on commit 2538257

Please sign in to comment.