Skip to content

Commit

Permalink
refactor active character check
Browse files Browse the repository at this point in the history
  • Loading branch information
bduhbya committed Jun 20, 2024
1 parent 65c5ec3 commit 37221cc
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/app/components/CombatTracker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ describe("CombatTracker", () => {
mockSingleCharacterWarriorFile,
mockSingleCharacterWarriorFile,
];
// The expected active character index after each activation of the move down button
const expectedActiveCharacterIndex = [0, 1, 0];

for (let i = 0; i < mockCharacterFiles.length; i++) {
const expectedCharacterCount = i + 1;
Expand All @@ -134,17 +136,28 @@ describe("CombatTracker", () => {
);
}

var activeCharacterRow = getByTestId(`${activeCharacterTestId}0`);
expect(activeCharacterRow).not.toBeNull();
act(() => fireEvent.click(moveDownButton)); // Move the active character down
await waitFor(() => {
activeCharacterRow = getByTestId(`${activeCharacterTestId}1`);
expect(activeCharacterRow).not.toBeNull();
});
for (let i = 0; i < expectedActiveCharacterIndex.length; i++) {
await checkActiveCharacterIndex(
expectedActiveCharacterIndex[i],
getByTestId,
);
act(() => fireEvent.click(moveDownButton)); // Move the active character down
}
});

// Helper functions

async function checkActiveCharacterIndex(
expectedActiveCharacterIndex: number,
getByTestId: Function,
) {
const activeCharacterRowString = `${activeCharacterTestId}${expectedActiveCharacterIndex}`;
await waitFor(() => {
const activeCharacterRow = getByTestId(activeCharacterRowString);
expect(activeCharacterRow).not.toBeNull();
});
}

async function addCharacterAndCheck(
characterFile: File,
expectedCharacterCount: number,
Expand Down

0 comments on commit 37221cc

Please sign in to comment.