smoketests

This commit is contained in:
itsrubberduck
2026-02-17 18:26:20 +01:00
parent f88fced5b1
commit ff4a1c3ee5
6 changed files with 282 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
normalizeMetarPhrase,
normalizeRadioPhrase,
spellIcaoDigits,
spellIcaoLetters,
toIcaoPhonetic,
} from '~~/shared/utils/radioSpeech'
describe('radioSpeech', () => {
it('spells ICAO digits and letters', () => {
assert.equal(spellIcaoDigits('120'), 'wun too zero')
assert.equal(spellIcaoLetters('eddf'), 'Echo Delta Delta Foxtrot')
assert.equal(toIcaoPhonetic('A3'), 'Alfa tree')
})
it('normalizes a combined phrase with callsign, runway, frequency and taxi route', () => {
const normalized = normalizeRadioPhrase('DLH359 contact 121.800, RWY 25R via N3 U4', {
expandCallsigns: true,
airlineMap: { DLH: 'Lufthansa' },
})
assert.match(normalized, /Lufthansa tree fife niner/)
assert.match(normalized, /wun too wun decimal eight zero zero/)
assert.match(normalized, /runway too fife right/)
assert.match(normalized, /November tree Uniform four/)
})
it('normalizes SID suffix and METAR data', () => {
const sid = normalizeRadioPhrase('MARUN 7F')
const metar = normalizeMetarPhrase('EDDF 171450Z 28015G25KT 9999 -RA SCT025 BKN040 15/08 Q1013')
assert.equal(sid, 'MARUN seven Foxtrot')
assert.match(metar, /wind too eight zero degrees/)
assert.match(metar, /gusting too fife knots/)
assert.match(metar, /QNH wun zero wun tree/)
})
})

View File

@@ -0,0 +1,68 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
altitudeToWords,
createBaseScenario,
createScenarioSeries,
minutesToWords,
runwayToWords,
} from '~~/shared/learn/scenario'
describe('scenario helpers', () => {
it('formats runway, minutes and altitude values', () => {
assert.equal(runwayToWords('25R'), 'two fife right')
assert.equal(minutesToWords(0), 'one minute')
assert.equal(minutesToWords(4.4), 'four minutes')
assert.equal(altitudeToWords(4500), 'four thousand fife zero zero')
})
it('creates a base scenario with critical data fields', () => {
const scenario = createBaseScenario()
assert.match(scenario.callsign, /^[A-Z]{3}\d{3,4}$/)
assert.equal(scenario.metar.startsWith(`${scenario.airport.icao} `), true)
assert.equal(scenario.frequencies.length > 0, true)
assert.equal(typeof scenario.handoff.frequencyWords, 'string')
assert.equal(scenario.handoff.frequencyWords.length > 0, true)
})
})
describe('createScenarioSeries', () => {
it('returns cloned cached data and isolates mutations', () => {
let sourceCalls = 0
const series = createScenarioSeries(() => {
sourceCalls += 1
return {
callsign: `SRC${sourceCalls}`,
nested: { value: 1 },
} as any
})
const first = series()
const second = series()
assert.equal(sourceCalls, 1)
assert.notStrictEqual(first, second)
assert.deepEqual(first, second)
first.nested.value = 99
const third = series()
assert.equal(third.nested.value, 1)
})
it('supports override scenarios and reset', () => {
const series = createScenarioSeries(() => ({ callsign: 'SRC1', nested: { value: 1 } } as any))
series.setScenario({ callsign: 'OVR1', nested: { value: 2 } } as any)
const fromOverride = series()
assert.equal(fromOverride.callsign, 'OVR1')
fromOverride.nested.value = 999
assert.equal(series().nested.value, 2)
series.setScenario(null)
series.reset()
assert.equal(series().callsign, 'SRC1')
})
})