-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update package.json dependencies * Fix legacy react code * Fix ESLint errors and warnings
- Loading branch information
Showing
39 changed files
with
5,693 additions
and
6,552 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,8 +1,8 @@ | ||
import { render } from "@testing-library/react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { App } from "./App"; | ||
|
||
test("should render", () => { | ||
const { getByText } = render(<App />); | ||
const header = getByText("Welcome to Bootzooka!"); | ||
render(<App />); | ||
const header = screen.getByText("Welcome to Bootzooka!"); | ||
expect(header).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
import React from "react"; | ||
import { render, fireEvent } from "@testing-library/react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { UserContextProvider, UserContext, UserAction } from "./UserContext"; | ||
import { userEvent } from "@testing-library/user-event"; | ||
|
||
const TestComponent: React.FC<{ action?: UserAction; label?: string }> = ({ action, label }) => { | ||
const { state, dispatch } = React.useContext(UserContext); | ||
return ( | ||
<> | ||
<div>{JSON.stringify(state)}</div> | ||
{action && <a onClick={() => dispatch(action)}>{label}</a>} | ||
{action && <button onClick={() => dispatch(action)}>{label}</button>} | ||
</> | ||
); | ||
}; | ||
|
||
test("handles set api key action", () => { | ||
const { getByText } = render( | ||
test("handles set api key action", async () => { | ||
render( | ||
<UserContextProvider> | ||
<TestComponent action={{ type: "SET_API_KEY", apiKey: "test-api-key" }} label="set api key" /> | ||
</UserContextProvider> | ||
</UserContextProvider>, | ||
); | ||
|
||
expect(getByText('{"apiKey":null,"user":null,"loggedIn":null}')).toBeInTheDocument(); | ||
expect(screen.getByText('{"apiKey":null,"user":null,"loggedIn":null}')).toBeInTheDocument(); | ||
|
||
fireEvent.click(getByText("set api key")); | ||
await userEvent.click(screen.getByText("set api key")); | ||
|
||
expect(getByText('{"apiKey":"test-api-key","user":null,"loggedIn":null}')).toBeInTheDocument(); | ||
expect(screen.getByText('{"apiKey":"test-api-key","user":null,"loggedIn":null}')).toBeInTheDocument(); | ||
}); | ||
|
||
test("handles login action", () => { | ||
const { getByText } = render( | ||
test("handles login action", async () => { | ||
render( | ||
<UserContextProvider> | ||
<TestComponent | ||
action={{ | ||
|
@@ -36,22 +37,22 @@ test("handles login action", () => { | |
}} | ||
label="log in" | ||
/> | ||
</UserContextProvider> | ||
</UserContextProvider>, | ||
); | ||
|
||
expect(getByText('{"apiKey":null,"user":null,"loggedIn":null}')).toBeInTheDocument(); | ||
expect(screen.getByText('{"apiKey":null,"user":null,"loggedIn":null}')).toBeInTheDocument(); | ||
|
||
fireEvent.click(getByText("log in")); | ||
await userEvent.click(screen.getByText("log in")); | ||
|
||
expect( | ||
getByText( | ||
'{"apiKey":null,"user":{"login":"user-login","email":"[email protected]","createdOn":"2020-10-09T09:57:17.995288Z"},"loggedIn":true}' | ||
) | ||
screen.getByText( | ||
'{"apiKey":null,"user":{"login":"user-login","email":"[email protected]","createdOn":"2020-10-09T09:57:17.995288Z"},"loggedIn":true}', | ||
), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
test("handles log in and update details action", () => { | ||
const { getAllByText, getByText } = render( | ||
test("handles log in and update details action", async () => { | ||
render( | ||
<UserContextProvider> | ||
<TestComponent | ||
action={{ | ||
|
@@ -67,34 +68,34 @@ test("handles log in and update details action", () => { | |
}} | ||
label="update user data" | ||
/> | ||
</UserContextProvider> | ||
</UserContextProvider>, | ||
); | ||
|
||
expect(getAllByText('{"apiKey":null,"user":null,"loggedIn":null}')[0]).toBeInTheDocument(); | ||
expect(screen.getAllByText('{"apiKey":null,"user":null,"loggedIn":null}')[0]).toBeInTheDocument(); | ||
|
||
fireEvent.click(getByText("update user data")); | ||
await userEvent.click(screen.getByText("update user data")); | ||
|
||
expect(getAllByText('{"apiKey":null,"user":null,"loggedIn":null}')[0]).toBeInTheDocument(); | ||
expect(screen.getAllByText('{"apiKey":null,"user":null,"loggedIn":null}')[0]).toBeInTheDocument(); | ||
|
||
fireEvent.click(getByText("log in")); | ||
await userEvent.click(screen.getByText("log in")); | ||
|
||
expect( | ||
getAllByText( | ||
'{"apiKey":null,"user":{"login":"user-login","email":"[email protected]","createdOn":"2020-10-09T09:57:17.995288Z"},"loggedIn":true}' | ||
)[0] | ||
screen.getAllByText( | ||
'{"apiKey":null,"user":{"login":"user-login","email":"[email protected]","createdOn":"2020-10-09T09:57:17.995288Z"},"loggedIn":true}', | ||
)[0], | ||
).toBeInTheDocument(); | ||
|
||
fireEvent.click(getByText("update user data")); | ||
await userEvent.click(screen.getByText("update user data")); | ||
|
||
expect( | ||
getAllByText( | ||
'{"apiKey":null,"user":{"login":"updated-user-login","email":"[email protected]","createdOn":"2020-10-09T09:57:17.995288Z"},"loggedIn":true}' | ||
)[0] | ||
screen.getAllByText( | ||
'{"apiKey":null,"user":{"login":"updated-user-login","email":"[email protected]","createdOn":"2020-10-09T09:57:17.995288Z"},"loggedIn":true}', | ||
)[0], | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
test("handles log in and log out action", () => { | ||
const { getAllByText, getByText } = render( | ||
test("handles log in and log out action", async () => { | ||
render( | ||
<UserContextProvider> | ||
<TestComponent | ||
action={{ | ||
|
@@ -109,24 +110,24 @@ test("handles log in and log out action", () => { | |
}} | ||
label="log out" | ||
/> | ||
</UserContextProvider> | ||
</UserContextProvider>, | ||
); | ||
|
||
expect(getAllByText('{"apiKey":null,"user":null,"loggedIn":null}')[0]).toBeInTheDocument(); | ||
expect(screen.getAllByText('{"apiKey":null,"user":null,"loggedIn":null}')[0]).toBeInTheDocument(); | ||
|
||
fireEvent.click(getByText("log out")); | ||
await userEvent.click(screen.getByText("log out")); | ||
|
||
expect(getAllByText('{"apiKey":null,"user":null,"loggedIn":false}')[0]).toBeInTheDocument(); | ||
expect(screen.getAllByText('{"apiKey":null,"user":null,"loggedIn":false}')[0]).toBeInTheDocument(); | ||
|
||
fireEvent.click(getByText("log in")); | ||
await userEvent.click(screen.getByText("log in")); | ||
|
||
expect( | ||
getAllByText( | ||
'{"apiKey":null,"user":{"login":"user-login","email":"[email protected]","createdOn":"2020-10-09T09:57:17.995288Z"},"loggedIn":true}' | ||
)[0] | ||
screen.getAllByText( | ||
'{"apiKey":null,"user":{"login":"user-login","email":"[email protected]","createdOn":"2020-10-09T09:57:17.995288Z"},"loggedIn":true}', | ||
)[0], | ||
).toBeInTheDocument(); | ||
|
||
fireEvent.click(getByText("log out")); | ||
await userEvent.click(screen.getByText("log out")); | ||
|
||
expect(getAllByText('{"apiKey":null,"user":null,"loggedIn":false}')[0]).toBeInTheDocument(); | ||
expect(screen.getAllByText('{"apiKey":null,"user":null,"loggedIn":false}')[0]).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
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,14 +1,14 @@ | ||
import { render } from "@testing-library/react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { ForkMe } from "./ForkMe"; | ||
|
||
test("renders image", () => { | ||
const { getByAltText } = render(<ForkMe />); | ||
const header = getByAltText(/fork me on github/i); | ||
render(<ForkMe />); | ||
const header = screen.getByAltText(/fork me on github/i); | ||
expect(header).toBeInTheDocument(); | ||
}); | ||
|
||
test("renders children", () => { | ||
const { getByText } = render(<ForkMe>test children content</ForkMe>); | ||
const header = getByText(/test children content/i); | ||
render(<ForkMe>test children content</ForkMe>); | ||
const header = screen.getByText(/test children content/i); | ||
expect(header).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
Oops, something went wrong.