index.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: jest.Mock;
  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. body: [TestStubs.Project({slug: 'foo-project'})],
  27. });
  28. MockApiClient.addMockResponse({
  29. url: '/organizations/org-slug/teams/',
  30. body: [TestStubs.Team({slug: 'foo-team'})],
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/members/',
  34. body: TestStubs.Members(),
  35. });
  36. MockApiClient.addMockResponse({
  37. url: '/organizations/org-slug/plugins/?plugins=_all',
  38. body: [],
  39. });
  40. MockApiClient.addMockResponse({
  41. url: '/organizations/org-slug/plugins/configs/',
  42. body: [],
  43. });
  44. MockApiClient.addMockResponse({
  45. url: '/organizations/org-slug/config/integrations/',
  46. body: [],
  47. });
  48. MockApiClient.addMockResponse({
  49. url: '/sentry-apps/?status=published',
  50. body: [],
  51. });
  52. MockApiClient.addMockResponse({
  53. url: '/doc-integrations/',
  54. body: [],
  55. });
  56. });
  57. it('renders', function () {
  58. render(<SettingsSearch />);
  59. // renders input
  60. expect(screen.getByPlaceholderText('Search')).toBeInTheDocument();
  61. });
  62. it('can focus when hotkey is pressed', function () {
  63. render(<SettingsSearch />);
  64. fireEvent.keyDown(document.body, {key: 'Slash', code: 'Slash', keyCode: 191});
  65. expect(screen.getByPlaceholderText('Search')).toHaveFocus();
  66. });
  67. it('can search', async function () {
  68. render(<SettingsSearch />, {
  69. context: routerContext,
  70. });
  71. await userEvent.type(screen.getByPlaceholderText('Search'), 'bil');
  72. expect(orgsMock.mock.calls).toEqual([
  73. [
  74. '/organizations/',
  75. expect.objectContaining({
  76. // This nested 'query' is correct
  77. query: {query: 'b'},
  78. }),
  79. ],
  80. [
  81. '/organizations/',
  82. expect.objectContaining({
  83. // This nested 'query' is correct
  84. query: {query: 'bi'},
  85. }),
  86. ],
  87. ]);
  88. await userEvent.click(
  89. await screen.findByText(textWithMarkupMatcher('billy-org Dashboard'))
  90. );
  91. expect(navigateTo).toHaveBeenCalledWith('/billy-org/', expect.anything(), undefined);
  92. });
  93. });