Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CoenWarmer committed Apr 26, 2023
1 parent da1cdab commit 20b116e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export function HeaderControl({ isLoading, slo }: Props) {
disabled={!hasWriteCapabilities}
icon="copy"
onClick={handleClone}
data-test-subj="sloActionsClone"
data-test-subj="sloDetailsHeaderControlPopoverClone"
>
{i18n.translate('xpack.observability.slo.slo.item.actions.clone', {
defaultMessage: 'Clone',
Expand All @@ -219,7 +219,7 @@ export function HeaderControl({ isLoading, slo }: Props) {
icon="trash"
disabled={!hasWriteCapabilities}
onClick={handleDelete}
data-test-subj="sloActionsDelete"
data-test-subj="sloDetailsHeaderControlPopoverDelete"
>
{i18n.translate('xpack.observability.slo.slo.item.actions.delete', {
defaultMessage: 'Delete',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,42 @@ describe('SLO Details Page', () => {
expect(screen.queryByTestId('sloDetailsHeaderControlPopoverCreateRule')).toBeTruthy();
});

it("renders a 'Manage rules' button under actions menu", async () => {
const slo = buildSlo();
useParamsMock.mockReturnValue(slo.id);
useFetchSloDetailsMock.mockReturnValue({ isLoading: false, slo });
useLicenseMock.mockReturnValue({ hasAtLeast: () => true });

render(<SloDetailsPage />);

fireEvent.click(screen.getByTestId('o11yHeaderControlActionsButton'));
expect(screen.queryByTestId('sloDetailsHeaderControlPopoverManageRules')).toBeTruthy();
});

it("renders a 'Clone' button under actions menu", async () => {
const slo = buildSlo();
useParamsMock.mockReturnValue(slo.id);
useFetchSloDetailsMock.mockReturnValue({ isLoading: false, slo });
useLicenseMock.mockReturnValue({ hasAtLeast: () => true });

render(<SloDetailsPage />);

fireEvent.click(screen.getByTestId('o11yHeaderControlActionsButton'));
expect(screen.queryByTestId('sloDetailsHeaderControlPopoverClone')).toBeTruthy();
});

it("renders a 'Delete' button under actions menu", async () => {
const slo = buildSlo();
useParamsMock.mockReturnValue(slo.id);
useFetchSloDetailsMock.mockReturnValue({ isLoading: false, slo });
useLicenseMock.mockReturnValue({ hasAtLeast: () => true });

render(<SloDetailsPage />);

fireEvent.click(screen.getByTestId('o11yHeaderControlActionsButton'));
expect(screen.queryByTestId('sloDetailsHeaderControlPopoverDelete')).toBeTruthy();
});

it('renders the Overview tab by default', async () => {
const slo = buildSlo();
useParamsMock.mockReturnValue(slo.id);
Expand Down
25 changes: 25 additions & 0 deletions x-pack/plugins/observability/public/pages/slos/slos.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,31 @@ describe('SLOs Page', () => {
expect(mockGetAddRuleFlyout).toBeCalled();
});

it('allows managing rules for an SLO', async () => {
useFetchSloListMock.mockReturnValue({ isLoading: false, sloList });

useFetchHistoricalSummaryMock.mockReturnValue({
isLoading: false,
sloHistoricalSummaryResponse: historicalSummaryData,
});

await act(async () => {
render(<SlosPage />);
});

screen.getAllByLabelText('Actions').at(0)?.click();

await waitForEuiPopoverOpen();

const button = screen.getByTestId('sloActionsManageRules');

expect(button).toBeTruthy();

button.click();

expect(mockNavigate).toBeCalled();
});

it('allows deleting an SLO', async () => {
useFetchSloListMock.mockReturnValue({ isLoading: false, sloList });

Expand Down

0 comments on commit 20b116e

Please sign in to comment.