Skip to content

Commit

Permalink
Added mock functions for axios put and delete
Browse files Browse the repository at this point in the history
Added more test for Application
  • Loading branch information
Michael-Xie committed Jan 28, 2020
1 parent 922e489 commit 48bdebe
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/__mocks__/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,21 @@ export default {
data: fixtures.interviewers
});
}
}),
delete: jest.fn(url => {
if (url === "/api/appointments") {
return Promise.resolve({
status: 204,
statusText: "No Content"
});
}
}),
put: jest.fn((url, data) => {
return Promise.resolve({
status: 204,
statusText: "No Content",
data: data
});
})

};
2 changes: 1 addition & 1 deletion src/components/Appointment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function Appointment(props) {
.catch((error) => transition(ERROR_DELETE, true));
}
return (
<article className="appointment">
<article className="appointment" data-testid="appointment">
<Header time={props.time} />
{mode === EMPTY && <Empty onAdd={() => {
transition(CREATE);
Expand Down
36 changes: 30 additions & 6 deletions src/components/__tests__/Application.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
import React from "react";

import { render, cleanup, waitForElement, fireEvent } from "@testing-library/react";
import { render, cleanup, waitForElement, fireEvent, getByText, prettyDOM, getAllByTestId, getByPlaceholderText, getByAltText, getAllByText} from "@testing-library/react";

import Application from "components/Application";

afterEach(cleanup);
describe("Application", () => {
it("changes the schedule when a new day is selected", async () => {
const { getByText } = render(<Application />);

it("changes the schedule when a new day is selected", async () => {
const { getByText } = render(<Application />);
await waitForElement(() => getByText("Monday"));

await waitForElement(() => getByText("Monday"));
fireEvent.click(getByText("Tuesday"));

fireEvent.click(getByText("Tuesday"));
expect(getByText("Leopold Silvers")).toBeInTheDocument();
});

expect(getByText("Leopold Silvers")).toBeInTheDocument();
it("loads data, books an interview and reduces the spots remaining for the first day by 1", async () => {
const { container } = render(<Application />);

await waitForElement(() => getByText(container, "Archie Cohen"));

const appointments = getAllByTestId(container, "appointment");
const appointment = appointments[0];

fireEvent.click(getByAltText(appointment, "Add"));

fireEvent.change(getByPlaceholderText(appointment, /enter student name/i), {
target: { value: "Lydia Miller-Jones" }
});
fireEvent.click(getByAltText(appointment, "Sylvia Palmer"));

fireEvent.click(getByText(appointment, "Save"));
// expect(getByText(appointment, "Saving")).toBeInTheDocument();

// await waitForElement(() => getByText(appointment, "Lydia Miller-Jones"));
// getByText("Monday")
console.log(prettyDOM(appointment));
});
});
File renamed without changes.

0 comments on commit 48bdebe

Please sign in to comment.