Skip to content

Commit

Permalink
change tests
Browse files Browse the repository at this point in the history
  • Loading branch information
duyguHsnHsn committed Aug 7, 2023
1 parent 5340e5a commit ab2f1ba
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Dialog, showDialog } from '@jupyterlab/apputils';
import { jobData } from '../jobData';
import React from 'react';
import { VdkOption } from '../vdkOptions/vdk_options';
import {jobRunRequest } from '../serverRequests';
import DeployJobDialog, {
showCreateDeploymentDialog
} from '../components/DeployJob';

// Mock the showDialog function
jest.mock('@jupyterlab/apputils', () => ({
showDialog: jest.fn(),
Dialog: {
okButton: jest.fn(),
cancelButton: jest.fn()
}
}));
jest.mock('../serverRequests', () => ({
jobRunRequest: jest.fn(),
jobRequest: jest.fn()
}));

describe('showCreateDeploymentDialog', () => {
beforeEach(() => {
jobData.set(VdkOption.PATH, 'test/path');
jobData.set(VdkOption.NAME, 'test-name');
jobData.set(VdkOption.TEAM, 'test-team');
// Mock the result of the showDialog function
const mockResult = { button: { accept: true }, value: true };
(showDialog as jest.Mock).mockResolvedValueOnce(mockResult);
// Mock the jobRunRequest function
(jobRunRequest as jest.Mock).mockResolvedValueOnce({
message: 'Job completed successfully!',
status: true
});
});

it('should show a dialog with the Create Deployment title and a DeployJobDialog component as its body', async () => {
// Call the function
await showCreateDeploymentDialog();

// Expect the first showDialog function to have been called with the correct parameters
expect(showDialog).toHaveBeenCalledWith({
title: 'Create Deployment',
body: (
<>
<DeployJobDialog
jobName={jobData.get(VdkOption.NAME)!}
jobPath={jobData.get(VdkOption.PATH)!}
jobTeam={jobData.get(VdkOption.TEAM)!}
/>
<div>
<input
type="checkbox"
name="deployRun"
id="deployRun"
className="jp-vdk-checkbox"
onChange={expect.any(Function)}
/>
<label className="checkboxLabel" htmlFor="deployRun">
Run before deployment
</label>
</div>
</>
),
buttons: [Dialog.okButton(), Dialog.cancelButton()]
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import { jobRequest, jobRunRequest } from '../serverRequests';
import DownloadJobDialog, {
showDownloadJobDialog
} from '../components/DownloadJob';
import DeployJobDialog, {
showCreateDeploymentDialog
} from '../components/DeployJob';
import CreateJobDialog, { showCreateJobDialog } from '../components/CreateJob';
import { VdkErrorMessage } from '../components/VdkErrorMessage';

Expand Down Expand Up @@ -135,40 +132,6 @@ describe('showDownloadJobDialog', () => {
});
});

describe('showCreateDeploymentDialog', () => {
beforeEach(() => {
jobData.set(VdkOption.PATH, 'test/path');
jobData.set(VdkOption.NAME, 'test-name');
jobData.set(VdkOption.TEAM, 'test-team');
// Mock the result of the showDialog function
const mockResult = { button: { accept: true }, value: true };
(showDialog as jest.Mock).mockResolvedValueOnce(mockResult);
// Mock the jobRunRequest function
(jobRunRequest as jest.Mock).mockResolvedValueOnce({
message: 'Job completed successfully!',
status: true
});
});

it('should show a dialog with the Create Deployment title and a DeployJobDialog component as its body', async () => {
// Call the function
await showCreateDeploymentDialog();

// Expect the first showDialog function to have been called with the correct parameters
expect(showDialog).toHaveBeenCalledWith({
title: 'Create Deployment',
body: (
<DeployJobDialog
jobName={jobData.get(VdkOption.NAME)!}
jobPath={jobData.get(VdkOption.PATH)!}
jobTeam={jobData.get(VdkOption.TEAM)!}
/>
),
buttons: [Dialog.okButton(), Dialog.cancelButton()]
});
});
});

describe('showCreateJobDialog', () => {
beforeEach(() => {
jobData.set(VdkOption.PATH, 'test/path');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class DeployJobDialog extends Component<IJobFullProps> {
export async function showCreateDeploymentDialog() {
let runBeforeDeploy = false;

const handleCheckboxChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const handleCheckboxChange = (event: React.ChangeEvent<HTMLInputElement>) => {
runBeforeDeploy = event.target.checked;
};

Expand Down

0 comments on commit ab2f1ba

Please sign in to comment.