Files
OpenFrontIO/tests/radialMenuElements.test.ts
FloPinguin 0286224299 Move betrayal button, remove betrayal confirmation 🔧 (#3076)
## Description:

- Move betrayal button to the boat-sending-button-location (you can't
send boats to allies) to prevent missclicks
- Remove betrayal confirmation

<img width="260" height="248" alt="image"
src="https://github.com/user-attachments/assets/0a25fc9c-c8a0-4ba9-a8c8-971d6a7a0511"
/>

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

FloPinguin
2026-01-31 13:52:58 -08:00

102 lines
2.8 KiB
TypeScript

import { vi } from "vitest";
// Mock BuildMenu to avoid importing lit and other ESM-heavy deps in this unit test
vi.mock("../src/client/graphics/layers/BuildMenu", () => ({
BuildMenu: class {},
flattenedBuildTable: [],
}));
// Mock Utils to avoid touching DOM (document) during tests
vi.mock("../src/client/Utils", () => ({
translateText: (k: string) => k,
getSvgAspectRatio: async () => 1,
}));
import {
COLORS,
rootMenuElement,
type MenuElementParams,
} from "../src/client/graphics/layers/RadialMenuElements";
// Minimal stubs to satisfy types used in rootMenuElement.subMenu and allyBreak actions
const makePlayer = (id: string) =>
({
id: () => id,
isAlliedWith: (other: any) =>
other && typeof other.id === "function" && other.id() !== id
? true
: true,
}) as unknown as import("../src/core/game/GameView").PlayerView;
const makeParams = (opts?: Partial<MenuElementParams>): MenuElementParams => {
const myPlayer = (opts?.myPlayer as any) ?? makePlayer("p1");
const selected = (opts?.selected as any) ?? makePlayer("p2");
return {
myPlayer,
selected,
tile: {} as any,
playerActions: {
canAttack: true,
interaction: {
canBreakAlliance: true,
canSendAllianceRequest: false,
canEmbargo: false,
},
} as any,
game: {
inSpawnPhase: () => false,
owner: () => ({ isPlayer: () => false }),
} as any,
buildMenu: {
canBuildOrUpgrade: () => false,
cost: () => 0,
count: () => 0,
sendBuildOrUpgrade: () => {},
} as any,
emojiTable: {} as any,
playerActionHandler: {
handleBreakAlliance: vi.fn(),
handleEmbargo: vi.fn(),
handleDonateGold: vi.fn(),
handleDonateTroops: vi.fn(),
handleTargetPlayer: vi.fn(),
} as any,
playerPanel: {
show: vi.fn(),
} as any,
chatIntegration: {
createQuickChatMenu: vi.fn(() => []),
} as any,
eventBus: {} as any,
closeMenu: vi.fn(),
};
};
const findAllyBreak = (items: any[]) =>
items.find((i) => i && i.id === "ally_break");
describe("RadialMenuElements ally break", () => {
test("shows break option with correct color when allied", () => {
const params = makeParams();
const items = rootMenuElement.subMenu!(params);
const ally = findAllyBreak(items)!;
expect(ally).toBeTruthy();
expect(ally.name).toBe("break");
expect(ally.color).toBe(COLORS.breakAlly);
});
test("break action calls handleBreakAlliance and closes menu", () => {
const params = makeParams();
const items = rootMenuElement.subMenu!(params);
const ally = findAllyBreak(items)!;
ally.action!(params);
expect(params.playerActionHandler.handleBreakAlliance).toHaveBeenCalledWith(
params.myPlayer,
params.selected,
);
expect(params.closeMenu).toHaveBeenCalled();
});
});