details.spec.tsx 3.6 KB

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