details.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {UptimeRuleFixture} from 'sentry-fixture/uptimeRule';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import UptimeAlertDetails from './details';
  5. describe('UptimeAlertDetails', function () {
  6. const {organization, project, routerProps} = initializeOrg();
  7. beforeEach(function () {
  8. MockApiClient.addMockResponse({
  9. url: `/organizations/${organization.slug}/projects/`,
  10. body: [project],
  11. });
  12. MockApiClient.addMockResponse({
  13. url: `/organizations/${organization.slug}/users/`,
  14. body: [],
  15. });
  16. MockApiClient.addMockResponse({
  17. url: `/organizations/${organization.slug}/issues/?limit=20&project=${project.id}&query=issue.category%3Auptime%20tags%5Buptime_rule%5D%3A1&statsPeriod=14d`,
  18. body: [],
  19. });
  20. });
  21. it('renders', async function () {
  22. MockApiClient.addMockResponse({
  23. url: `/projects/${organization.slug}/${project.slug}/uptime/1/`,
  24. body: UptimeRuleFixture({name: 'Uptime Test Rule'}),
  25. });
  26. render(
  27. <UptimeAlertDetails
  28. {...routerProps}
  29. params={{...routerProps.params, uptimeRuleId: '1'}}
  30. />,
  31. {organization}
  32. );
  33. expect(await screen.findByText('Uptime Test Rule')).toBeInTheDocument();
  34. });
  35. it('shows a message for invalid uptime alert', async function () {
  36. MockApiClient.addMockResponse({
  37. url: `/projects/${organization.slug}/${project.slug}/uptime/2/`,
  38. statusCode: 404,
  39. });
  40. render(
  41. <UptimeAlertDetails
  42. {...routerProps}
  43. params={{...routerProps.params, uptimeRuleId: '2'}}
  44. />,
  45. {organization}
  46. );
  47. expect(
  48. await screen.findByText('The uptime alert rule you were looking for was not found.')
  49. ).toBeInTheDocument();
  50. });
  51. it('disables and enables the rule', async function () {
  52. MockApiClient.addMockResponse({
  53. url: `/projects/${organization.slug}/${project.slug}/uptime/2/`,
  54. statusCode: 404,
  55. });
  56. MockApiClient.addMockResponse({
  57. url: `/projects/${organization.slug}/${project.slug}/uptime/1/`,
  58. body: UptimeRuleFixture({name: 'Uptime Test Rule'}),
  59. });
  60. render(
  61. <UptimeAlertDetails
  62. {...routerProps}
  63. params={{...routerProps.params, uptimeRuleId: '1'}}
  64. />,
  65. {organization}
  66. );
  67. await screen.findByText('Uptime Test Rule');
  68. const disableMock = MockApiClient.addMockResponse({
  69. url: `/projects/${organization.slug}/${project.slug}/uptime/1/`,
  70. method: 'PUT',
  71. body: UptimeRuleFixture({name: 'Uptime Test Rule', status: 'disabled'}),
  72. });
  73. await userEvent.click(
  74. await screen.findByRole('button', {
  75. name: 'Disable this uptime rule and stop performing checks',
  76. })
  77. );
  78. expect(disableMock).toHaveBeenCalledWith(
  79. expect.anything(),
  80. expect.objectContaining({data: {status: 'disabled'}})
  81. );
  82. const enableMock = MockApiClient.addMockResponse({
  83. url: `/projects/${organization.slug}/${project.slug}/uptime/1/`,
  84. method: 'PUT',
  85. body: UptimeRuleFixture({name: 'Uptime Test Rule', status: 'active'}),
  86. });
  87. // Button now re-enables the monitor
  88. await userEvent.click(
  89. await screen.findByRole('button', {name: 'Enable this uptime rule'})
  90. );
  91. expect(enableMock).toHaveBeenCalledWith(
  92. expect.anything(),
  93. expect.objectContaining({data: {status: 'active'}})
  94. );
  95. });
  96. });