diff --git a/components/header-bar/src/command-palette/__tests__/browse-apps-view.test.js b/components/header-bar/src/command-palette/__tests__/browse-apps-view.test.js index a1b906b00..e0dec701c 100644 --- a/components/header-bar/src/command-palette/__tests__/browse-apps-view.test.js +++ b/components/header-bar/src/command-palette/__tests__/browse-apps-view.test.js @@ -1,4 +1,6 @@ +import { fireEvent, wait } from '@testing-library/react' import userEvent from '@testing-library/user-event' + import React from 'react' import CommandPalette from '../command-palette.js' import { @@ -45,13 +47,13 @@ describe('Command Palette - List View - Browse Apps View', () => { expect(listItems[0]).toHaveClass('highlighted') // go back to default view - user.click(getByLabelText('Back Button')) + await user.click(getByLabelText('Back Button')) expect(queryByText(/Top Apps/i)).toBeInTheDocument() expect(queryByText(/Actions/i)).toBeInTheDocument() }) - it.only('handles navigation and hover state of list items', async () => { - const user = userEvent.setup() + it('handles navigation and hover state of list items', async () => { + // const user = userEvent.setup() const { getAllByRole, queryByTestId, @@ -59,6 +61,8 @@ describe('Command Palette - List View - Browse Apps View', () => { queryByText, findByPlaceholderText, container, + findByTestId, + debug, } = render( { commands={testCommands} /> ) - // open modal - await container.focus() - await user.keyboard('{ctrl}/') - // fireEvent.keyDown(container, '{ctrl}/') - //open browse apps view - await user.click(queryByTestId('headerbar-browse-apps')) + await userEvent.keyboard('{meta>}/') + + // ToDo: this is a workaround after upgrading react because otherwise / is typed into the Searchbox in the test + await userEvent.keyboard('{backspace}') + + const browseAppsLink = await findByTestId('headerbar-browse-apps') + + await userEvent.click(browseAppsLink) // no filter view const searchField = await findByPlaceholderText('Search apps') - console.log(searchField) expect(queryByText(/All Apps/i)).toBeInTheDocument() const listItems = queryAllByTestId('headerbar-list-item') @@ -89,21 +94,21 @@ describe('Command Palette - List View - Browse Apps View', () => { 'Test App 1' ) - await user.keyboard('{ArrowDown}') + await userEvent.keyboard('{ArrowDown}') expect(listItems[0]).not.toHaveClass('highlighted') expect(listItems[1]).toHaveClass('highlighted') expect(listItems[1].querySelector('span')).toHaveTextContent( 'Test App 2' ) - await user.keyboard('{ArrowDown}') + await userEvent.keyboard('{ArrowDown}') expect(listItems[1]).not.toHaveClass('highlighted') expect(listItems[2]).toHaveClass('highlighted') expect(listItems[2].querySelector('span')).toHaveTextContent( 'Test App 3' ) - await user.keyboard('{ArrowUp}') + await userEvent.keyboard('{ArrowUp}') expect(listItems[2]).not.toHaveClass('highlighted') expect(listItems[1]).toHaveClass('highlighted') expect(listItems[1].querySelector('span')).toHaveTextContent( @@ -111,7 +116,7 @@ describe('Command Palette - List View - Browse Apps View', () => { ) // filter items view - await user.type(searchField, 'Test App') + await userEvent.type(searchField, 'Test App') expect(searchField).toHaveValue('Test App') expect(queryByText(/All Apps/i)).not.toBeInTheDocument() expect(queryByText(/Results for "Test App"/i)).toBeInTheDocument() @@ -124,7 +129,7 @@ describe('Command Palette - List View - Browse Apps View', () => { ) // simulate hover - await user.hover(listItems[8]) + await userEvent.hover(listItems[8]) expect(listItems[1]).not.toHaveClass('highlighted') expect(listItems[8]).toHaveClass('highlighted') expect(listItems[8].querySelector('span')).toHaveTextContent( @@ -132,7 +137,7 @@ describe('Command Palette - List View - Browse Apps View', () => { ) const clearButton = getAllByRole('button')[1] - await user.click(clearButton) + await userEvent.click(clearButton) // back to normal list view/no filter view expect(queryByText(/All Apps/i)).toBeInTheDocument() diff --git a/components/header-bar/src/command-palette/__tests__/command-palette.test.js b/components/header-bar/src/command-palette/__tests__/command-palette.test.js index d4aa08de2..d1eb022b5 100644 --- a/components/header-bar/src/command-palette/__tests__/command-palette.test.js +++ b/components/header-bar/src/command-palette/__tests__/command-palette.test.js @@ -1,4 +1,8 @@ -import { render as originalRender, waitFor } from '@testing-library/react' +import { + render as originalRender, + waitFor, + waitForElementToBeRemoved, +} from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import PropTypes from 'prop-types' import React from 'react' @@ -105,10 +109,12 @@ describe('Command Palette Component', () => { // ctrl + / // open modal - await user.keyboard('{ctrl}/') + await user.keyboard('{meta>}/') expect(queryByTestId(modalTest)).toBeInTheDocument() + + await user.keyboard('{backspace}') // close modal - await user.keyboard('{ctrl}/') + await user.keyboard('{meta>}/') expect(queryByTestId(modalTest)).not.toBeInTheDocument() }) @@ -122,10 +128,11 @@ describe('Command Palette Component', () => { // meta + / // open modal - await user.keyboard('{meta}/') + await user.keyboard('{meta>}/') expect(queryByTestId(modalTest)).toBeInTheDocument() + await user.keyboard('{backspace}') // close modal - await user.keyboard('{meta}/') + await user.keyboard('{meta>}/') expect(queryByTestId(modalTest)).not.toBeInTheDocument() }) @@ -138,16 +145,18 @@ describe('Command Palette Component', () => { expect(queryByTestId(modalTest)).not.toBeInTheDocument() // open modal - await user.keyboard('{ctrl}/') + await user.keyboard('{meta>}/') await waitFor(() => expect(queryByTestId(modalTest)).toBeInTheDocument() ) + // ToDo: this is a workaround after react-18 upgrade + await user.keyboard('{backspace}') + // Esc key closes the modal - await user.keyboard('{esc}') - await waitFor(() => - expect(queryByTestId(modalTest)).not.toBeInTheDocument() - ) + await user.keyboard('{Escape}') + + expect(queryByTestId(modalTest)).not.toBeInTheDocument() }) })