Skip to content

Commit

Permalink
add jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dliu27 committed Dec 3, 2024
1 parent 3d4c8b3 commit a701abc
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const RunRequestTable = ({runRequests, isJob, repoAddress, mode, jobName}
</td>
<td style={{width: '7.5%', verticalAlign: 'middle', textAlign: 'center'}}>
<PreviewButton
request={request}
onClick={() => {
setSelectedRequest(request);
setVisibleDialog('config');
Expand Down Expand Up @@ -91,10 +92,14 @@ export const RunRequestTable = ({runRequests, isJob, repoAddress, mode, jobName}
);
};

function PreviewButton({onClick}: {onClick: () => void}) {
function PreviewButton({request, onClick}: {request: RunRequestFragment; onClick: () => void}) {
return (
<Tooltip content="Preview run config and tags" placement="left-start">
<Button icon={<Icon name="data_object" />} onClick={onClick} />
<Button
icon={<Icon name="data_object" />}
onClick={onClick}
data-testid={testId(`preview-${request.runKey || ''}`)}
/>
</Tooltip>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {render, screen} from '@testing-library/react';
import {render, screen, waitFor} from '@testing-library/react';
import {BrowserRouter} from 'react-router-dom';

import {RunRequestTable} from '../DryRunRequestTable';
Expand All @@ -9,6 +9,10 @@ jest.mock('../../workspace/WorkspaceContext/util', () => ({
useRepository: jest.fn(() => null),
}));

jest.mock('../../runs/RunConfigDialog', () => ({
RunConfigDialog: () => <div>RunConfigDialog</div>,
}));

function TestComponent() {
return (
<BrowserRouter>
Expand All @@ -31,10 +35,19 @@ describe('RunRequestTableTest', () => {
render(<TestComponent />);

runRequests.forEach((req) => {
req.tags.forEach(({key, value}) => {
expect(screen.getByText(`${key}: ${value}`)).toBeVisible();
});
expect(screen.getByTestId(req.runKey!)).toBeVisible();
});
});

it('renders preview button and opens dialog on click', async () => {
render(<TestComponent />);

const previewButton = screen.getByTestId(`preview-${runRequests[0]!.runKey || ''}`);
expect(previewButton).toBeVisible();
previewButton.click();

await waitFor(() => {
expect(screen.getByText(/RunConfigDialog/i)).toBeVisible();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,42 @@ describe('EvaluateScheduleTest', () => {
expect(screen.getByText('Skipped')).toBeVisible();
});
});

it('allows you to test again', async () => {
render(<Test mocks={[GetScheduleQueryMock, ScheduleDryRunMutationSkipped]} />);
const selectButton = await screen.findByTestId('tick-selection');
await userEvent.click(selectButton);
await waitFor(() => {
expect(screen.getByTestId('tick-5')).toBeVisible();
});
await userEvent.click(screen.getByTestId('tick-5'));
await userEvent.click(screen.getByTestId('continue'));
await waitFor(() => {
expect(screen.getByText('Skipped')).toBeVisible();
});
await userEvent.click(screen.getByTestId('try-again'));
expect(screen.queryByText('Failed')).toBe(null);
expect(screen.queryByText('Skipped')).toBe(null);
});

it('launches all runs', async () => {
render(<Test mocks={[GetScheduleQueryMock, ScheduleDryRunMutationRunRequests]} />);
const selectButton = await screen.findByTestId('tick-selection');
await userEvent.click(selectButton);
await waitFor(() => {
expect(screen.getByTestId('tick-5')).toBeVisible();
});
await userEvent.click(screen.getByTestId('tick-5'));
await userEvent.click(screen.getByTestId('continue'));
await waitFor(() => {
expect(screen.getByText(/1\s+run request/i)).toBeVisible();
expect(screen.getByTestId('launch-all')).not.toBeDisabled();
});

userEvent.click(screen.getByTestId('launch-all'));

await waitFor(() => {
expect(screen.getByText(/Launching runs/i)).toBeVisible();
});
}, 10000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ describe('SensorDryRunTest', () => {
});
});

it('renders skip reason', async () => {
render(<Test mocks={[Mocks.SensorDryRunMutationSkipped]} />);
const cursorInput = await screen.findByTestId('cursor-input');
await userEvent.type(cursorInput, 'testing123');
await userEvent.click(screen.getByTestId('continue'));
await waitFor(() => {
expect(screen.getByText('Skipped')).toBeVisible();
});
});

it('allows you to test again', async () => {
render(<Test mocks={[Mocks.SensorDryRunMutationError]} />);
const cursorInput = await screen.findByTestId('cursor-input');
Expand All @@ -72,13 +82,25 @@ describe('SensorDryRunTest', () => {
expect(screen.getByTestId('cursor-input')).toBeVisible();
});

it('renders skip reason', async () => {
render(<Test mocks={[Mocks.SensorDryRunMutationSkipped]} />);
it('launches all runs', async () => {
render(<Test mocks={[Mocks.SensorDryRunMutationRunRequests, Mocks.PersistCursorValueMock]} />);
const cursorInput = await screen.findByTestId('cursor-input');
await userEvent.type(cursorInput, 'testing123');
await userEvent.click(screen.getByTestId('continue'));
await waitFor(() => {
expect(screen.getByText('Skipped')).toBeVisible();
expect(screen.getByText(/3\srun requests/g)).toBeVisible();
expect(screen.queryByText('Skipped')).toBe(null);
expect(screen.queryByText('Failed')).toBe(null);
});
});

await waitFor(() => {
expect(screen.getByTestId('launch-all')).not.toBeDisabled();
});

userEvent.click(screen.getByTestId('launch-all'));

await waitFor(() => {
expect(screen.getByText(/Launching runs/i)).toBeVisible();
});
}, 10000);
});

0 comments on commit a701abc

Please sign in to comment.