Skip to content

Commit

Permalink
test for job application dialog (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
januschung authored Dec 18, 2023
1 parent 71e8002 commit edced46
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/components/JobApplicationDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ export default function JobApplicationDialog({jobApplication, handleClose, open,
required
id="companyName"
name="companyName"
label="Company name"
label="Company Name"
fullWidth
autoComplete="given-name"
variant="standard"
onChange={(e) => {
setCompanyName(e.target.value);
}}
defaultValue={jobApplication.companyName}
// defaultValue={companyName}
/>

<TextField
Expand Down
54 changes: 54 additions & 0 deletions src/components/__tests__/JobApplicationDialog.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { render, screen } from '@testing-library/react';
import JobApplicationDialog from '../JobApplicationDialog';
import { MockedProvider } from "@apollo/client/testing";
import dayjs from 'dayjs';


const mocks = [];

it('Should render New Job Application Dialog', async() => {
render(<MockedProvider mocks={mocks} addTypename={false}>
<JobApplicationDialog
jobApplication={{"status": "open"}}
open={true}
setOpen={false}
isNew={true} />
</MockedProvider>
);

expect(screen.getByText("Add Job Application")).toBeInTheDocument();
expect(screen.getByDisplayValue("open")).toBeInTheDocument();
const currentDate = dayjs(new Date()).format('MM/DD/YYYY')
expect(screen.getByDisplayValue(currentDate)).toBeInTheDocument();
expect(screen.getByText("Company Name")).toBeInTheDocument();
expect(screen.getByText("Job Title")).toBeInTheDocument();
expect(screen.getByText("Salary Range")).toBeInTheDocument();
expect(screen.getByText("Description")).toBeInTheDocument();
expect(screen.getByText("Job Link")).toBeInTheDocument();

});

it('Should render Edit Job Application Dialog', async() => {
render(<MockedProvider mocks={mocks} addTypename={false}>
<JobApplicationDialog
jobApplication={{"companyName": "a",
"jobTitle": "b",
"salaryRange": "c",
"description": "d",
"jobUrl": "http://example.com",
"appliedDate": '2021-01-01',
"status": "active"}}
open={true}
setOpen={false}
isNew={false} />
</MockedProvider>
);
expect(screen.getByText("Edit Job Application")).toBeInTheDocument();
expect(screen.getByDisplayValue("a")).toHaveAttribute('id', 'companyName');
expect(screen.getByDisplayValue("b")).toHaveAttribute('id', 'jobTitle');
expect(screen.getByDisplayValue("c")).toHaveAttribute('id', 'salaryRange');
expect(screen.getByDisplayValue("d")).toHaveAttribute('id', 'description');
expect(screen.getByDisplayValue("http://example.com")).toHaveAttribute('id', 'jobUrl');
expect(screen.getByDisplayValue('01/01/2021')).toBeInTheDocument();
expect(screen.getByDisplayValue("active")).toBeInTheDocument();
});

0 comments on commit edced46

Please sign in to comment.