commandPalette.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {MembersFixture} from 'sentry-fixture/members';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {RouterFixture} from 'sentry-fixture/routerFixture';
  5. import {TeamFixture} from 'sentry-fixture/team';
  6. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  7. import {navigateTo} from 'sentry/actionCreators/navigation';
  8. import {
  9. makeClosableHeader,
  10. makeCloseButton,
  11. ModalBody,
  12. ModalFooter,
  13. } from 'sentry/components/globalModal/components';
  14. import CommandPaletteModal from 'sentry/components/modals/commandPalette';
  15. import FormSearchStore from 'sentry/stores/formSearchStore';
  16. jest.mock('sentry/actionCreators/formSearch');
  17. jest.mock('sentry/actionCreators/navigation');
  18. function renderMockRequests() {
  19. FormSearchStore.loadSearchMap([]);
  20. const organization = MockApiClient.addMockResponse({
  21. url: '/organizations/',
  22. body: [OrganizationFixture({slug: 'billy-org', name: 'billy org'})],
  23. });
  24. MockApiClient.addMockResponse({
  25. url: '/organizations/org-slug/projects/',
  26. body: [ProjectFixture({slug: 'foo-project'})],
  27. });
  28. MockApiClient.addMockResponse({
  29. url: '/organizations/org-slug/teams/',
  30. body: [TeamFixture({slug: 'foo-team'})],
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/members/',
  34. body: MembersFixture(),
  35. });
  36. MockApiClient.addMockResponse({
  37. url: '/organizations/org-slug/plugins/?plugins=_all',
  38. body: [],
  39. });
  40. MockApiClient.addMockResponse({
  41. url: '/organizations/org-slug/config/integrations/',
  42. body: [],
  43. });
  44. MockApiClient.addMockResponse({
  45. url: '/organizations/org-slug/plugins/configs/',
  46. body: [],
  47. });
  48. MockApiClient.addMockResponse({
  49. url: '/sentry-apps/?status=published',
  50. body: [],
  51. });
  52. MockApiClient.addMockResponse({
  53. url: '/doc-integrations/',
  54. body: [],
  55. });
  56. MockApiClient.addMockResponse({
  57. url: '/assistant/',
  58. body: [],
  59. });
  60. return {organization};
  61. }
  62. describe('Command Palette Modal', function () {
  63. it('can open command palette modal and search', async function () {
  64. const mockRequests = renderMockRequests();
  65. render(
  66. <CommandPaletteModal
  67. Body={ModalBody}
  68. closeModal={jest.fn()}
  69. CloseButton={makeCloseButton(jest.fn())}
  70. Header={makeClosableHeader(jest.fn())}
  71. Footer={ModalFooter}
  72. />,
  73. {
  74. router: RouterFixture({
  75. params: {orgId: 'org-slug'},
  76. }),
  77. }
  78. );
  79. // NOTE: The `debounce` in `ApiSource` surprisingly only fires for the
  80. // first two typed characters of a sequence in most cases. This test only
  81. // types two characters to match in-app behaviour even though it's unclear
  82. // why it works that way
  83. await userEvent.type(screen.getByRole('textbox'), 'bi');
  84. expect(mockRequests.organization).toHaveBeenLastCalledWith(
  85. expect.anything(),
  86. expect.objectContaining({
  87. // This nested 'query' is correct
  88. query: {query: 'bi'},
  89. })
  90. );
  91. const badges = await screen.findAllByTestId('badge-display-name');
  92. expect(badges[0]).toHaveTextContent('billy-org Dashboard');
  93. expect(badges[1]).toHaveTextContent('billy-org Settings');
  94. await userEvent.click(badges[0]);
  95. expect(navigateTo).toHaveBeenCalledWith('/billy-org/', expect.anything(), undefined);
  96. });
  97. });