index.spec.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {fireEvent, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {textWithMarkupMatcher} from 'sentry-test/utils';
  3. import {navigateTo} from 'sentry/actionCreators/navigation';
  4. import FormSearchStore from 'sentry/stores/formSearchStore';
  5. import SettingsSearch from 'sentry/views/settings/components/settingsSearch';
  6. jest.mock('sentry/actionCreators/formSearch');
  7. jest.mock('sentry/actionCreators/navigation');
  8. describe('SettingsSearch', function () {
  9. let orgsMock;
  10. const routerContext = TestStubs.routerContext([
  11. {
  12. router: TestStubs.router({
  13. params: {},
  14. }),
  15. },
  16. ]);
  17. beforeEach(function () {
  18. FormSearchStore.loadSearchMap([]);
  19. MockApiClient.clearMockResponses();
  20. orgsMock = MockApiClient.addMockResponse({
  21. url: '/organizations/',
  22. body: [TestStubs.Organization({slug: 'billy-org', name: 'billy org'})],
  23. });
  24. MockApiClient.addMockResponse({
  25. url: '/organizations/org-slug/projects/',
  26. query: 'foo',
  27. body: [TestStubs.Project({slug: 'foo-project'})],
  28. });
  29. MockApiClient.addMockResponse({
  30. url: '/organizations/org-slug/teams/',
  31. query: 'foo',
  32. body: [TestStubs.Team({slug: 'foo-team'})],
  33. });
  34. MockApiClient.addMockResponse({
  35. url: '/organizations/org-slug/members/',
  36. query: 'foo',
  37. body: TestStubs.Members(),
  38. });
  39. MockApiClient.addMockResponse({
  40. url: '/organizations/org-slug/plugins/?plugins=_all',
  41. query: 'foo',
  42. body: [],
  43. });
  44. MockApiClient.addMockResponse({
  45. url: '/organizations/org-slug/plugins/configs/',
  46. body: [],
  47. });
  48. MockApiClient.addMockResponse({
  49. url: '/organizations/org-slug/config/integrations/',
  50. query: 'foo',
  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 params={{}} />);
  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. });