index.spec.tsx 3.3 KB

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