-
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.
chore: (frontend) initial frontend tests
Signed-off-by: Jacob Potter <pttr.jcb@gmail.com>
- Loading branch information
1 parent
78fea87
commit ea26f67
Showing
13 changed files
with
324 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ jobs: | |
run: npm run build | ||
|
||
- name: Test | ||
run: npm run test:browser | ||
run: npm run test | ||
|
||
|
||
|
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,3 +1,5 @@ | ||
|
||
.DS_Store | ||
api/.idea/dataSources.xml | ||
api/.idea/ | ||
/frontend/coverage/ | ||
/.vite/vitest/results.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {describe, expect, it, vi} from "vitest"; | ||
import {PokemonList} from "./PokemonList.tsx"; | ||
import {render} from "vitest-browser-react"; | ||
import pokemon_page_1 from '../../fixtures/pokemon_page_1.json' | ||
|
||
|
||
describe("PokemonList", () => { | ||
it("renders correctly", () => { | ||
const mockPokemonSelect = vi.fn(); | ||
const {getByRole} = render(<PokemonList pokemon={pokemon_page_1.pokemon} pokemonId={"3"} | ||
onPokemonSelect={mockPokemonSelect}/>); | ||
|
||
const buttons = getByRole("button"); | ||
|
||
expect(buttons.all()).toHaveLength(12) | ||
|
||
}) | ||
|
||
}) |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {describe, expect, it, vi} from "vitest"; | ||
import {render} from "vitest-browser-react"; | ||
import {PokemonListItem} from "./PokemonListItem.tsx"; | ||
import pokemon_page_1 from '../../fixtures/pokemon_page_1.json' | ||
|
||
|
||
describe("PokemonListItem", () => { | ||
|
||
const mockPokemonSelect = vi.fn() | ||
|
||
it("should render correctly", () => { | ||
const {getByText, getByRole} = render(<PokemonListItem pokemonSpecies={pokemon_page_1.pokemon[0]} | ||
onPokemonSelect={mockPokemonSelect}/>) | ||
|
||
|
||
expect(getByText("Bulbasaur")).toBeTruthy() | ||
expect(getByRole("img")).toBeTruthy | ||
}) | ||
|
||
it("should change style with active prop", () => { | ||
const {getByRole} = render(<PokemonListItem pokemonSpecies={pokemon_page_1.pokemon[0]} | ||
onPokemonSelect={mockPokemonSelect}/>) | ||
|
||
expect(getByRole("button").element().className.includes("active")) | ||
}) | ||
|
||
it("should pass id when clicked", async () => { | ||
const {getByRole} = render(<PokemonListItem pokemonSpecies={pokemon_page_1.pokemon[0]} | ||
onPokemonSelect={mockPokemonSelect}/>) | ||
|
||
const button = getByRole("button"); | ||
|
||
await button.click() | ||
|
||
expect(mockPokemonSelect).toHaveBeenCalledWith(1) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {describe, expect, it} from "vitest"; | ||
import {render} from "vitest-browser-react"; | ||
import {PokemonSummary} from "./PokemonSummary.tsx"; | ||
import pokemon_page_1 from '../../fixtures/pokemon_page_1.json' | ||
|
||
describe("PokemonSummary", () => { | ||
it("Should render correctly", () => { | ||
const {getByText} = render(<PokemonSummary pokemonSpecies={pokemon_page_1.pokemon[0]}/>); | ||
|
||
expect(getByText('Bulbasaur')).toBeTruthy | ||
}) | ||
}) |
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
16 changes: 16 additions & 0 deletions
16
frontend/src/components/ui/pokedex/KeyboardButton.spec.tsx
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {describe, expect, it, vi} from "vitest"; | ||
import {KeyboardButton} from "./KeyboardButton.tsx"; | ||
import {render} from "vitest-browser-react"; | ||
|
||
describe("KeyboardButton", () => { | ||
|
||
const mockOnClick = vi.fn() | ||
|
||
it("should render correctly", async () => { | ||
const {getByRole} = render(<KeyboardButton onClick={mockOnClick}/>); | ||
|
||
await getByRole("button").click() | ||
|
||
expect(mockOnClick).toHaveBeenCalled() | ||
}) | ||
}) |
Oops, something went wrong.