From 92828852336aa59831daf73410ac6cae73b53e8c Mon Sep 17 00:00:00 2001 From: brendanlaschke Date: Wed, 27 Sep 2023 15:19:33 +0200 Subject: [PATCH] Fix cmd menu tests (#1739) * - fix tests * - fixed header * - lint - fixed catalog menuitemcommand * - fix prop destructuring in test * - combine single/multiple create and goto commands --- .../command-menu/components/CommandMenu.tsx | 42 +++++++++---------- .../__stories__/CommandMenu.stories.tsx | 10 +++-- .../__stories__/MenuItemCommand.stories.tsx | 23 ++++++++++ .../ui/navbar/__stories__/NavItem.stories.tsx | 1 - ...cEditableDoubleTextChipCellDisplayMode.tsx | 1 - 5 files changed, 49 insertions(+), 28 deletions(-) diff --git a/front/src/modules/command-menu/components/CommandMenu.tsx b/front/src/modules/command-menu/components/CommandMenu.tsx index a8b9a9da6..aa27fa5c5 100644 --- a/front/src/modules/command-menu/components/CommandMenu.tsx +++ b/front/src/modules/command-menu/components/CommandMenu.tsx @@ -42,7 +42,7 @@ export const CommandMenu = () => { openCommandMenu(); }, AppHotkeyScope.CommandMenu, - [openCommandMenu], + [openCommandMenu, setSearch], ); const { data: peopleData } = useSearchPeopleQuery({ @@ -133,29 +133,27 @@ export const CommandMenu = () => { No results found. - {matchingCreateCommand.length === 1 && - matchingCreateCommand.map((cmd) => ( - - ))} + {matchingCreateCommand.map((cmd) => ( + + ))} - {matchingNavigateCommand.length === 1 && - matchingNavigateCommand.map((cmd) => ( - - ))} + {matchingNavigateCommand.map((cmd) => ( + + ))} {people.map((person) => ( diff --git a/front/src/modules/command-menu/components/__stories__/CommandMenu.stories.tsx b/front/src/modules/command-menu/components/__stories__/CommandMenu.stories.tsx index 35bb66068..521bcab3e 100644 --- a/front/src/modules/command-menu/components/__stories__/CommandMenu.stories.tsx +++ b/front/src/modules/command-menu/components/__stories__/CommandMenu.stories.tsx @@ -12,6 +12,8 @@ import { sleep } from '~/testing/sleep'; import { CommandMenu } from '../CommandMenu'; +const openTimeout = 50; + const meta: Meta = { title: 'Modules/CommandMenu/CommandMenu', component: CommandMenu, @@ -70,7 +72,7 @@ export const MatchingPersonCompanyActivityCreateNavigate: Story = { play: async () => { const canvas = within(document.body); const searchInput = await canvas.findByPlaceholderText('Search'); - await sleep(10); + await sleep(openTimeout); await userEvent.type(searchInput, 'n'); expect(await canvas.findByText('Alexandre Prot')).toBeInTheDocument(); expect(await canvas.findByText('Airbnb')).toBeInTheDocument(); @@ -84,7 +86,7 @@ export const OnlyMatchingCreateAndNavigate: Story = { play: async () => { const canvas = within(document.body); const searchInput = await canvas.findByPlaceholderText('Search'); - await sleep(10); + await sleep(openTimeout); await userEvent.type(searchInput, 'ta'); expect(await canvas.findByText('Create Task')).toBeInTheDocument(); expect(await canvas.findByText('Go to Tasks')).toBeInTheDocument(); @@ -95,7 +97,7 @@ export const AtleastMatchingOnePerson: Story = { play: async () => { const canvas = within(document.body); const searchInput = await canvas.findByPlaceholderText('Search'); - await sleep(10); + await sleep(openTimeout); await userEvent.type(searchInput, 'alex'); expect(await canvas.findByText('Alexandre Prot')).toBeInTheDocument(); }, @@ -105,7 +107,7 @@ export const NotMatchingAnything: Story = { play: async () => { const canvas = within(document.body); const searchInput = await canvas.findByPlaceholderText('Search'); - await sleep(10); + await sleep(openTimeout); await userEvent.type(searchInput, 'asdasdasd'); expect(await canvas.findByText('No results found.')).toBeInTheDocument(); }, diff --git a/front/src/modules/ui/menu-item/components/__stories__/MenuItemCommand.stories.tsx b/front/src/modules/ui/menu-item/components/__stories__/MenuItemCommand.stories.tsx index e0d704f8b..92d8ced70 100644 --- a/front/src/modules/ui/menu-item/components/__stories__/MenuItemCommand.stories.tsx +++ b/front/src/modules/ui/menu-item/components/__stories__/MenuItemCommand.stories.tsx @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/react'; +import { Command } from 'cmdk'; import { IconBell } from '@/ui/icon'; import { @@ -24,6 +25,17 @@ export const Default: Story = { text: 'First option', command: '⌘ 1', }, + render: (props) => ( + + + + ), decorators: [ComponentDecorator], }; @@ -74,5 +86,16 @@ export const Catalog: Story = { } as CatalogOptions, }, }, + render: (props) => ( + + + + ), decorators: [CatalogDecorator], }; diff --git a/front/src/modules/ui/navbar/__stories__/NavItem.stories.tsx b/front/src/modules/ui/navbar/__stories__/NavItem.stories.tsx index 29096b53a..6bb28fbbe 100644 --- a/front/src/modules/ui/navbar/__stories__/NavItem.stories.tsx +++ b/front/src/modules/ui/navbar/__stories__/NavItem.stories.tsx @@ -1,7 +1,6 @@ import styled from '@emotion/styled'; import { Decorator, Meta, StoryObj } from '@storybook/react'; - import { IconSearch, IconSettings } from '@/ui/icon'; import { CatalogDecorator } from '~/testing/decorators/CatalogDecorator'; import { ComponentWithRouterDecorator } from '~/testing/decorators/ComponentWithRouterDecorator'; diff --git a/front/src/modules/ui/table/editable-cell/type/components/GenericEditableDoubleTextChipCellDisplayMode.tsx b/front/src/modules/ui/table/editable-cell/type/components/GenericEditableDoubleTextChipCellDisplayMode.tsx index 562b7139a..53dc18217 100644 --- a/front/src/modules/ui/table/editable-cell/type/components/GenericEditableDoubleTextChipCellDisplayMode.tsx +++ b/front/src/modules/ui/table/editable-cell/type/components/GenericEditableDoubleTextChipCellDisplayMode.tsx @@ -1,6 +1,5 @@ import { useRecoilState } from 'recoil'; - import { DoubleTextChipDisplay } from '@/ui/content-display/components/DoubleTextChipDisplay'; import { ViewFieldDoubleTextChipMetadata } from '@/ui/editable-field/types/ViewField'; import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';