index.spec.tsx 3.0 KB

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