mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
test(atlas): settle the first CI round of the new Atlas tests
Client types: Array.at is past the lib target, typed mocks where a spy is called. Client lint: mock components named so hooks may run in them, state reported from effects instead of written into props, promises voided or awaited. Client tests: class order as passed, month names checked in Japanese whatever the ICU build, mesh vertex counts asserted by shape, the buffer growth case built from many small squares instead of one strip that took 15 s, the shooting star tests driving the sky's own schedule, and reduced motion mocked once so it no longer silences later tests. Server: the hidden-setting cases as it.each (no-await-in-loop), and the presence branches the realtime 100% threshold asks for.
This commit is contained in:
@@ -17,6 +17,11 @@ interface Probe {
|
||||
}
|
||||
|
||||
/** The scrubber over real year state, so play and drag move what it shows. */
|
||||
/** Hands the harness state to the test, after the render that produced it. */
|
||||
function report(target: Probe, seen: Probe): void {
|
||||
Object.assign(target, seen);
|
||||
}
|
||||
|
||||
function Harness({
|
||||
probe,
|
||||
initialYear = null,
|
||||
@@ -30,8 +35,7 @@ function Harness({
|
||||
}): React.ReactElement {
|
||||
const [year, setYear] = React.useState<number | null>(initialYear);
|
||||
const [timelineOpen, setTimelineOpen] = React.useState(open);
|
||||
probe.year = year;
|
||||
probe.open = timelineOpen;
|
||||
React.useEffect(() => report(probe, { year, open: timelineOpen }));
|
||||
const s = viewState({
|
||||
year,
|
||||
setYear,
|
||||
|
||||
@@ -141,8 +141,8 @@ describe('AtlasGlobeTours', () => {
|
||||
expect(screen.getByText('2,300 m')).toBeInTheDocument();
|
||||
expect(screen.getByText('2,100 m')).toBeInTheDocument();
|
||||
expect(screen.getByText('tours.stats.title|tours.stats.basisInfo')).toBeInTheDocument();
|
||||
expect(fake.basis.at(-1)).toBe(byBasis);
|
||||
expect(fake.uncounted.at(-1)).toEqual({ upcoming: 4, unassigned: 1, undated: 2 });
|
||||
expect(fake.basis.slice(-1)[0]).toBe(byBasis);
|
||||
expect(fake.uncounted.slice(-1)[0]).toEqual({ upcoming: 4, unassigned: 1, undated: 2 });
|
||||
// No type bars without types, and no list button without done tours.
|
||||
expect(screen.queryByText('atlas.globe.byType')).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'tours.stats.showTours' })).not.toBeInTheDocument();
|
||||
@@ -186,10 +186,10 @@ describe('AtlasGlobeTours', () => {
|
||||
it('FE-ATLAS2-VIEWB-117: with done tours the list opens in its dialog and closes again', () => {
|
||||
fake.stats = { summary: summary(2, [{ place_id: 1 }]), data: null, type: 'all' };
|
||||
render(<AtlasGlobeTours s={viewState()} />);
|
||||
expect(fake.dialog.at(-1)?.open).toBe(false);
|
||||
expect(fake.dialog.slice(-1)[0]?.open).toBe(false);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'tours.stats.showTours' }));
|
||||
expect(fake.dialog.at(-1)?.open).toBe(true);
|
||||
expect(fake.dialog.slice(-1)[0]?.open).toBe(true);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'close-list' }));
|
||||
expect(fake.dialog.at(-1)?.open).toBe(false);
|
||||
expect(fake.dialog.slice(-1)[0]?.open).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,7 +55,7 @@ vi.mock('../../components/AtlasGlobe/AtlasGlobe', () => ({
|
||||
vi.mock('../../components/AtlasGlobe/GlobeSky', async () => {
|
||||
const { useImperativeHandle } = await import('react');
|
||||
return {
|
||||
default: ({ ref }: { ref?: import('react').Ref<{ layout: (e: unknown) => void }> }) => {
|
||||
default: function GlobeSkyStub({ ref }: { ref?: import('react').Ref<{ layout: (e: unknown) => void }> }) {
|
||||
useImperativeHandle(ref, () => ({ layout: view.skyLayout }));
|
||||
return null;
|
||||
},
|
||||
@@ -64,7 +64,7 @@ vi.mock('../../components/AtlasGlobe/GlobeSky', async () => {
|
||||
vi.mock('../../components/AtlasGlobe/GlobePins', async () => {
|
||||
const { useImperativeHandle } = await import('react');
|
||||
return {
|
||||
default: ({ ref }: { ref?: import('react').Ref<{ layout: (e: unknown) => void }> }) => {
|
||||
default: function GlobePinsStub({ ref }: { ref?: import('react').Ref<{ layout: (e: unknown) => void }> }) {
|
||||
useImperativeHandle(ref, () => ({ layout: view.pinsLayout }));
|
||||
return null;
|
||||
},
|
||||
|
||||
@@ -25,9 +25,14 @@ interface Spies {
|
||||
form: ViewBucketForm;
|
||||
year: number;
|
||||
month: number;
|
||||
select: ReturnType<typeof vi.fn>;
|
||||
add: ReturnType<typeof vi.fn>;
|
||||
reset: ReturnType<typeof vi.fn>;
|
||||
select: ReturnType<typeof vi.fn<(p: GlobePlaceHit) => void>>;
|
||||
add: ReturnType<typeof vi.fn<() => Promise<void>>>;
|
||||
reset: ReturnType<typeof vi.fn<() => void>>;
|
||||
}
|
||||
|
||||
/** Hands the form state to the test, after the render that produced it. */
|
||||
function report(target: Spies, seen: Pick<Spies, 'form' | 'year' | 'month'>): void {
|
||||
Object.assign(target, seen);
|
||||
}
|
||||
|
||||
/** The card over real form state, as useAtlasBucket holds it. */
|
||||
@@ -45,9 +50,7 @@ function Harness({
|
||||
const [form, setForm] = React.useState<ViewBucketForm>(initial);
|
||||
const [year, setYear] = React.useState(initialYear);
|
||||
const [month, setMonth] = React.useState(initialMonth);
|
||||
spies.form = form;
|
||||
spies.year = year;
|
||||
spies.month = month;
|
||||
React.useEffect(() => report(spies, { form, year, month }));
|
||||
const bucketState = {
|
||||
bucketForm: form,
|
||||
setBucketForm: setForm,
|
||||
@@ -69,7 +72,14 @@ function Harness({
|
||||
}
|
||||
|
||||
function spiesOf(): Spies {
|
||||
return { form: EMPTY, year: 0, month: 0, select: vi.fn(), add: vi.fn(async () => undefined), reset: vi.fn() };
|
||||
return {
|
||||
form: EMPTY,
|
||||
year: 0,
|
||||
month: 0,
|
||||
select: vi.fn<(p: GlobePlaceHit) => void>(),
|
||||
add: vi.fn<() => Promise<void>>(async () => undefined),
|
||||
reset: vi.fn<() => void>(),
|
||||
};
|
||||
}
|
||||
|
||||
const HIT = { name: 'Kyoto', address: 'Kyoto, Japan', lat: 35.0116, lng: 135.7681 };
|
||||
@@ -95,7 +105,7 @@ describe('AtlasGlobeWishAdd', () => {
|
||||
render(<Harness spies={spiesOf()} />);
|
||||
expect(screen.getByText('atlas.globe.newWish')).toBeInTheDocument();
|
||||
expect(searchBox()).toHaveFocus();
|
||||
expect(search.asked.at(-1)).toEqual(['', 'de']);
|
||||
expect(search.asked.slice(-1)[0]).toEqual(['', 'de']);
|
||||
expect(screen.getByRole('button', { name: 'atlas.globe.wishSave' })).toBeDisabled();
|
||||
// Nothing typed, no result list.
|
||||
expect(screen.queryByText(/atlas\.globe\.wishJustName/)).not.toBeInTheDocument();
|
||||
@@ -111,7 +121,7 @@ describe('AtlasGlobeWishAdd', () => {
|
||||
const spies = spiesOf();
|
||||
render(<Harness spies={spies} />);
|
||||
fireEvent.change(searchBox(), { target: { value: ' Hokkaido ' } });
|
||||
expect(search.asked.at(-1)).toEqual([' Hokkaido ', 'de']);
|
||||
expect(search.asked.slice(-1)[0]).toEqual([' Hokkaido ', 'de']);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'atlas.globe.wishJustName[name=Hokkaido]' }));
|
||||
expect(spies.form).toMatchObject({ name: 'Hokkaido', lat: '', lng: '' });
|
||||
// Picked: the name is editable and there is no place under it.
|
||||
|
||||
@@ -185,7 +185,8 @@ describe('useWishAddForm', () => {
|
||||
});
|
||||
|
||||
it('FE-ATLAS2-HOOK-210: the month names follow the reader language', () => {
|
||||
const { state } = formState(EMPTY, 'de');
|
||||
// Japanese, whose month names share nothing with the English ones whatever the ICU build.
|
||||
const { state } = formState(EMPTY, 'ja');
|
||||
const { result } = renderHook(() => useWishAddForm(state));
|
||||
expect(result.current.months[0]).not.toBe('Jan');
|
||||
expect(new Set(result.current.months).size).toBe(12);
|
||||
|
||||
Reference in New Issue
Block a user