123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import {UptimeRuleFixture} from 'sentry-fixture/uptimeRule';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import UptimeAlertDetails from './details';
- describe('UptimeAlertDetails', function () {
- const {organization, project, routerProps} = initializeOrg();
- beforeEach(function () {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [project],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/users/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/issues/?limit=20&project=${project.id}&query=issue.category%3Auptime%20tags%5Buptime_rule%5D%3A1&statsPeriod=14d`,
- body: [],
- });
- });
- it('renders', async function () {
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/uptime/1/`,
- body: UptimeRuleFixture({name: 'Uptime Test Rule'}),
- });
- render(
- <UptimeAlertDetails
- {...routerProps}
- params={{...routerProps.params, uptimeRuleId: '1'}}
- />,
- {organization}
- );
- expect(await screen.findByText('Uptime Test Rule')).toBeInTheDocument();
- });
- it('shows a message for invalid uptime alert', async function () {
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/uptime/2/`,
- statusCode: 404,
- });
- render(
- <UptimeAlertDetails
- {...routerProps}
- params={{...routerProps.params, uptimeRuleId: '2'}}
- />,
- {organization}
- );
- expect(
- await screen.findByText('The uptime alert rule you were looking for was not found.')
- ).toBeInTheDocument();
- });
- it('disables and enables the rule', async function () {
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/uptime/2/`,
- statusCode: 404,
- });
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/uptime/1/`,
- body: UptimeRuleFixture({name: 'Uptime Test Rule'}),
- });
- render(
- <UptimeAlertDetails
- {...routerProps}
- params={{...routerProps.params, uptimeRuleId: '1'}}
- />,
- {organization}
- );
- await screen.findByText('Uptime Test Rule');
- const disableMock = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/uptime/1/`,
- method: 'PUT',
- body: UptimeRuleFixture({name: 'Uptime Test Rule', status: 'disabled'}),
- });
- await userEvent.click(
- await screen.findByRole('button', {
- name: 'Disable this uptime rule and stop performing checks',
- })
- );
- expect(disableMock).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({data: {status: 'disabled'}})
- );
- const enableMock = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/uptime/1/`,
- method: 'PUT',
- body: UptimeRuleFixture({name: 'Uptime Test Rule', status: 'active'}),
- });
- // Button now re-enables the monitor
- await userEvent.click(
- await screen.findByRole('button', {name: 'Enable this uptime rule'})
- );
- expect(enableMock).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({data: {status: 'active'}})
- );
- });
- });
|