index.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {Members} from 'sentry-fixture/members';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {fireEvent, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {textWithMarkupMatcher} from 'sentry-test/utils';
  5. import {navigateTo} from 'sentry/actionCreators/navigation';
  6. import FormSearchStore from 'sentry/stores/formSearchStore';
  7. import SettingsSearch from 'sentry/views/settings/components/settingsSearch';
  8. jest.mock('sentry/actionCreators/formSearch');
  9. jest.mock('sentry/actionCreators/navigation');
  10. describe('SettingsSearch', function () {
  11. let orgsMock: jest.Mock;
  12. const routerContext = TestStubs.routerContext([
  13. {
  14. router: TestStubs.router({
  15. params: {},
  16. }),
  17. },
  18. ]);
  19. beforeEach(function () {
  20. FormSearchStore.loadSearchMap([]);
  21. MockApiClient.clearMockResponses();
  22. orgsMock = MockApiClient.addMockResponse({
  23. url: '/organizations/',
  24. body: [Organization({slug: 'billy-org', name: 'billy org'})],
  25. });
  26. MockApiClient.addMockResponse({
  27. url: '/organizations/org-slug/projects/',
  28. body: [TestStubs.Project({slug: 'foo-project'})],
  29. });
  30. MockApiClient.addMockResponse({
  31. url: '/organizations/org-slug/teams/',
  32. body: [TestStubs.Team({slug: 'foo-team'})],
  33. });
  34. MockApiClient.addMockResponse({
  35. url: '/organizations/org-slug/members/',
  36. body: Members(),
  37. });
  38. MockApiClient.addMockResponse({
  39. url: '/organizations/org-slug/plugins/?plugins=_all',
  40. body: [],
  41. });
  42. MockApiClient.addMockResponse({
  43. url: '/organizations/org-slug/plugins/configs/',
  44. body: [],
  45. });
  46. MockApiClient.addMockResponse({
  47. url: '/organizations/org-slug/config/integrations/',
  48. body: [],
  49. });
  50. MockApiClient.addMockResponse({
  51. url: '/sentry-apps/?status=published',
  52. body: [],
  53. });
  54. MockApiClient.addMockResponse({
  55. url: '/doc-integrations/',
  56. body: [],
  57. });
  58. });
  59. it('renders', function () {
  60. render(<SettingsSearch />);
  61. // renders input
  62. expect(screen.getByPlaceholderText('Search')).toBeInTheDocument();
  63. });
  64. it('can focus when hotkey is pressed', function () {
  65. render(<SettingsSearch />);
  66. fireEvent.keyDown(document.body, {key: 'Slash', code: 'Slash', keyCode: 191});
  67. expect(screen.getByPlaceholderText('Search')).toHaveFocus();
  68. });
  69. it('can search', async function () {
  70. render(<SettingsSearch />, {
  71. context: routerContext,
  72. });
  73. await userEvent.type(screen.getByPlaceholderText('Search'), 'bil');
  74. expect(orgsMock.mock.calls).toEqual([
  75. [
  76. '/organizations/',
  77. expect.objectContaining({
  78. // This nested 'query' is correct
  79. query: {query: 'b'},
  80. }),
  81. ],
  82. [
  83. '/organizations/',
  84. expect.objectContaining({
  85. // This nested 'query' is correct
  86. query: {query: 'bi'},
  87. }),
  88. ],
  89. ]);
  90. await userEvent.click(
  91. await screen.findByText(textWithMarkupMatcher('billy-org Dashboard'))
  92. );
  93. expect(navigateTo).toHaveBeenCalledWith('/billy-org/', expect.anything(), undefined);
  94. });
  95. });