mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
2e1dca9fe9
Settings, Integrations, wanderer gains an optional background check of the trails you imported, off until you switch it on. While on, TREK reads the short record of each such trail at most once a day (never its GPX file) and leaves a hint when the trail may have moved on: "may have changed" when only wanderer's change time moved, "changed" when its name or description proves it, and "not checkable" when the trail is gone, no longer yours or carries no change time. Nothing is ever said to be unchanged. A new hint arrives as a notification that opens the tour (a new ?place= link in the planner); the tour's provenance shows it with the source check right beside it, and the card lists all open hints in a dialog, each leading to its tour. The check reads the source in full as before and spends the hint; taking a change in stays the confirmed reimport. No tour is ever changed or deleted. The check only asks through your own connection, only about trails your account imported into trips you can still open, and stops when you switch it off, remove the connection, wanderer refuses the token (until a test passes or a new token is saved) or the admin switches wanderer off; hints and snapshots stay. A run asks at most 25 connections for at most 10 records each, one after another, and an instance that fails (an outage, a rate limit) is left alone for an hour, doubling up to two days. Server: migration 046120 adds the switch and the run bookkeeping to wanderer_connections and the tour_source_hints table (one row per snapshot, for its importer, gone with it). WandererWatchService and an hourly wanderer-watch job on the CronRegistrar live in the tours domain and read through WandererService; GET and PUT /api/integrations/wanderer/watch and GET /api/trips/:tripId/tours/wanderer/sources/:placeId/hint (place_edit, like the check) answer with @trek/shared contracts. A new user notification event, wanderer_source_hint, can be muted per channel. Saving a new token now clears what the last check said about the old one. There is no MCP tool, as for the rest of the personal wanderer connection. All 27 locales carry the strings, and the admin wiki page says what the check does.
209 lines
8.1 KiB
TypeScript
209 lines
8.1 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import type { TourProvenance, TourSourceCheckResponse, TourSourceHint } from '@trek/shared';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import TourProvenanceSection from './TourProvenanceSection';
|
|
import type { SourceCheck } from './useSourceCheck';
|
|
|
|
const base: TourProvenance = {
|
|
origin: 'trek',
|
|
createdAt: '2026-07-01 10:00:00',
|
|
source: { kind: 'trek' },
|
|
derivedFrom: null,
|
|
plannedOver: false,
|
|
editedLocally: null,
|
|
};
|
|
|
|
function check(over: Partial<SourceCheck> = {}): SourceCheck {
|
|
return {
|
|
checking: false,
|
|
result: null,
|
|
check: vi.fn(),
|
|
canReimport: false,
|
|
confirming: false,
|
|
askReimport: vi.fn(),
|
|
cancelReimport: vi.fn(),
|
|
reimporting: false,
|
|
reimport: vi.fn(),
|
|
...over,
|
|
} as SourceCheck;
|
|
}
|
|
|
|
// Rendered without the translation provider: every text reads as its key, so the test pins which string each part shows.
|
|
describe('TourProvenanceSection (P2C-02, MF-03)', () => {
|
|
it('names a planned tour as planned here, with no local state and no check', () => {
|
|
render(<TourProvenanceSection provenance={base} />);
|
|
expect(screen.getByText('tours.provenance.label')).toBeInTheDocument();
|
|
expect(screen.getByText('tours.badge.planned')).toBeInTheDocument();
|
|
expect(screen.getByText('tours.provenance.createdAt')).toBeInTheDocument();
|
|
expect(screen.queryByText('tours.provenance.localState')).toBeNull();
|
|
expect(screen.queryByRole('button', { name: /tours.provenance.check/ })).toBeNull();
|
|
});
|
|
|
|
it('names the trip and tour a tour was taken over from, and nothing for one that was not (LIB-02)', () => {
|
|
const { rerender } = render(
|
|
<TourProvenanceSection provenance={{ ...base, takenOverFrom: { tripTitle: 'Alps', tourName: 'Ridge' } }} />
|
|
);
|
|
expect(screen.getByText('tours.provenance.takenOverFrom')).toBeInTheDocument();
|
|
expect(screen.getByTestId('tour-provenance-taken-over')).toHaveTextContent('Alps: Ridge');
|
|
rerender(<TourProvenanceSection provenance={{ ...base, takenOverFrom: null }} />);
|
|
expect(screen.queryByTestId('tour-provenance-taken-over')).toBeNull();
|
|
});
|
|
|
|
it('shows a GPX import with its file, and that it was planned over keeping its track', () => {
|
|
render(
|
|
<TourProvenanceSection
|
|
provenance={{ ...base, origin: 'gpx', source: { kind: 'gpx', fileName: 'ridge.gpx' }, plannedOver: true }}
|
|
/>
|
|
);
|
|
expect(screen.getByText('tours.badge.gpx')).toBeInTheDocument();
|
|
expect(screen.getByText('ridge.gpx')).toBeInTheDocument();
|
|
expect(screen.getByText('tours.provenance.importedAt')).toBeInTheDocument();
|
|
expect(screen.getByText('tours.provenance.plannedOver')).toBeInTheDocument();
|
|
});
|
|
|
|
it('names a KML or KMZ import by its format, never as GPX (IO-02)', () => {
|
|
const { rerender } = render(
|
|
<TourProvenanceSection provenance={{ ...base, origin: 'gpx', source: { kind: 'gpx', fileName: 'Alps.KML' } }} />
|
|
);
|
|
expect(screen.getByText('tours.provenance.fileImport')).toBeInTheDocument();
|
|
expect(screen.queryByText('tours.badge.gpx')).toBeNull();
|
|
expect(screen.getByText('Alps.KML')).toBeInTheDocument();
|
|
rerender(
|
|
<TourProvenanceSection provenance={{ ...base, origin: 'gpx', source: { kind: 'gpx', fileName: null } }} />
|
|
);
|
|
expect(screen.getByText('tours.badge.gpx')).toBeInTheDocument();
|
|
});
|
|
|
|
it('links a wanderer snapshot to its trail, tells local edits apart and checks the source on purpose', () => {
|
|
const onCheck = vi.fn();
|
|
render(
|
|
<TourProvenanceSection
|
|
provenance={{
|
|
...base,
|
|
origin: 'wanderer',
|
|
source: {
|
|
kind: 'wanderer',
|
|
instance: 'https://trails.example',
|
|
externalId: 't1',
|
|
externalUrl: 'https://trails.example/trail/view/@me/t1',
|
|
externalUpdated: '2026-10-01 08:00:00Z',
|
|
importedAt: '2026-10-02 09:00:00',
|
|
},
|
|
editedLocally: true,
|
|
}}
|
|
check={check({ check: onCheck })}
|
|
/>
|
|
);
|
|
expect(screen.getByText('trails.example')).toBeInTheDocument();
|
|
expect(screen.getByRole('link', { name: 'tours.provenance.openSource' })).toHaveAttribute(
|
|
'href',
|
|
'https://trails.example/trail/view/@me/t1'
|
|
);
|
|
expect(screen.getByText('tours.provenance.externalUpdated')).toBeInTheDocument();
|
|
expect(screen.getByText('tours.provenance.editedLocally')).toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole('button', { name: /tours.provenance.check$/ }));
|
|
expect(onCheck).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('says what the check found, the parts that changed, and asks before the reimport', () => {
|
|
const result: TourSourceCheckResponse = {
|
|
state: 'changed',
|
|
changes: ['name', 'route'],
|
|
externalUpdated: '2026-10-14 12:00:00Z',
|
|
importedUpdated: null,
|
|
editedLocally: false,
|
|
reimport: { trailId: 't1', contentHash: 'h' },
|
|
};
|
|
const askReimport = vi.fn();
|
|
const { rerender } = render(
|
|
<TourProvenanceSection
|
|
provenance={{
|
|
...base,
|
|
origin: 'wanderer',
|
|
source: {
|
|
kind: 'wanderer',
|
|
instance: 'https://t.example',
|
|
externalId: 't1',
|
|
externalUrl: null,
|
|
externalUpdated: null,
|
|
importedAt: null,
|
|
},
|
|
}}
|
|
check={check({ result, canReimport: true, askReimport })}
|
|
/>
|
|
);
|
|
expect(screen.getByRole('status')).toHaveTextContent('tours.provenance.state.changed');
|
|
expect(screen.getByText('tours.provenance.change.name')).toBeInTheDocument();
|
|
expect(screen.getByText('tours.provenance.change.route')).toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole('button', { name: /tours.provenance.reimport/ }));
|
|
expect(askReimport).toHaveBeenCalledTimes(1);
|
|
|
|
rerender(
|
|
<TourProvenanceSection
|
|
provenance={{
|
|
...base,
|
|
origin: 'wanderer',
|
|
source: {
|
|
kind: 'wanderer',
|
|
instance: 'https://t.example',
|
|
externalId: 't1',
|
|
externalUrl: null,
|
|
externalUpdated: null,
|
|
importedAt: null,
|
|
},
|
|
}}
|
|
check={check({ result: { ...result, state: 'unavailable', changes: [], reimport: null } })}
|
|
/>
|
|
);
|
|
expect(screen.getByText('tours.provenance.body.unavailable')).toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: /tours.provenance.reimport/ })).toBeNull();
|
|
});
|
|
|
|
it('shows the background hint with its own check button until the source answered (WAN-02)', () => {
|
|
const onCheck = vi.fn();
|
|
const wanderer: TourProvenance = {
|
|
...base,
|
|
origin: 'wanderer',
|
|
source: {
|
|
kind: 'wanderer',
|
|
instance: 'https://t.example',
|
|
externalId: 't1',
|
|
externalUrl: null,
|
|
externalUpdated: null,
|
|
importedAt: null,
|
|
},
|
|
};
|
|
const hint: TourSourceHint = {
|
|
state: 'changed',
|
|
changes: ['description'],
|
|
reason: null,
|
|
externalUpdated: '2026-10-14',
|
|
checkedAt: '2026-10-20T10:00:00Z',
|
|
};
|
|
const { rerender } = render(
|
|
<TourProvenanceSection provenance={wanderer} check={check({ check: onCheck })} hint={hint} />
|
|
);
|
|
const notice = screen.getByTestId('tour-source-hint');
|
|
expect(notice).toHaveTextContent('wanderer.watch.noticeLabel');
|
|
expect(screen.getByTestId('source-hint-state')).toHaveAttribute('data-state', 'changed');
|
|
expect(screen.getByText('tours.provenance.change.description')).toBeInTheDocument();
|
|
const buttons = screen.getAllByRole('button', { name: /tours.provenance.check$/ });
|
|
expect(buttons).toHaveLength(1);
|
|
fireEvent.click(buttons[0]);
|
|
expect(onCheck).toHaveBeenCalledTimes(1);
|
|
|
|
rerender(
|
|
<TourProvenanceSection
|
|
provenance={wanderer}
|
|
check={check({ answered: true })}
|
|
hint={{ ...hint, state: 'unverifiable', changes: [], reason: 'unavailable' }}
|
|
/>
|
|
);
|
|
expect(screen.queryByTestId('tour-source-hint')).toBeNull();
|
|
expect(screen.getAllByRole('button', { name: /tours.provenance.check$/ })).toHaveLength(1);
|
|
|
|
rerender(<TourProvenanceSection provenance={wanderer} hint={hint} />);
|
|
expect(screen.queryByTestId('tour-source-hint')).toBeNull();
|
|
});
|
|
});
|