Files
OpenFrontIO/tests/client/graphics/layers/EventDisplayAlliance.test.ts
Wraith 26f5d40819 build: migrate build system to Vite and test runner to Vitest & Remove depracated husky usage (#2703)
- Replace Webpack with Vite for faster client bundling and HMR.
- Migrate tests from Jest to Vitest and update configuration.
- Update Web Worker instantiation to standard ESM syntax.
- Implement Env utility in `src/core` for safe, hybrid environment
variable access (Vite vs Node).
- Refactor configuration loaders to remove direct `process.env`
dependencies in shared code.
- Update TypeScript environment definitions and project scripts for the
new toolchain.
- Remove the [depracated usage of the
husky](https://github.com/typicode/husky/releases/tag/v9.0.1).

## Description:

migrate build system to Vite and test runner to Vitest & Remove
depracated husky usage

## 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
- [ ] 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:

wraith4081

---------

Co-authored-by: evanpelle <evanpelle@gmail.com>
2025-12-28 22:10:26 -08:00

144 lines
3.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
vi.mock("lit", () => ({
html: () => {},
LitElement: class {},
}));
vi.mock("lit/decorators.js", () => ({
customElement: () => (clazz: any) => clazz,
query: () => () => {},
state: () => () => {},
property: () => () => {},
}));
vi.mock("lit/directive.js", () => ({
DirectiveResult: class {},
}));
vi.mock("lit/directives/unsafe-html.js", () => ({
unsafeHTML: () => {},
UnsafeHTMLDirective: class {},
}));
import { EventsDisplay } from "../../../../src/client/graphics/layers/EventsDisplay";
import { MessageType } from "../../../../src/core/game/Game";
describe("EventsDisplay - alliance renewal cleanup (allianceID based)", () => {
function makeRenewal(
allianceID: number,
focusID: number,
description = "Alliance about to expire",
) {
return {
description,
type: MessageType.RENEW_ALLIANCE,
allianceID,
focusID,
createdAt: 0,
};
}
test("removes ONLY renewal events for the broken alliance", () => {
const display = new EventsDisplay();
const allianceAB = 1;
const allianceAC = 2;
const allianceBC = 3;
(display as any).events = [
makeRenewal(allianceAB, 1), // AB
makeRenewal(allianceAC, 1), // AC
makeRenewal(allianceBC, 2), // BC
];
// Break alliance AB
(display as any).removeAllianceRenewalEvents(allianceAB);
const remaining = (display as any).events;
// AB renewal removed
expect(remaining.some((e: any) => e.allianceID === allianceAB)).toBe(false);
// Other alliances untouched
expect(remaining.some((e: any) => e.allianceID === allianceAC)).toBe(true);
expect(remaining.some((e: any) => e.allianceID === allianceBC)).toBe(true);
});
test("does NOT remove renewals just because the same player is involved", () => {
const display = new EventsDisplay();
const allianceAB = 10;
const allianceAC = 11;
(display as any).events = [
makeRenewal(allianceAB, 1), // Player 1 involved
makeRenewal(allianceAC, 1), // Same player, different alliance
];
(display as any).removeAllianceRenewalEvents(allianceAB);
const remaining = (display as any).events;
expect(remaining.length).toBe(1);
expect(remaining[0].allianceID).toBe(allianceAC);
});
test("breaking one alliance does not affect renewals between other players", () => {
const display = new EventsDisplay();
const allianceAB = 100;
const allianceCD = 200;
(display as any).events = [
makeRenewal(allianceAB, 1), // AB
makeRenewal(allianceCD, 3), // CD
];
(display as any).removeAllianceRenewalEvents(allianceAB);
const remaining = (display as any).events;
expect(remaining.length).toBe(1);
expect(remaining[0].allianceID).toBe(allianceCD);
});
test("does not affect non-RENEW_ALLIANCE events", () => {
const display = new EventsDisplay();
(display as any).events = [
{
description: "Alliance broken",
type: MessageType.ALLIANCE_BROKEN,
createdAt: 0,
},
{
description: "Alliance accepted",
type: MessageType.ALLIANCE_ACCEPTED,
createdAt: 0,
},
{
description: "Renewal",
type: MessageType.RENEW_ALLIANCE,
allianceID: 999,
createdAt: 0,
},
];
(display as any).removeAllianceRenewalEvents(999);
const remaining = (display as any).events;
expect(
remaining.some((e: any) => e.type === MessageType.ALLIANCE_BROKEN),
).toBe(true);
expect(
remaining.some((e: any) => e.type === MessageType.ALLIANCE_ACCEPTED),
).toBe(true);
expect(
remaining.some((e: any) => e.type === MessageType.RENEW_ALLIANCE),
).toBe(false);
});
});