archive.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. } from 'sentry-test/reactTestingLibrary';
  7. import ArchiveActions from 'sentry/components/actions/archive';
  8. import {GroupStatus} from 'sentry/types';
  9. describe('ArchiveActions', () => {
  10. const onUpdate = jest.fn();
  11. afterEach(() => {
  12. jest.resetAllMocks();
  13. });
  14. it('archives the issue', async () => {
  15. render(<ArchiveActions onUpdate={onUpdate} />);
  16. await userEvent.click(screen.getByRole('button', {name: 'Archive'}));
  17. expect(onUpdate).toHaveBeenCalledWith({
  18. status: GroupStatus.IGNORED,
  19. statusDetails: {},
  20. substatus: 'archived_until_escalating',
  21. });
  22. });
  23. it('archives forever', async () => {
  24. render(<ArchiveActions onUpdate={onUpdate} />);
  25. await userEvent.click(screen.getByRole('button', {name: 'Archive options'}));
  26. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Forever'}));
  27. expect(onUpdate).toHaveBeenCalledWith({
  28. status: 'ignored',
  29. statusDetails: {},
  30. substatus: 'archived_forever',
  31. });
  32. });
  33. it('displays confirmation', async () => {
  34. render(
  35. <ArchiveActions
  36. onUpdate={onUpdate}
  37. shouldConfirm
  38. confirmMessage={() => 'Archive 5 issues'}
  39. />
  40. );
  41. renderGlobalModal();
  42. await userEvent.click(screen.getByRole('button', {name: 'Archive'}));
  43. // Confirm dialog
  44. expect(screen.getByText('Archive 5 issues')).toBeInTheDocument();
  45. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  46. expect(onUpdate).toHaveBeenCalledWith({
  47. status: GroupStatus.IGNORED,
  48. statusDetails: {},
  49. substatus: 'archived_until_escalating',
  50. });
  51. });
  52. it('disables button and dropdown', () => {
  53. render(<ArchiveActions onUpdate={onUpdate} disabled />);
  54. expect(screen.getByRole('button', {name: 'Archive'})).toBeDisabled();
  55. expect(screen.getByRole('button', {name: 'Archive options'})).toBeDisabled();
  56. });
  57. it('has ignore actions', async () => {
  58. render(<ArchiveActions onUpdate={onUpdate} />);
  59. await userEvent.click(screen.getByRole('button', {name: 'Archive options'}));
  60. await userEvent.hover(screen.getByRole('menuitemradio', {name: 'For\u2026'}));
  61. await userEvent.click(screen.getByRole('menuitemradio', {name: '30 minutes'}));
  62. expect(onUpdate).toHaveBeenCalledWith({
  63. status: 'ignored',
  64. statusDetails: {ignoreDuration: 30},
  65. substatus: 'archived_until_condition_met',
  66. });
  67. });
  68. it('does render archive until occurrence options', async () => {
  69. render(<ArchiveActions onUpdate={onUpdate} disableArchiveUntilOccurrence={false} />);
  70. await userEvent.click(screen.getByRole('button', {name: 'Archive options'}));
  71. expect(
  72. screen.queryByRole('menuitemradio', {name: 'Until this occurs again\u2026'})
  73. ).toBeInTheDocument();
  74. expect(
  75. screen.queryByRole('menuitemradio', {
  76. name: 'Until this affects an additional\u2026',
  77. })
  78. ).toBeInTheDocument();
  79. });
  80. it('does not render archive until occurrence options', async () => {
  81. render(<ArchiveActions onUpdate={onUpdate} disableArchiveUntilOccurrence />);
  82. await userEvent.click(screen.getByRole('button', {name: 'Archive options'}));
  83. expect(
  84. screen.queryByRole('menuitemradio', {name: 'Until this occurs again\u2026'})
  85. ).not.toBeInTheDocument();
  86. expect(
  87. screen.queryByRole('menuitemradio', {
  88. name: 'Until this affects an additional\u2026',
  89. })
  90. ).not.toBeInTheDocument();
  91. });
  92. });