index.spec.tsx 3.0 KB

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