|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import type { Session, Telemetry } from '@irdashies/types'; |
| 3 | +import { SessionBarProcessor } from './SessionBarProcessor'; |
| 4 | + |
| 5 | +describe('SessionBarProcessor', () => { |
| 6 | + it('returns snapshots detached from reusable processor buffers', () => { |
| 7 | + const processor = new SessionBarProcessor(); |
| 8 | + processor.init({ |
| 9 | + DriverInfo: { |
| 10 | + DriverCarIdx: 0, |
| 11 | + Drivers: [{ CarIdx: 0, CarID: 67, CarClassID: 1 }], |
| 12 | + }, |
| 13 | + } as unknown as Session); |
| 14 | + processor.onFrame({ |
| 15 | + SessionTime: { value: [1] }, |
| 16 | + SessionNum: { value: [1] }, |
| 17 | + CarIdxPosition: { value: [1] }, |
| 18 | + } as unknown as Telemetry); |
| 19 | + const published = processor.snapshot(); |
| 20 | + processor.onFrame({ |
| 21 | + SessionTime: { value: [1.2] }, |
| 22 | + SessionNum: { value: [1] }, |
| 23 | + CarIdxPosition: { value: [2] }, |
| 24 | + } as unknown as Telemetry); |
| 25 | + expect(published.competitorPositions).toEqual([1]); |
| 26 | + expect(processor.snapshot().competitorPositions).toEqual([2]); |
| 27 | + }); |
| 28 | + |
| 29 | + it('projects the auxiliary session bar state and resets with lifecycle', () => { |
| 30 | + const processor = new SessionBarProcessor(); |
| 31 | + processor.init({ |
| 32 | + WeekendInfo: { |
| 33 | + TrackDisplayName: 'Okayama', |
| 34 | + WeekendOptions: { IncidentLimit: 17 }, |
| 35 | + }, |
| 36 | + DriverInfo: { |
| 37 | + DriverCarIdx: 0, |
| 38 | + Drivers: [{ CarIdx: 0, CarID: 67, CarClassID: 1 }], |
| 39 | + }, |
| 40 | + SessionInfo: { |
| 41 | + Sessions: [{ SessionNum: 1, SessionName: 'Race', SessionType: 'Race' }], |
| 42 | + }, |
| 43 | + } as unknown as Session); |
| 44 | + processor.onFrame({ |
| 45 | + SessionTime: { value: [1] }, |
| 46 | + SessionNum: { value: [1] }, |
| 47 | + DisplayUnits: { value: [1] }, |
| 48 | + FuelLevel: { value: [30] }, |
| 49 | + PlayerCarTeamIncidentCount: { value: [2] }, |
| 50 | + CarIdxPosition: { value: [1] }, |
| 51 | + CarIdxClassPosition: { value: [1] }, |
| 52 | + CarIdxBestLapTime: { value: [90] }, |
| 53 | + Lap: { value: [2] }, |
| 54 | + Speed: { value: [50] }, |
| 55 | + } as unknown as Telemetry); |
| 56 | + expect(processor.snapshot()).toMatchObject({ |
| 57 | + sessionName: 'Race', |
| 58 | + trackDisplayName: 'Okayama', |
| 59 | + fuelLevel: 30, |
| 60 | + incidents: 2, |
| 61 | + playerClassPosition: 1, |
| 62 | + playerClassSize: 1, |
| 63 | + sessionBestLap: 90, |
| 64 | + }); |
| 65 | + processor.onFrame({ |
| 66 | + SessionTime: { value: [1.05] }, |
| 67 | + SessionNum: { value: [1] }, |
| 68 | + Lap: { value: [2] }, |
| 69 | + Speed: { value: [70] }, |
| 70 | + } as unknown as Telemetry); |
| 71 | + processor.onFrame({ |
| 72 | + SessionTime: { value: [1.2] }, |
| 73 | + SessionNum: { value: [1] }, |
| 74 | + Lap: { value: [3] }, |
| 75 | + Speed: { value: [40] }, |
| 76 | + } as unknown as Telemetry); |
| 77 | + expect(processor.snapshot()).toMatchObject({ |
| 78 | + lastLapTopSpeed: 70, |
| 79 | + sessionBestTopSpeed: 70, |
| 80 | + }); |
| 81 | + processor.onLifecycle({ type: 'disconnect' }); |
| 82 | + expect(processor.snapshot()).toMatchObject({ |
| 83 | + sessionNum: null, |
| 84 | + incidents: 0, |
| 85 | + }); |
| 86 | + }); |
| 87 | +}); |
0 commit comments