Skip to content

Commit

Permalink
Merge pull request #37 from fabiothiroki/improvetest
Browse files Browse the repository at this point in the history
improve tests
  • Loading branch information
fabiothiroki committed May 2, 2021
2 parents 1f9ad4b + 25eb46f commit 502b069
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/components/App/tests/App.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { render, screen, waitFor, fireEvent } from "@testing-library/react";
import {
render,
screen,
waitFor,
fireEvent,
waitForElementToBeRemoved,
} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { rest } from "msw";
import { setupServer } from "msw/node";
import { QueryClientProvider, QueryClient } from "react-query";
import mockAirportResponse from "../../../services/Airport/test/mockAirportReponse";
import mockFlightResponse from "../../../services/Flight/tests/mockFlightResponse";
import App from "../App";
import FORM_FIELDS from "../../Search/constants";

const server = setupServer(
rest.get("https://api.skypicker.com/locations", (req, res, ctx) =>
res(ctx.json(mockAirportResponse))
),
rest.get("https://api.skypicker.com/flights", (req, res, ctx) =>
res(ctx.json(mockFlightResponse))
)
);

Expand Down Expand Up @@ -58,4 +68,12 @@ test("Search submit", async () => {
await waitFor(() => {
expect(screen.getByRole("progressbar")).toBeInTheDocument();
});

await waitForElementToBeRemoved(() => screen.getByRole("progressbar"));

expect(screen.queryByText(/Find cheap flights/i)).not.toBeInTheDocument();
expect(screen.getAllByText(/San Francisco/i).length).toEqual(2);
expect(screen.getAllByText(/San Diego/i).length).toEqual(2);
expect(screen.getByText(/88 EUR/i)).toBeInTheDocument();
expect(screen.getByText(/105 EUR/i)).toBeInTheDocument();
});

0 comments on commit 502b069

Please sign in to comment.