FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
nameUtils.test.ts
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2026-present FERS Contributors (see AUTHORS.md).
3
4import { beforeEach, describe, expect, test } from 'bun:test';
5import { defaultGlobalParameters } from './defaults';
6import { useScenarioStore } from './index';
7import {
8 resetSyncQueueForTests,
9 setSyncQueueInvokerForTests,
10 waitForSyncIdle,
11} from './syncQueue';
12
13type InvokeFn = typeof import('@tauri-apps/api/core').invoke;
14
15describe('scenario object names', () => {
16 beforeEach(() => {
17 resetSyncQueueForTests();
18 setSyncQueueInvokerForTests((async () => []) as InvokeFn);
19 useScenarioStore.setState({
20 globalParameters: defaultGlobalParameters,
21 waveforms: [],
22 timings: [],
23 antennas: [],
24 platforms: [],
25 selectedItemId: null,
26 selectedComponentId: null,
27 isDirty: false,
28 currentTime: defaultGlobalParameters.start,
29 });
30 });
31
32 test('component creation auto-renames duplicate default names', async () => {
33 const store = useScenarioStore.getState();
34 store.addPlatform();
35 const platform = useScenarioStore.getState().platforms[0];
36
37 useScenarioStore
38 .getState()
39 .addPlatformComponent(platform.id, 'monostatic');
40 useScenarioStore
41 .getState()
42 .addPlatformComponent(platform.id, 'monostatic');
43
44 expect(
45 useScenarioStore
46 .getState()
47 .platforms[0].components.map((component) => component.name)
48 ).toEqual(['Platform 1 Monostatic', 'Platform 1 Monostatic Copy']);
49
50 await waitForSyncIdle();
51 });
52
53 test('manual duplicate component rename gets a copy suffix', async () => {
54 useScenarioStore.setState({
55 waveforms: [
56 {
57 id: '1688849860263937',
58 type: 'Waveform',
59 name: 'Shared Name',
60 waveformType: 'cw',
61 power: 1,
62 carrier_frequency: 1e9,
63 },
64 ],
65 platforms: [
66 {
67 id: '281474976710657',
68 type: 'Platform',
69 name: 'Platform 1',
70 motionPath: {
71 interpolation: 'static',
72 waypoints: [
73 {
74 id: '281474976710658',
75 x: 0,
76 y: 0,
77 altitude: 0,
78 time: 0,
79 },
80 ],
81 },
82 rotation: {
83 type: 'fixed',
84 startAzimuth: 0,
85 startElevation: 0,
86 azimuthRate: 0,
87 elevationRate: 0,
88 },
89 components: [
90 {
91 id: '562949953421313',
92 type: 'transmitter',
93 name: 'Original Tx',
94 radarType: 'cw',
95 prf: null,
96 antennaId: null,
97 waveformId: null,
98 timingId: null,
99 schedule: [],
100 },
101 ],
102 },
103 ],
104 });
105
106 useScenarioStore
107 .getState()
108 .updateItem('281474976710657', 'components.0.name', 'Shared Name');
109
110 expect(
111 useScenarioStore.getState().platforms[0].components[0].name
112 ).toBe('Shared Name Copy');
113
114 await waitForSyncIdle();
115 });
116
117 test('default asset names avoid cross-kind conflicts', async () => {
118 useScenarioStore.setState({
119 platforms: [
120 {
121 id: '281474976710657',
122 type: 'Platform',
123 name: 'Platform 1',
124 motionPath: {
125 interpolation: 'static',
126 waypoints: [
127 {
128 id: '281474976710658',
129 x: 0,
130 y: 0,
131 altitude: 0,
132 time: 0,
133 },
134 ],
135 },
136 rotation: {
137 type: 'fixed',
138 startAzimuth: 0,
139 startElevation: 0,
140 azimuthRate: 0,
141 elevationRate: 0,
142 },
143 components: [
144 {
145 id: '1125899906842625',
146 type: 'target',
147 name: 'Waveform 1',
148 rcs_type: 'isotropic',
149 rcs_value: 1,
150 rcs_model: 'constant',
151 },
152 ],
153 },
154 ],
155 });
156
157 useScenarioStore.getState().addWaveform();
158
159 expect(useScenarioStore.getState().waveforms[0].name).toBe(
160 'Waveform 1 Copy'
161 );
162
163 await waitForSyncIdle();
164 });
165});