commandPalette.spec.tsx 3.2 KB

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