commandPalette.spec.tsx 3.3 KB

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