-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from fabiothiroki/apptesteal
Apptesteal
- Loading branch information
Showing
4 changed files
with
82 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,61 @@ | ||
import { render, screen, waitFor, fireEvent } 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 App from "../App"; | ||
import FORM_FIELDS from "../../Search/constants"; | ||
|
||
test("Render initial state", () => { | ||
expect(App).toBeDefined(); | ||
const server = setupServer( | ||
rest.get("https://api.skypicker.com/locations", (req, res, ctx) => | ||
res(ctx.json(mockAirportResponse)) | ||
) | ||
); | ||
|
||
const renderComponent = () => { | ||
const queryClient = new QueryClient(); | ||
return render( | ||
<QueryClientProvider client={queryClient}> | ||
<App /> | ||
</QueryClientProvider> | ||
); | ||
}; | ||
|
||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
test("Render form and results", async () => { | ||
renderComponent(); | ||
|
||
expect(screen.queryByText(/Search Flights/i)).toBeInTheDocument(); | ||
|
||
await waitFor(() => { | ||
expect(screen.queryByText(/Find cheap flights/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test("Search submit", async () => { | ||
renderComponent(); | ||
|
||
userEvent.type(screen.getByRole("textbox", { name: "From" }), "prag"); | ||
userEvent.click(await screen.findByText(/prague/i)); | ||
|
||
userEvent.type(screen.getByRole("textbox", { name: "To" }), "prag"); | ||
userEvent.click(await screen.findByText(/prague/i)); | ||
|
||
fireEvent.change(screen.getByTestId(FORM_FIELDS.DEPARTURE_DATE), { | ||
target: { value: "2020-05-13" }, | ||
}); | ||
|
||
fireEvent.change(screen.getByTestId(FORM_FIELDS.RETURN_DATE), { | ||
target: { value: "2020-05-15" }, | ||
}); | ||
|
||
fireEvent.submit(screen.getByTestId("submitButton")); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole("progressbar")).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters