Files
OpenFrontIO/tests/client/TestSkinExecution.test.ts
T
Ryan 3c0b5149b5 [Feature] Test a skin (#2857)
## Description:

It lets users test skins :)
<img width="847" height="734" alt="image"
src="https://github.com/user-attachments/assets/55ed112c-a401-417d-bc39-06deb7f4817e"
/>

They are added to Iceland Map no bots, no nations, max troops, max
speed, auto attack wilderness, win victory at 99%, and then the testing
complete modal appears with the skin they tested is present (rating
system not developed as OOS)

<img width="1165" height="703" alt="image"
src="https://github.com/user-attachments/assets/037add18-95b4-46cc-9627-3eabfb51c631"
/>

<img width="618" height="647" alt="image"
src="https://github.com/user-attachments/assets/8d1d6afe-8107-4472-a143-181eabaa67c6"
/>

Game does not save, the username of the player is the name of the skin,
the ID of the game is the name of the skin too.


## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

w.o.n

---------

Co-authored-by: Evan <evanpelle@gmail.com>
Co-authored-by: iamlewis <lewismmmm@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: VariableVince <24507472+VariableVince@users.noreply.github.com>
2026-05-26 23:31:07 +01:00

83 lines
2.1 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { TestSkinExecution } from "../../src/core/execution/TestSkinExecution";
describe("TestSkinExecution", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
vi.restoreAllMocks();
});
it("showModal calls onShowModal and prevents scheduled initial attack", () => {
const fakePlayer = {
cosmetics: { pattern: { name: "pattern1", colorPalette: { name: "p" } } },
troops: () => 100,
} as any;
const gameView = {
playerByClientID: (_: any) => fakePlayer,
} as any;
const onShowModalRequested = vi.fn();
const onAttackIntent = vi.fn();
const onShowModal = vi.fn();
const exec = new TestSkinExecution(
gameView,
"client1" as any,
() => true,
onShowModalRequested,
onAttackIntent,
onShowModal,
);
exec.start();
// Immediately show modal which should clear timeouts
exec.showModal();
// Should have requested runner to stop
expect(onShowModalRequested).toHaveBeenCalled();
// Should have called onShowModal with the right payload
expect(onShowModal).toHaveBeenCalledWith("pattern1", { name: "p" });
// Advance timers past the initial attack delay; since showModal cleared timeouts, no attack should fire
vi.advanceTimersByTime(500);
expect(onAttackIntent).not.toHaveBeenCalled();
});
it("start schedules initial attack if not cancelled", () => {
const fakePlayer = {
cosmetics: { pattern: { name: "pattern1", colorPalette: null } },
troops: () => 100,
} as any;
const gameView = {
playerByClientID: (_: any) => fakePlayer,
} as any;
const onAttackIntent = vi.fn();
const exec = new TestSkinExecution(
gameView,
"client1" as any,
() => true,
() => {},
onAttackIntent,
() => {},
);
exec.start();
// advance past initial attack delay
vi.advanceTimersByTime(200);
// initial attack should have called the onAttackIntent callback
expect(onAttackIntent).toHaveBeenCalledWith(null, 50);
});
});