Skip to content

Commit

Permalink
disable hide in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
r100-stack committed Sep 20, 2024
1 parent 92a8517 commit f99e419
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 91 deletions.
22 changes: 22 additions & 0 deletions packages/itwinui-react/src/core/Buttons/DropdownButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ it('should update when menu opens or closes', async () => {
expect(svg).toEqual(downArrow);
});

it('should work with menu items', async () => {
const { container } = renderComponent();

const button = container.querySelector('.iui-button') as HTMLButtonElement;
expect(button).toBeTruthy();

let menu = document.querySelector('.iui-menu') as HTMLElement;
expect(menu).toBeFalsy();

await userEvent.click(button);
menu = document.querySelector('[role=menu]') as HTMLElement;
expect(menu).toBeVisible();

expect(document.querySelectorAll('[role=menuitem]')).toHaveLength(3);

const menuItem = menu.querySelector('[role=menuitem]') as HTMLElement;
expect(menuItem).toBeTruthy();
await userEvent.click(menuItem);

expect(menu).not.toBeVisible();
});

it('should render borderless button correctly', () => {
const { container } = renderComponent({ styleType: 'borderless' });
const button = container.querySelector('.iui-button') as HTMLButtonElement;
Expand Down
49 changes: 49 additions & 0 deletions packages/itwinui-react/src/core/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,55 @@ it('renders avatar alone correctly', () => {
expect(avatar).toBeTruthy();
expect(avatar?.textContent).toEqual('AvatarContent');
});
it('renders moreMenu alone correctly', async () => {
// Summarized, as this is partly based on DropdownMenu, which is tested independently.
const itemOneOnClick = vi.fn();

const { container } = render(
<Header
appLogo={<div>AppTitle</div>}
menuItems={(close) => [
<MenuItem
key={0}
onClick={() => {
itemOneOnClick();
close();
}}
>
Test0
</MenuItem>,
<MenuItem key={1} onClick={close}>
Test1
</MenuItem>,
<MenuItem key={2} onClick={close}>
Test2
</MenuItem>,
]}
/>,
);
const button = container.querySelector(
'.iui-page-header-right > .iui-button[data-iui-variant="borderless"]:last-child',
) as HTMLButtonElement;
expect(button).toBeTruthy();
expect(button.getAttribute('aria-label')).toEqual('More options');

let menu = document.querySelector('.iui-menu') as HTMLElement;
expect(menu).toBeFalsy();

await userEvent.click(button);
menu = document.querySelector('.iui-menu') as HTMLElement;
expect(menu).toBeVisible();

expect(document.querySelectorAll('[role=menuitem]')).toHaveLength(3);

const menuItem = menu.querySelector('[role=menuitem]') as HTMLElement;
expect(menuItem).toBeTruthy();
await userEvent.click(menuItem);

expect(menu).not.toBeVisible();

expect(itemOneOnClick).toHaveBeenCalled();
});

it('renders translatedStrings correctly', () => {
const { container } = render(
Expand Down
3 changes: 2 additions & 1 deletion packages/itwinui-react/src/core/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
Box,
ShadowRoot,
cloneElementWithRef,
isUnitTest,
mergeEventHandlers,
useControlledState,
useId,
Expand Down Expand Up @@ -189,7 +190,7 @@ export const usePopover = (options: PopoverOptions & PopoverInternalProps) => {
flip: options.middleware?.flip ?? true,
shift: options.middleware?.shift ?? true,
size: options.middleware?.size ?? true,
hide: options.middleware?.hide ?? true,
hide: options.middleware?.hide || !isUnitTest, // default is true, except in fake DOM environments
}),
[options.middleware],
);
Expand Down
21 changes: 0 additions & 21 deletions testing/e2e/app/routes/DropdownButton/route.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions testing/e2e/app/routes/DropdownButton/spec.ts

This file was deleted.

26 changes: 0 additions & 26 deletions testing/e2e/app/routes/Header/route.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions testing/e2e/app/routes/Header/spec.ts

This file was deleted.

0 comments on commit f99e419

Please sign in to comment.