This commit is contained in:
Scott Anderson
2025-08-24 21:32:32 -04:00
parent eaefecb00f
commit 809d60ff58
95 changed files with 1385 additions and 1424 deletions
@@ -14,8 +14,8 @@ import { TileRef } from "../../../src/core/game/GameMap";
import { GameView, PlayerView } from "../../../src/core/game/GameView";
jest.mock("../../../src/client/Utils", () => ({
translateText: jest.fn((key: string) => key),
renderNumber: jest.fn((num: number) => num.toString()),
translateText: jest.fn((key: string) => key),
}));
jest.mock("../../../src/client/graphics/layers/BuildMenu", () => {
@@ -23,46 +23,46 @@ jest.mock("../../../src/client/graphics/layers/BuildMenu", () => {
return {
flattenedBuildTable: [
{
unitType: UnitType.City,
key: "unit_type.city",
countable: true,
description: "unit_type.city_desc",
icon: "city-icon",
countable: true,
key: "unit_type.city",
unitType: UnitType.City,
},
{
unitType: UnitType.Factory,
key: "unit_type.factory",
countable: true,
description: "unit_type.factory_desc",
icon: "factory-icon",
countable: true,
key: "unit_type.factory",
unitType: UnitType.Factory,
},
{
unitType: UnitType.AtomBomb,
key: "unit_type.atom_bomb",
countable: false,
description: "unit_type.atom_bomb_desc",
icon: "atom-bomb-icon",
countable: false,
key: "unit_type.atom_bomb",
unitType: UnitType.AtomBomb,
},
{
unitType: UnitType.Warship,
key: "unit_type.warship",
countable: true,
description: "unit_type.warship_desc",
icon: "warship-icon",
countable: true,
key: "unit_type.warship",
unitType: UnitType.Warship,
},
{
unitType: UnitType.HydrogenBomb,
key: "unit_type.hydrogen_bomb",
countable: false,
description: "unit_type.hydrogen_bomb_desc",
icon: "hydrogen-bomb-icon",
countable: false,
key: "unit_type.hydrogen_bomb",
unitType: UnitType.HydrogenBomb,
},
{
unitType: UnitType.MIRV,
key: "unit_type.mirv",
countable: false,
description: "unit_type.mirv_desc",
icon: "mirv-icon",
countable: false,
key: "unit_type.mirv",
unitType: UnitType.MIRV,
},
],
};
@@ -95,17 +95,17 @@ describe("RadialMenuElements", () => {
} as unknown as PlayerView;
mockGame = {
inSpawnPhase: jest.fn(() => false),
owner: jest.fn(() => mockPlayer),
isLand: jest.fn(() => true),
config: jest.fn(() => ({
isUnitDisabled: jest.fn(() => false),
theme: () => ({
territoryColor: () => ({
lighten: () => ({ alpha: () => ({ toRgbString: () => "#fff" }) }),
}),
}),
isUnitDisabled: jest.fn(() => false),
})),
inSpawnPhase: jest.fn(() => false),
isLand: jest.fn(() => true),
owner: jest.fn(() => mockPlayer),
} as unknown as GameView;
mockBuildMenu = {
@@ -117,38 +117,38 @@ describe("RadialMenuElements", () => {
mockPlayerActions = {
buildableUnits: [
{ type: UnitType.City, canBuild: true },
{ type: UnitType.Factory, canBuild: true },
{ type: UnitType.AtomBomb, canBuild: true },
{ type: UnitType.Warship, canBuild: true },
{ type: UnitType.HydrogenBomb, canBuild: true },
{ type: UnitType.MIRV, canBuild: true },
{ type: UnitType.TransportShip, canBuild: true },
{ canBuild: true, type: UnitType.City },
{ canBuild: true, type: UnitType.Factory },
{ canBuild: true, type: UnitType.AtomBomb },
{ canBuild: true, type: UnitType.Warship },
{ canBuild: true, type: UnitType.HydrogenBomb },
{ canBuild: true, type: UnitType.MIRV },
{ canBuild: true, type: UnitType.TransportShip },
],
canAttack: true,
interaction: {
canSendAllianceRequest: true,
canBreakAlliance: false,
canDonateTroops: true,
canDonateGold: true,
canDonateTroops: true,
canSendAllianceRequest: true,
},
};
mockTile = {} as TileRef;
mockParams = {
buildMenu: mockBuildMenu,
chatIntegration: {} as any,
closeMenu: jest.fn(),
emojiTable: {} as any,
eventBus: {} as any,
game: mockGame,
myPlayer: mockPlayer,
playerActionHandler: {} as any,
playerActions: mockPlayerActions,
playerPanel: {} as any,
selected: mockPlayer,
tile: mockTile,
playerActions: mockPlayerActions,
game: mockGame,
buildMenu: mockBuildMenu,
emojiTable: {} as any,
playerActionHandler: {} as any,
playerPanel: {} as any,
chatIntegration: {} as any,
eventBus: {} as any,
closeMenu: jest.fn(),
};
});
+25 -25
View File
@@ -11,8 +11,6 @@ describe("UILayer", () => {
beforeEach(() => {
game = {
width: () => 100,
height: () => 100,
config: () => ({
theme: () => ({
territoryColor: () => ({
@@ -20,12 +18,14 @@ describe("UILayer", () => {
}),
}),
}),
x: () => 10,
y: () => 10,
unitInfo: () => ({ maxHealth: 10, constructionDuration: 5 }),
height: () => 100,
myPlayer: () => ({ id: () => 1 }),
ticks: () => 1,
unitInfo: () => ({ constructionDuration: 5, maxHealth: 10 }),
updatesSinceLastTick: () => undefined,
width: () => 100,
x: () => 10,
y: () => 10,
};
eventBus = { on: jest.fn() };
});
@@ -46,10 +46,10 @@ describe("UILayer", () => {
const ui = new UILayer(game, eventBus);
ui.redraw();
const unit = {
type: () => "Warship",
isActive: () => true,
tile: () => ({}),
owner: () => ({}),
tile: () => ({}),
type: () => "Warship",
};
const event = { isSelected: true, unit };
ui.drawSelectionBox = jest.fn();
@@ -61,13 +61,13 @@ describe("UILayer", () => {
const ui = new UILayer(game, eventBus);
ui.redraw();
const unit = {
id: () => 1,
type: () => "Warship",
health: () => 5,
tile: () => ({}),
owner: () => ({}),
isActive: () => true,
createdAt: () => 1,
health: () => 5,
id: () => 1,
isActive: () => true,
owner: () => ({}),
tile: () => ({}),
type: () => "Warship",
} as unknown as UnitView;
ui.drawHealthBar(unit);
expect(ui["allHealthBars"].has(1)).toBe(true);
@@ -90,12 +90,12 @@ describe("UILayer", () => {
const ui = new UILayer(game, eventBus);
ui.redraw();
const unit = {
id: () => 1,
type: () => "Warship",
health: () => 5,
tile: () => ({}),
owner: () => ({}),
id: () => 1,
isActive: () => true,
owner: () => ({}),
tile: () => ({}),
type: () => "Warship",
} as unknown as UnitView;
ui.drawHealthBar(unit);
expect(ui["allHealthBars"].has(1)).toBe(true);
@@ -111,8 +111,8 @@ describe("UILayer", () => {
ui.redraw();
const unit = {
id: () => 2,
tile: () => ({}),
isActive: () => true,
tile: () => ({}),
} as unknown as UnitView;
ui.createLoadingBar(unit);
expect(ui["allProgressBars"].has(2)).toBe(true);
@@ -122,12 +122,12 @@ describe("UILayer", () => {
const ui = new UILayer(game, eventBus);
ui.redraw();
const unit = {
id: () => 2,
type: () => "Construction",
constructionType: () => "City",
id: () => 2,
isActive: () => true,
owner: () => ({ id: () => 1 }),
tile: () => ({}),
isActive: () => true,
type: () => "Construction",
} as unknown as UnitView;
ui.onUnitEvent(unit);
expect(ui["allProgressBars"].has(2)).toBe(true);
@@ -142,13 +142,13 @@ describe("UILayer", () => {
const ui = new UILayer(game, eventBus);
ui.redraw();
const unit = {
id: () => 2,
type: () => "Construction",
constructionType: () => "City",
createdAt: () => 1,
id: () => 2,
isActive: () => true,
owner: () => ({ id: () => 1 }),
tile: () => ({}),
isActive: () => true,
createdAt: () => 1,
type: () => "Construction",
} as unknown as UnitView;
ui.onUnitEvent(unit);
expect(ui["allProgressBars"].has(2)).toBe(true);