edit.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {MemberFixture} from 'sentry-fixture/member';
  2. import {TeamFixture} from 'sentry-fixture/team';
  3. import {UptimeRuleFixture} from 'sentry-fixture/uptimeRule';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {
  6. render,
  7. renderGlobalModal,
  8. screen,
  9. userEvent,
  10. within,
  11. } from 'sentry-test/reactTestingLibrary';
  12. import selectEvent from 'sentry-test/selectEvent';
  13. import OrganizationStore from 'sentry/stores/organizationStore';
  14. import {UptimeRulesEdit} from './edit';
  15. describe('uptime/edit', function () {
  16. beforeEach(function () {
  17. MockApiClient.addMockResponse({
  18. url: '/organizations/org-slug/members/',
  19. body: [MemberFixture()],
  20. });
  21. MockApiClient.addMockResponse({
  22. url: '/organizations/org-slug/teams/',
  23. body: [TeamFixture()],
  24. });
  25. });
  26. it('displays the edit form', async function () {
  27. const {organization, project, routerProps} = initializeOrg();
  28. OrganizationStore.onUpdate(organization);
  29. const uptimeRule = UptimeRuleFixture();
  30. const handleChangeTitle = jest.fn();
  31. MockApiClient.addMockResponse({
  32. url: `/projects/${organization.slug}/${project.slug}/uptime/${uptimeRule.id}/`,
  33. method: 'GET',
  34. body: uptimeRule,
  35. });
  36. render(
  37. <UptimeRulesEdit
  38. {...routerProps}
  39. onChangeTitle={handleChangeTitle}
  40. userTeamIds={[]}
  41. organization={organization}
  42. project={project}
  43. params={{projectId: project.slug, ruleId: uptimeRule.id}}
  44. />,
  45. {organization}
  46. );
  47. await screen.findByText('Configure Request');
  48. const url = screen.getByRole('textbox', {name: 'URL'});
  49. expect(url).toHaveValue(uptimeRule.url);
  50. const name = screen.getByRole('textbox', {name: 'Uptime rule name'});
  51. expect(name).toHaveValue(uptimeRule.name);
  52. await selectEvent.openMenu(screen.getByRole('textbox', {name: 'Owner'}));
  53. expect(screen.getByRole('menuitemradio', {name: 'Foo Bar'})).toBeChecked();
  54. });
  55. it('can delete rule', async function () {
  56. const {organization, project, routerProps} = initializeOrg();
  57. OrganizationStore.onUpdate(organization);
  58. const uptimeRule = UptimeRuleFixture();
  59. const handleChangeTitle = jest.fn();
  60. MockApiClient.addMockResponse({
  61. url: `/projects/${organization.slug}/${project.slug}/uptime/${uptimeRule.id}/`,
  62. method: 'GET',
  63. body: uptimeRule,
  64. });
  65. render(
  66. <UptimeRulesEdit
  67. {...routerProps}
  68. onChangeTitle={handleChangeTitle}
  69. userTeamIds={[]}
  70. organization={organization}
  71. project={project}
  72. params={{projectId: project.slug, ruleId: uptimeRule.id}}
  73. />,
  74. {organization}
  75. );
  76. await screen.findByText('Configure Request');
  77. const deleteRule = MockApiClient.addMockResponse({
  78. url: `/projects/${organization.slug}/${project.slug}/uptime/${uptimeRule.id}/`,
  79. method: 'DELETE',
  80. });
  81. renderGlobalModal();
  82. await userEvent.click(screen.getByRole('button', {name: 'Delete Rule'}));
  83. const modal = await screen.findByRole('dialog');
  84. await userEvent.click(within(modal).getByRole('button', {name: 'Delete Rule'}));
  85. expect(deleteRule).toHaveBeenCalled();
  86. });
  87. });