newIssueExperienceButton.spec.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import {NewIssueExperienceButton} from 'sentry/views/issueDetails/actions/newIssueExperienceButton';
  3. describe('NewIssueExperienceButton', function () {
  4. it('triggers changes to the user config', async function () {
  5. const mockChangeUserSettings = MockApiClient.addMockResponse({
  6. url: '/users/me/',
  7. method: 'PUT',
  8. });
  9. render(<NewIssueExperienceButton />);
  10. const button = screen.getByRole('button', {
  11. name: 'Switch to the new issue experience',
  12. });
  13. await userEvent.click(button);
  14. // Text should change immediately
  15. expect(
  16. screen.getByRole('button', {name: 'Switch to the old issue experience'})
  17. ).toBeInTheDocument();
  18. // User option should be saved
  19. await waitFor(() => {
  20. expect(mockChangeUserSettings).toHaveBeenCalledWith(
  21. '/users/me/',
  22. expect.objectContaining({
  23. data: {
  24. options: {
  25. issueDetailsNewExperienceQ42023: true,
  26. },
  27. },
  28. })
  29. );
  30. });
  31. // Clicking again toggles it off
  32. await userEvent.click(button);
  33. // Old text should be back
  34. expect(
  35. screen.getByRole('button', {name: 'Switch to the new issue experience'})
  36. ).toBeInTheDocument();
  37. // And save the option as false
  38. await waitFor(() => {
  39. expect(mockChangeUserSettings).toHaveBeenCalledWith(
  40. '/users/me/',
  41. expect.objectContaining({
  42. data: {
  43. options: {
  44. issueDetailsNewExperienceQ42023: false,
  45. },
  46. },
  47. })
  48. );
  49. });
  50. });
  51. });