index.spec.tsx 3.1 KB

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