diff --git a/src/app/features/hud/hud-dock.component.spec.ts b/src/app/features/hud/hud-dock.component.spec.ts index 7b3f361..cd29fda 100644 --- a/src/app/features/hud/hud-dock.component.spec.ts +++ b/src/app/features/hud/hud-dock.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { Router } from '@angular/router'; -import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { DataLoaderService } from '../../core/data/data-loader.service'; import { BookmarksStore } from '../../shared/state/bookmarks.store'; @@ -378,6 +378,8 @@ describe('HudDockComponent', () => { fixture.detectChanges(); }); + afterEach(() => vi.unstubAllEnvs()); + function button(name: string): HTMLButtonElement { return [...host().querySelectorAll('#dock-panel-display button')].find((b) => b.textContent?.trim() === name)!; } @@ -417,6 +419,9 @@ describe('HudDockComponent', () => { }); it('jumps the clock to the date submitted, read as UTC', () => { + // Five and a half hours from UTC, so a field read as local time lands elsewhere: in UTC itself, + // where CI runs, the two readings are the same instant and this could not tell them apart. + vi.stubEnv('TZ', 'Asia/Kolkata'); const field = host().querySelector('#clock-date')!; field.value = '2020-12-21T18:00'; button('Go').click(); @@ -431,5 +436,15 @@ describe('HudDockComponent', () => { expect(time.atNow()).toBe(true); expect(host().querySelector('#clock-date')!.value).toBe(time.date().toISOString().slice(0, 16)); }); + + it('fills the date field again with the clock’s date when the panel is opened again', () => { + time.setDate(new Date('2020-12-21T18:00Z')); + fixture.componentInstance.toggleTab('display'); + fixture.detectChanges(); + fixture.componentInstance.toggleTab('display'); + fixture.detectChanges(); + + expect(host().querySelector('#clock-date')!.value).toBe('2020-12-21T18:00'); + }); }); }); diff --git a/src/app/shared/state/time.store.spec.ts b/src/app/shared/state/time.store.spec.ts index 9895c92..88bb121 100644 --- a/src/app/shared/state/time.store.spec.ts +++ b/src/app/shared/state/time.store.spec.ts @@ -48,6 +48,14 @@ describe('TimeStore', () => { expect(time.julianDate() - afterTwoDays).toBeLessThan(1 / 24); }); + it('runs the date backwards at a negative rate', () => { + time.setRate(-86_400); + const before = time.julianDate(); + vi.advanceTimersByTime(1000); + + expect(time.julianDate() - before).toBeCloseTo(-1, 9); + }); + it('knows the map is away from now even once it is back at real time', () => { expect(time.atNow()).toBe(true); time.setRate(2_629_800);