commandPaletteModal.spec.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {openCommandPalette} from 'sentry/actionCreators/modal';
  3. import {navigateTo} from 'sentry/actionCreators/navigation';
  4. import FormSearchStore from 'sentry/stores/formSearchStore';
  5. import App from 'sentry/views/app';
  6. jest.mock('sentry/actionCreators/formSearch');
  7. jest.mock('sentry/actionCreators/navigation');
  8. describe('Command Palette Modal', function () {
  9. let orgsMock;
  10. beforeEach(function () {
  11. FormSearchStore.loadSearchMap([]);
  12. MockApiClient.clearMockResponses();
  13. orgsMock = MockApiClient.addMockResponse({
  14. url: '/organizations/',
  15. body: [TestStubs.Organization({slug: 'billy-org', name: 'billy org'})],
  16. });
  17. MockApiClient.addMockResponse({
  18. url: '/organizations/org-slug/projects/',
  19. query: 'foo',
  20. body: [TestStubs.Project({slug: 'foo-project'})],
  21. });
  22. MockApiClient.addMockResponse({
  23. url: '/organizations/org-slug/teams/',
  24. query: 'foo',
  25. body: [TestStubs.Team({slug: 'foo-team'})],
  26. });
  27. MockApiClient.addMockResponse({
  28. url: '/organizations/org-slug/members/',
  29. query: 'foo',
  30. body: TestStubs.Members(),
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/plugins/?plugins=_all',
  34. body: [],
  35. });
  36. MockApiClient.addMockResponse({
  37. url: '/organizations/org-slug/config/integrations/',
  38. body: [],
  39. });
  40. MockApiClient.addMockResponse({
  41. url: '/organizations/org-slug/plugins/configs/',
  42. body: [],
  43. });
  44. MockApiClient.addMockResponse({
  45. url: '/sentry-apps/?status=published',
  46. body: [],
  47. });
  48. MockApiClient.addMockResponse({
  49. url: '/doc-integrations/',
  50. body: [],
  51. });
  52. MockApiClient.addMockResponse({
  53. url: '/internal/health/',
  54. body: {
  55. problems: [],
  56. },
  57. });
  58. MockApiClient.addMockResponse({
  59. url: '/assistant/',
  60. body: [],
  61. });
  62. });
  63. it('can open command palette modal and search', async function () {
  64. const wrapper = mountWithTheme(
  65. <App params={{orgId: 'org-slug'}}>{<div>placeholder content</div>}</App>,
  66. TestStubs.routerContext([
  67. {
  68. router: TestStubs.router({
  69. params: {orgId: 'org-slug'},
  70. }),
  71. },
  72. ])
  73. );
  74. // No Modal
  75. expect(wrapper.find('Modal')).toHaveLength(0);
  76. openCommandPalette({params: {orgId: 'org-slug'}});
  77. await tick();
  78. await tick();
  79. wrapper.update();
  80. // Should have Modal + input
  81. expect(wrapper.find('Modal')).toHaveLength(1);
  82. wrapper.find('Modal input').simulate('change', {target: {value: 'bil'}});
  83. await tick();
  84. wrapper.update();
  85. expect(orgsMock).toHaveBeenCalledWith(
  86. expect.anything(),
  87. expect.objectContaining({
  88. // This nested 'query' is correct
  89. query: {query: 'bil'},
  90. })
  91. );
  92. expect(
  93. wrapper.find('SearchResult [data-test-id="badge-display-name"]').first().text()
  94. ).toBe('billy-org Dashboard');
  95. expect(wrapper.find('Modal SearchResultWrapper').first().prop('highlighted')).toBe(
  96. true
  97. );
  98. expect(wrapper.find('Modal SearchResultWrapper').at(1).prop('highlighted')).toBe(
  99. false
  100. );
  101. wrapper
  102. .find('SearchResult [data-test-id="badge-display-name"]')
  103. .first()
  104. .simulate('click');
  105. expect(navigateTo).toHaveBeenCalledWith('/billy-org/', expect.anything(), undefined);
  106. });
  107. });