-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixedWingInteraction.test.ts
More file actions
118 lines (96 loc) · 4.03 KB
/
Copy pathFixedWingInteraction.test.ts
File metadata and controls
118 lines (96 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (c) 2025-2026 Matthew Kissinger
import { describe, expect, it, vi } from 'vitest';
import * as THREE from 'three';
import { FixedWingInteraction } from './FixedWingInteraction';
vi.mock('../../utils/DeviceDetector', () => ({
shouldUseTouchControls: vi.fn(() => false),
}));
function createAircraftMap(): Map<string, THREE.Group> {
return new Map();
}
function addAircraft(map: Map<string, THREE.Group>, id: string, x: number, z: number): void {
const group = new THREE.Group();
group.position.set(x, 0, z);
map.set(id, group);
}
describe('FixedWingInteraction', () => {
it('prioritizes trainer aircraft over nearby gunship aircraft', () => {
const aircraft = createAircraftMap();
addAircraft(aircraft, 'ac47', 2, 0);
addAircraft(aircraft, 'a1', 4, 0);
const displayNames = new Map([
['ac47', 'AC-47 Spooky'],
['a1', 'A-1 Skyraider'],
]);
const configKeys = new Map([
['ac47', 'AC47_SPOOKY'],
['a1', 'A1_SKYRAIDER'],
]);
const enterFixedWing = vi.fn();
const hud = { setInteractionContext: vi.fn() };
const playerController = {
isInHelicopter: () => false,
isInFixedWing: () => false,
getPosition: () => new THREE.Vector3(0, 0, 0),
enterFixedWing,
};
const interaction = new FixedWingInteraction(aircraft, displayNames, configKeys);
interaction.setHUDSystem(hud as any);
interaction.setPlayerController(playerController as any);
interaction.checkPlayerProximity();
interaction.tryEnterAircraft();
expect(hud.setInteractionContext).toHaveBeenCalledWith(expect.objectContaining({
targetId: 'a1',
promptText: expect.stringContaining('A-1 Skyraider'),
}));
expect(enterFixedWing).toHaveBeenCalledWith('a1', expect.any(THREE.Vector3));
});
it('allows gunship aircraft to be boarded when they are the only nearby fixed-wing option', () => {
const aircraft = createAircraftMap();
addAircraft(aircraft, 'ac47', 3, 0);
const displayNames = new Map([['ac47', 'AC-47 Spooky']]);
const configKeys = new Map([['ac47', 'AC47_SPOOKY']]);
const hud = { setInteractionContext: vi.fn() };
const playerController = {
isInHelicopter: () => false,
isInFixedWing: () => false,
getPosition: () => new THREE.Vector3(0, 0, 0),
enterFixedWing: vi.fn(),
};
const interaction = new FixedWingInteraction(aircraft, displayNames, configKeys);
interaction.setHUDSystem(hud as any);
interaction.setPlayerController(playerController as any);
interaction.checkPlayerProximity();
expect(interaction.tryEnterAircraft()).toBe(true);
expect(hud.setInteractionContext).toHaveBeenCalledWith(expect.objectContaining({
targetId: 'ac47',
promptText: expect.stringContaining('AC-47 Spooky'),
}));
expect(playerController.enterFixedWing).toHaveBeenCalledWith('ac47', expect.any(THREE.Vector3));
});
it('keeps a render-culled parked aircraft enterable when the player is on foot', () => {
const aircraft = createAircraftMap();
addAircraft(aircraft, 'a1', 3, 0);
aircraft.get('a1')!.visible = false;
const displayNames = new Map([['a1', 'A-1 Skyraider']]);
const configKeys = new Map([['a1', 'A1_SKYRAIDER']]);
const hud = { setInteractionContext: vi.fn() };
const playerController = {
isInHelicopter: () => false,
isInFixedWing: () => false,
getPosition: () => new THREE.Vector3(0, 0, 0),
enterFixedWing: vi.fn(),
};
const interaction = new FixedWingInteraction(aircraft, displayNames, configKeys);
interaction.setHUDSystem(hud as any);
interaction.setPlayerController(playerController as any);
interaction.checkPlayerProximity();
expect(interaction.tryEnterAircraft()).toBe(true);
expect(hud.setInteractionContext).toHaveBeenCalledWith(expect.objectContaining({
targetId: 'a1',
promptText: expect.stringContaining('A-1 Skyraider'),
}));
expect(playerController.enterFixedWing).toHaveBeenCalledWith('a1', expect.any(THREE.Vector3));
});
});