Skip to content

Commit

Permalink
alert-dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Dec 18, 2024
1 parent 0537886 commit 31b3012
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
import { AlertRequest, ApiServerModelsAlertsAlertRequestTier } from 'api-client';
import React from 'react';
import { describe, it, vi } from 'vitest';
import { describe, expect, it, vi } from 'vitest';

import { RmfApiProvider } from '../hooks';
import { MockRmfApi, render, TestProviders } from '../utils/test-utils.test';
import { AlertManager } from './alert-manager';
import { AlertDialog, AlertManager } from './alert-manager';

describe('Alert dialog', () => {
const rmfApi = new MockRmfApi();
rmfApi.alertsApi.getAlertResponseAlertsRequestAlertIdResponseGet = vi
.fn()
.mockResolvedValue({ data: [] });
rmfApi.tasksApi.getTaskLogTasksTaskIdLogGet = () => new Promise(() => {});

const Base = (props: React.PropsWithChildren<{}>) => {
return (
<TestProviders>
<RmfApiProvider value={rmfApi}>{props.children}</RmfApiProvider>
</TestProviders>
);
};

it('renders without crashing', () => {
const alertRequest: AlertRequest = {
id: 'test-alert',
unix_millis_alert_time: 0,
title: 'Test Alert',
subtitle: 'Test subtitle',
message: 'This is a test alert',
tier: ApiServerModelsAlertsAlertRequestTier.Error,
responses_available: ['ok'],
display: true,
task_id: 'test-task',
alert_parameters: [],
};
const onDismiss = vi.fn();

const root = render(
<Base>
<AlertDialog alertRequest={alertRequest} onDismiss={onDismiss} />
</Base>,
);
expect(root.getByText('Test Alert')).toBeTruthy();
expect(root.getByText('This is a test alert')).toBeTruthy();
expect(root.getByTestId('test-alert-ok-button')).toBeTruthy();
expect(root.getByTestId('task-cancel-button')).toBeTruthy();
expect(root.getByTestId('dismiss-button')).toBeTruthy();
});
});

describe('Alert manager', () => {
const rmfApi = new MockRmfApi();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import { useAppController, useRmfApi } from '../hooks';
import { AppEvents } from './app-events';
import { TaskCancelButton } from './tasks/task-cancellation';

interface AlertDialogProps {
export interface AlertDialogProps {
alertRequest: AlertRequest;
onDismiss: () => void;
}

const AlertDialog = React.memo((props: AlertDialogProps) => {
export const AlertDialog = React.memo((props: AlertDialogProps) => {
const { alertRequest, onDismiss } = props;
const [isOpen, setIsOpen] = React.useState(true);
const { showAlert } = useAppController();
Expand Down Expand Up @@ -196,6 +196,7 @@ const AlertDialog = React.memo((props: AlertDialogProps) => {
variant="contained"
autoFocus
key={`${alertRequest.id}-${response}`}
data-testid={`${alertRequest.id}-${response}-button`}
sx={{
fontSize: '1rem',
padding: '6px 12px',
Expand All @@ -211,6 +212,7 @@ const AlertDialog = React.memo((props: AlertDialogProps) => {
})}
{alertRequest.task_id ? (
<TaskCancelButton
data-testid="task-cancel-button"
taskId={alertRequest.task_id}
size="small"
variant="contained"
Expand All @@ -223,6 +225,7 @@ const AlertDialog = React.memo((props: AlertDialogProps) => {
/>
) : null}
<Button
data-testid="dismiss-button"
size="small"
variant="contained"
autoFocus
Expand Down

0 comments on commit 31b3012

Please # to comment.