mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
f57a0dbd31
Two review findings of MDT-02 in the planner's list and the day plan: - A stage asked for while the draft has unsaved changes stayed pending when the changes were kept or the tour failed to open, so opening that tour later from its row jumped to a stage nobody asked for then. The rail now has cancel(), which the discard question calls when it is dismissed and the open calls when it fails, and it lets a stage go once the opened tour's points are in and none of its stages starts at that stop. - Every day holding a stage of a tour read the whole tour on its own, so a five stage tour sent five identical requests on top of the list's own. tourPointsRepo shares one read per trip, tour and revision among the views showing it at the same time, through the tour repo as before, and drops it once the last view lets go or the read fails.
67 lines
2.7 KiB
TypeScript
67 lines
2.7 KiB
TypeScript
// FE-TOUR-POINTSREPO-001 to FE-TOUR-POINTSREPO-004: one read of a tour's saved points, shared by every
|
|
// view showing it at the same time (MDT-02).
|
|
import type { TourListItem, TourWaypoint } from '@trek/shared';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { tourPointsRepo } from './tourPointsRepo';
|
|
import { tourRepo } from './tourRepo';
|
|
|
|
const TOUR = { place_id: 81, name: 'Hut to hut', tour_type: 'hike' } as TourListItem;
|
|
const POINTS: TourWaypoint[] = [
|
|
{ lat: 47, lng: 11, role: 'start', sequence: 0, key: 'stop-start' },
|
|
{ lat: 47.03, lng: 11, role: 'end', sequence: 1, key: 'stop-end' },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
vi.restoreAllMocks();
|
|
vi.spyOn(tourRepo, 'detail').mockResolvedValue({ tour: TOUR, waypoints: POINTS });
|
|
});
|
|
|
|
describe('tourPointsRepo', () => {
|
|
it('FE-TOUR-POINTSREPO-001: views showing the same tour at once share one read', async () => {
|
|
const first = tourPointsRepo.hold(9, 81, '81:2');
|
|
const second = tourPointsRepo.hold(9, 81, '81:2');
|
|
expect(await first.points).toEqual(POINTS);
|
|
expect(await second.points).toEqual(POINTS);
|
|
expect(tourRepo.detail).toHaveBeenCalledTimes(1);
|
|
expect(tourRepo.detail).toHaveBeenCalledWith(9, 81, expect.any(AbortSignal));
|
|
first.release();
|
|
second.release();
|
|
});
|
|
|
|
it('FE-TOUR-POINTSREPO-002: a new revision is a read of its own', async () => {
|
|
const before = tourPointsRepo.hold(9, 81, '81:2');
|
|
const after = tourPointsRepo.hold(9, 81, '81:3');
|
|
await Promise.all([before.points, after.points]);
|
|
expect(tourRepo.detail).toHaveBeenCalledTimes(2);
|
|
before.release();
|
|
after.release();
|
|
});
|
|
|
|
it('FE-TOUR-POINTSREPO-003: the read is aborted once nobody holds it, and the next view reads again', async () => {
|
|
const first = tourPointsRepo.hold(9, 81, '81:2');
|
|
const second = tourPointsRepo.hold(9, 81, '81:2');
|
|
const signal = vi.mocked(tourRepo.detail).mock.calls[0]?.[2];
|
|
first.release();
|
|
// Letting go twice does not let go of the other view's hold.
|
|
first.release();
|
|
expect(signal?.aborted).toBe(false);
|
|
second.release();
|
|
expect(signal?.aborted).toBe(true);
|
|
const next = tourPointsRepo.hold(9, 81, '81:2');
|
|
await next.points;
|
|
expect(tourRepo.detail).toHaveBeenCalledTimes(2);
|
|
next.release();
|
|
});
|
|
|
|
it('FE-TOUR-POINTSREPO-004: a failed read is dropped at once, so the next view reads again', async () => {
|
|
vi.mocked(tourRepo.detail).mockRejectedValueOnce(new Error('offline'));
|
|
const failed = tourPointsRepo.hold(9, 81, '81:2');
|
|
await expect(failed.points).rejects.toThrow('offline');
|
|
const retry = tourPointsRepo.hold(9, 81, '81:2');
|
|
expect(await retry.points).toEqual(POINTS);
|
|
expect(tourRepo.detail).toHaveBeenCalledTimes(2);
|
|
failed.release();
|
|
retry.release();
|
|
});
|
|
});
|