Skip to content

Commit

Permalink
Completed writing and passing test for cancelling an interview
Browse files Browse the repository at this point in the history
Edited mock axios to include delete function
  • Loading branch information
Michael-Xie committed Jan 28, 2020
1 parent 1fc5f7e commit 715fc25
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
21 changes: 10 additions & 11 deletions src/__mocks__/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,18 @@ export default {
}
}),
delete: jest.fn(url => {
if (url === "/api/appointments") {
return Promise.resolve({
status: 204,
statusText: "No Content"
});
}
return Promise.resolve({
status: 204,
statusText: "No Content"
});
}),

put: jest.fn((url, data) => {
return Promise.resolve({
status: 204,
statusText: "No Content",
data: data
});
return Promise.resolve({
status: 204,
statusText: "No Content",
data: data
});
})

};
35 changes: 34 additions & 1 deletion src/components/__tests__/Application.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

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

import Application from "components/Application";

Expand Down Expand Up @@ -40,4 +40,37 @@ describe("Application", () => {
.find(day => queryByText(day, "Monday"));
expect(getByText(day, "no spots remaining")).toBeInTheDocument();
});

it("loads data, cancels an interview and increases the spots remaining for Monday by 1", async () => {
//1. Render the Application
const { container, debug } = render(<Application />);

// 2. Wait until the text "Archie Cohen" is displayed.
await waitForElement(() => getByText(container, "Archie Cohen"));

// 3. Click the "Delete" button on the booked appointment.
const appointment = getAllByTestId(container, "appointment").find(
appointment => queryByText(appointment, "Archie Cohen")
);

fireEvent.click(queryByAltText(appointment, "Delete"));

// 4. Check that the confirmation message is shown.
expect(getByText(appointment, "Are you sure you want to delete?")).toBeInTheDocument();

// 5. Click the "Confirm" button on the confirmation.
fireEvent.click(getByText(appointment, "Confirm"));

// 6. Check that the element with the text "Deleting" is displayed.
expect(getByText(appointment, "Deleting")).toBeInTheDocument();

// 7. Wait until the element with the "Add" button is displayed.
await waitForElement(() => getByAltText(appointment, "Add"));

// 8. Check that the DayListItem with the text "Monday" also has the text "2 spots remaining".
const day = getAllByTestId(container, "day")
.find(day => queryByText(day, "Monday"));

expect(getByText(day, "2 spots remaining")).toBeInTheDocument();
})
});

0 comments on commit 715fc25

Please sign in to comment.