commandPalette.spec.tsx 3.6 KB

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