Skip to content

Commit

Permalink
Test for multiple characters
Browse files Browse the repository at this point in the history
  • Loading branch information
bduhbya committed Jun 20, 2024
1 parent 2b08925 commit 4a534ee
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/app/components/CombatTracker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, fireEvent, act, waitFor } from "@testing-library/react";
import { render, fireEvent, act, waitFor, queryAllByText } from "@testing-library/react";
import CombatTracker from "./CombatTracker";
import "@testing-library/jest-dom";
import React from "react";
Expand Down Expand Up @@ -119,22 +119,19 @@ describe("CombatTracker", () => {
});

it("moves current active character down correctly", async () => {
const { getByText } = render(<CombatTracker />);
const { getByText, queryAllByText } = render(<CombatTracker />);
const moveDownButton = getByText(strings.moveDownLabel);
const mockCharacterFiles = [
mockSingleCharacterWarriorFile,
mockSingleCharacterWarriorFile,
];
const mockCharacters = [
mockSingleCharacterWarrior,
mockSingleCharacterWarrior,
];

for (let i = 0; i < mockCharacters.length; i++) {
for (let i = 0; i < mockCharacterFiles.length; i++) {
(
promptForFile as jest.MockedFunction<typeof promptForFile>
).mockResolvedValue(mockCharacterFiles[i]);

const expectedCharacterCount = i + 1;
fireEvent.click(getByText(strings.addToCombatButton));

// Wait for promises to resolve
Expand All @@ -143,12 +140,12 @@ describe("CombatTracker", () => {
expect(getByText("Mock InitiativeInputDialog")).toBeInTheDocument(),
);
handleConfirmHook(addedCharacter);
await waitFor(() =>
expect(getByText(addedCharacter.name)).toBeInTheDocument(),
);
expect(
getByText(addedCharacter.initiative.toString()),
).toBeInTheDocument();
await waitFor(() =>{
const characterElements = queryAllByText(addedCharacter.name);
expect(characterElements.length === expectedCharacterCount);
});
const initiativeElements = queryAllByText(addedCharacter.initiative.toString());
expect(initiativeElements.length === expectedCharacterCount);
}
});
});

0 comments on commit 4a534ee

Please sign in to comment.