123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import {Members} from 'sentry-fixture/members';
- import {Organization} from 'sentry-fixture/organization';
- import {Project as ProjectFixture} from 'sentry-fixture/project';
- import {RouterContextFixture} from 'sentry-fixture/routerContextFixture';
- import {RouterFixture} from 'sentry-fixture/routerFixture';
- import {Team} from 'sentry-fixture/team';
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {navigateTo} from 'sentry/actionCreators/navigation';
- import {
- makeClosableHeader,
- makeCloseButton,
- ModalBody,
- ModalFooter,
- } from 'sentry/components/globalModal/components';
- import CommandPaletteModal from 'sentry/components/modals/commandPalette';
- import FormSearchStore from 'sentry/stores/formSearchStore';
- jest.mock('sentry/actionCreators/formSearch');
- jest.mock('sentry/actionCreators/navigation');
- function renderMockRequests() {
- FormSearchStore.loadSearchMap([]);
- const organization = MockApiClient.addMockResponse({
- url: '/organizations/',
- body: [Organization({slug: 'billy-org', name: 'billy org'})],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [ProjectFixture({slug: 'foo-project'})],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/teams/',
- body: [Team({slug: 'foo-team'})],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/members/',
- body: Members(),
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/plugins/?plugins=_all',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/config/integrations/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/plugins/configs/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/sentry-apps/?status=published',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/doc-integrations/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/internal/health/',
- body: {
- problems: [],
- },
- });
- MockApiClient.addMockResponse({
- url: '/assistant/',
- body: [],
- });
- return {organization};
- }
- describe('Command Palette Modal', function () {
- it('can open command palette modal and search', async function () {
- const mockRequests = renderMockRequests();
- render(
- <CommandPaletteModal
- Body={ModalBody}
- closeModal={jest.fn()}
- CloseButton={makeCloseButton(jest.fn())}
- Header={makeClosableHeader(jest.fn())}
- Footer={ModalFooter}
- />,
- {
- context: RouterContextFixture([
- {
- router: RouterFixture({
- params: {orgId: 'org-slug'},
- }),
- },
- ]),
- }
- );
- // NOTE: The `debounce` in `ApiSource` surprisingly only fires for the
- // first two typed characters of a sequence in most cases. This test only
- // types two characters to match in-app behaviour even though it's unclear
- // why it works that way
- await userEvent.type(screen.getByRole('textbox'), 'bi');
- expect(mockRequests.organization).toHaveBeenLastCalledWith(
- expect.anything(),
- expect.objectContaining({
- // This nested 'query' is correct
- query: {query: 'bi'},
- })
- );
- const badges = await screen.findAllByTestId('badge-display-name');
- expect(badges[0]).toHaveTextContent('billy-org Dashboard');
- expect(badges[1]).toHaveTextContent('billy-org Settings');
- await userEvent.click(badges[0]);
- expect(navigateTo).toHaveBeenCalledWith('/billy-org/', expect.anything(), undefined);
- });
- });
|