createSavedSearchModal.spec.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import selectEvent from 'react-select-event';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import CreateSavedSearchModal from 'sentry/views/issueList/createSavedSearchModal';
  4. import {IssueSortOptions} from 'sentry/views/issueList/utils';
  5. describe('CreateSavedSearchModal', function () {
  6. let createMock;
  7. const organization = TestStubs.Organization({
  8. access: ['org:write'],
  9. });
  10. function renderComponent() {
  11. return render(
  12. <CreateSavedSearchModal
  13. Header={p => p.children}
  14. Body={p => p.children}
  15. Footer={p => p.children}
  16. organization={organization}
  17. query="is:unresolved assigned:lyn@sentry.io"
  18. sort={IssueSortOptions.DATE}
  19. />
  20. );
  21. }
  22. beforeEach(function () {
  23. createMock = MockApiClient.addMockResponse({
  24. url: '/organizations/org-slug/searches/',
  25. method: 'POST',
  26. body: {id: '1', name: 'test', query: 'is:unresolved assigned:lyn@sentry.io'},
  27. });
  28. });
  29. afterEach(function () {
  30. MockApiClient.clearMockResponses();
  31. });
  32. it('saves a search when query is not changed', function () {
  33. renderComponent();
  34. userEvent.type(screen.getByRole('textbox', {name: 'Name'}), 'new search name');
  35. userEvent.click(screen.getByRole('button', {name: 'Save'}));
  36. expect(createMock).toHaveBeenCalledWith(
  37. expect.anything(),
  38. expect.objectContaining({
  39. data: {
  40. name: 'new search name',
  41. query: 'is:unresolved assigned:lyn@sentry.io',
  42. sort: IssueSortOptions.DATE,
  43. type: 0,
  44. },
  45. })
  46. );
  47. });
  48. it('saves a search when query is changed', async function () {
  49. renderComponent();
  50. userEvent.type(screen.getByRole('textbox', {name: 'Name'}), 'new search name');
  51. userEvent.clear(screen.getByRole('textbox', {name: 'Query'}));
  52. userEvent.type(screen.getByRole('textbox', {name: 'Query'}), 'is:resolved');
  53. await selectEvent.select(screen.getByText('Last Seen'), 'Priority');
  54. userEvent.click(screen.getByRole('button', {name: 'Save'}));
  55. expect(createMock).toHaveBeenCalledWith(
  56. '/organizations/org-slug/searches/',
  57. expect.objectContaining({
  58. data: {
  59. name: 'new search name',
  60. query: 'is:resolved',
  61. sort: IssueSortOptions.PRIORITY,
  62. type: 0,
  63. },
  64. })
  65. );
  66. });
  67. });