Skip to content

Commit

Permalink
test: some more
Browse files Browse the repository at this point in the history
  • Loading branch information
fspoettel committed Jun 20, 2024
1 parent 5769bf1 commit a3a5ce5
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/components/cardset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function CardSet({ onChangeCardQuantity, onSelect, set }: Props) {
<Checkbox
checked={set.selected}
className={css["cardset-title"]}
data-testid="cardset-select"
disabled={!onSelect || !set.canSelect}
id={`card-set-${set.id}`}
label={set.title}
Expand Down
4 changes: 2 additions & 2 deletions src/components/deck-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export function DeckSummary({
</div>
)}
<div className={css["header-container"]}>
<h3 className={css["title"]}>
<h3 className={css["title"]} data-testid="deck-title">
{showValidation && !validation?.valid && <CircleAlert />}
{deck.name}
</h3>
<div className={css["header-row"]}>
<h4 className={css["sub"]}>
<h4 className={css["sub"]} data-testid="deck-investigator">
{deck.cards.investigator.card.real_name}
</h4>
<div className={css["stats"]}>
Expand Down
1 change: 1 addition & 0 deletions src/components/filters/cost-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function CostFilter({ id }: { id: number }) {
title="Cost"
>
<RangeSelect
data-testid="filters-cost"
id="cost-select"
label="Cost"
max={max}
Expand Down
1 change: 1 addition & 0 deletions src/components/filters/faction-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function FactionFilter({ id }: Props) {
return (
<ToggleGroup
className={css["faction-filter"]}
data-testid="filters-faction"
full
icons
onValueChange={handleValueChange}
Expand Down
1 change: 1 addition & 0 deletions src/components/filters/level-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export function LevelFilter({ id }: { id: number }) {
nonCollapsibleContent={
!filter.open && (
<ToggleGroup
data-testid="filters-level-shortcut"
full
onValueChange={handleApplyLevelShortcut}
type="single"
Expand Down
1 change: 1 addition & 0 deletions src/components/filters/type-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function TypeFilter({ id }: { id: number }) {
>
{!filter.open && activeList?.cardType === "player" && (
<ToggleGroup
data-testid="filters-type-shortcut"
full
onValueChange={handleApplyShortcut}
type="multiple"
Expand Down
24 changes: 11 additions & 13 deletions src/pages/browse/deck-collection/deck-collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,30 @@ export function DeckCollection() {
<DeckCollectionImport />
</Popover>
<Link asChild to="/deck/create">
<Button as="a">
<Button as="a" data-testid="create-trigger">
<Plus />
</Button>
</Link>
</div>
</header>
{decks.length ? (
<Scroller>
<ol className={css["decks"]} data-testid="collection">
<ol className={css["decks"]}>
{decks.map(({ deck, validation }) => (
<li
className={css["deck"]}
data-testid="collection-deck"
key={deck.id}
>
<Link asChild href={`/deck/view/${deck.id}`}>
<a>
<DeckSummary
deck={deck}
interactive
showThumbnail
validation={validation}
>
{deck.tags && <DeckTags tags={deck.tags} />}
</DeckSummary>
</a>
<Link href={`/deck/view/${deck.id}`}>
<DeckSummary
deck={deck}
interactive
showThumbnail
validation={validation}
>
{deck.tags && <DeckTags tags={deck.tags} />}
</DeckSummary>
</Link>
</li>
))}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/choose-investigator/choose-investigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ function DeckCreateChooseInvestigator() {
<CardList
renderListCardAction={(card) => (
<Link asChild to={`/deck/create/${card.code}`}>
<Button as="a" size="lg" variant="bare">
<Button
as="a"
data-testid="create-choose-investigator"
size="lg"
variant="bare"
>
<CirclePlusIcon />
</Button>
</Link>
Expand Down
10 changes: 9 additions & 1 deletion src/pages/deck-create/deck-create-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function DeckCreateEditor() {
<Field full padded>
<FieldLabel>Title</FieldLabel>
<input
data-testid="create-title"
onChange={handleInputChange}
type="text"
value={deckCreate.title}
Expand All @@ -111,6 +112,7 @@ export function DeckCreateEditor() {
<Field full padded>
<FieldLabel>Taboo Set</FieldLabel>
<Select
data-testid="create-taboo"
emptyLabel="None"
onChange={handleTabooSetChange}
options={tabooSets}
Expand All @@ -124,6 +126,7 @@ export function DeckCreateEditor() {
<FieldLabel>Investigator Front</FieldLabel>
<Select
data-side="front"
data-testid="create-investigator-front"
onChange={handleInvestigatorChange}
options={getInvestigatorOptions(investigator, "Front")}
required
Expand All @@ -134,6 +137,7 @@ export function DeckCreateEditor() {
<FieldLabel>Investigator Back</FieldLabel>
<Select
data-side="back"
data-testid="create-investigator-back"
onChange={handleInvestigatorChange}
options={getInvestigatorOptions(investigator, "Back")}
required
Expand Down Expand Up @@ -177,7 +181,11 @@ export function DeckCreateEditor() {
))}

<nav className={css["editor-nav"]}>
<Button onClick={handleDeckCreate} variant="primary">
<Button
data-testid="create-save"
onClick={handleDeckCreate}
variant="primary"
>
Create deck
</Button>
<Button onClick={goBack} type="button" variant="bare">
Expand Down
38 changes: 38 additions & 0 deletions tests/deck-create.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect, test } from "@playwright/test";

test("create deck", async ({ page }) => {

Check failure on line 3 in tests/deck-create.spec.ts

View workflow job for this annotation

GitHub Actions / Test

tests/deck-create.spec.ts

Error: Playwright Test did not expect test() to be called here. Most common reasons include: - You are calling test() in a configuration file. - You are calling test() in a file that is imported by the configuration file. - You have two different versions of @playwright/test. This usually happens when one of the dependencies in your package.json depends on @playwright/test. ❯ TestTypeImpl._currentSuite node_modules/playwright/lib/common/testType.js:71:13 ❯ TestTypeImpl._createTest node_modules/playwright/lib/common/testType.js:80:24 ❯ Module.<anonymous> node_modules/playwright/lib/transform/transform.js:256:12 ❯ tests/deck-create.spec.ts:3:1
await page.goto("http://localhost:3000/");
await page.getByTestId("create-trigger").click();
await page.getByTestId("search-input").click();
await page.getByTestId("search-input").fill("jenny");

await expect(page.getByTestId("cardlist-count")).toContainText("1 cards");

await page.getByTestId("create-choose-investigator").click();
await page.getByText("Replacements").click();
await page.getByLabel("Signatures").click();
await page.getByTestId("create-title").click();
await page.getByTestId("create-title").fill("Jenny Test");
await page.getByTestId("create-title").press("Tab");
await page.getByTestId("create-taboo").selectOption("7");
await page.getByTestId("create-save").click();

await expect(page.getByTestId("deck-investigator")).toContainText(
"Jenny Barnes",
);

await expect(page.getByTestId("deck-title")).toContainText("Jenny Test");

await expect(
page.getByRole("button", { name: "Green Man Medallion" }),
).toBeVisible();
await expect(
page.getByRole("button", { name: "Sacrificial Beast" }),
).toBeVisible();
await expect(
page.getByRole("button", { name: "Jenny's Twin .45s" }),
).not.toBeVisible();
await expect(
page.getByRole("button", { name: "Searching for Izzie" }),
).not.toBeVisible();
});
10 changes: 7 additions & 3 deletions tests/deck-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from "@playwright/test";

test("deck import", async ({ page }) => {

Check failure on line 3 in tests/deck-import.spec.ts

View workflow job for this annotation

GitHub Actions / Test

tests/deck-import.spec.ts

Error: Playwright Test did not expect test() to be called here. Most common reasons include: - You are calling test() in a configuration file. - You are calling test() in a file that is imported by the configuration file. - You have two different versions of @playwright/test. This usually happens when one of the dependencies in your package.json depends on @playwright/test. ❯ TestTypeImpl._currentSuite node_modules/playwright/lib/common/testType.js:71:13 ❯ TestTypeImpl._createTest node_modules/playwright/lib/common/testType.js:80:24 ❯ Module.<anonymous> node_modules/playwright/lib/transform/transform.js:256:12 ❯ tests/deck-import.spec.ts:3:1
await page.goto("http://localhost:3000/");

await page.getByTestId("import-trigger").click();
await page.getByTestId("import-input").click();
await page
Expand All @@ -10,7 +11,10 @@ test("deck import", async ({ page }) => {
"https://arkhamdb.com/decklist/view/47001/khaku-fifty-shades-of-blurse-fhv-intro-deck-guide-1.0",
);
await page.getByTestId("import-submit").click();
await expect(page.getByTestId("collection-deck").locator("h4")).toContainText(
"Kōhaku Narukami",
);
await expect(
page
.getByTestId("collection-deck")
.first()
.getByTestId("deck-investigator"),
).toContainText("Kōhaku Narukami");
});
32 changes: 32 additions & 0 deletions tests/filters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect, test } from "@playwright/test";

test("test", async ({ page }) => {

Check failure on line 3 in tests/filters.spec.ts

View workflow job for this annotation

GitHub Actions / Test

tests/filters.spec.ts

Error: Playwright Test did not expect test() to be called here. Most common reasons include: - You are calling test() in a configuration file. - You are calling test() in a file that is imported by the configuration file. - You have two different versions of @playwright/test. This usually happens when one of the dependencies in your package.json depends on @playwright/test. ❯ TestTypeImpl._currentSuite node_modules/playwright/lib/common/testType.js:71:13 ❯ TestTypeImpl._createTest node_modules/playwright/lib/common/testType.js:80:24 ❯ Module.<anonymous> node_modules/playwright/lib/transform/transform.js:256:12 ❯ tests/filters.spec.ts:3:1
await page.goto("http://localhost:3000/");
await page.getByTestId("filters-faction").getByTitle("Multiclass").click();
await page
.getByTestId("filters-type-shortcut")
.getByRole("button", { name: "Event" })
.click();
await page
.getByTestId("filters-level-shortcut")
.getByRole("radio", { name: "Level 1-5" })
.click();

await page
.locator("div")
.filter({ hasText: /^CostAll$/ })
.nth(1)
.click();

await page.getByLabel("Maximum").click();

for (let i = 0; i < 12; i++) {
await page.getByLabel("Maximum").press("ArrowLeft");
}

await expect(page.getByTestId("cardlist-count")).toContainText("1 cards");

await expect(
page.getByRole("figure").locator("div").filter({ hasText: "Snipe" }),
).toBeVisible();
});

0 comments on commit a3a5ce5

Please sign in to comment.