index.spec.tsx 3.2 KB

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