mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
feat(mobile): add a place shared from Google Maps or Amap to a trip
A place shared from a maps app to TREK could only be kept among a trip's links or read as a booking. A map link is now first offered as a place: after the trip is picked, its new place sheet opens with the link in the search, which looks it up at once through the existing resolver, so name, address and position are filled in and only need saving. Other links are offered as before. Addresses discussion #2582.
This commit is contained in:
@@ -22,7 +22,7 @@ beforeEach(() => {
|
||||
// A second spyOn returns the first spy with its calls; start every test clean.
|
||||
vi.restoreAllMocks();
|
||||
navigate.mockReset();
|
||||
useSharedImportStore.setState({ file: null, tripId: null, link: null });
|
||||
useSharedImportStore.setState({ file: null, tripId: null, link: null, placeLink: null });
|
||||
useAddonStore.setState({ addons: [{ id: 'collab', enabled: true }] as never, loaded: true });
|
||||
useTripAddonsStore.setState({ trips: {} });
|
||||
// Every trip follows the instance switch unless a test says otherwise; answered at once, so no read outlives its test.
|
||||
@@ -217,6 +217,35 @@ describe('NativeImportSheet', () => {
|
||||
expect(saveSharedLink).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('offers a shared map link as a place first, and hands it to the trip picked (#2582)', async () => {
|
||||
const maps = {
|
||||
url: 'https://www.google.com/maps/place/Time+Out+Market',
|
||||
title: 'Time Out Market',
|
||||
presetTripId: null,
|
||||
};
|
||||
render(<NativeImportSheet />);
|
||||
act(() => useSharedImportStore.getState().setFile(page(), maps));
|
||||
const choices = await screen.findAllByRole('button', {
|
||||
name: /Add it as a place|Save to the trip's links|Read a booking/,
|
||||
});
|
||||
expect(choices[0]).toHaveAccessibleName(/Add it as a place/);
|
||||
|
||||
fireEvent.click(choices[0]);
|
||||
expect(screen.getByText('Add the place to which trip?')).toBeInTheDocument();
|
||||
fireEvent.click(await screen.findByRole('button', { name: /Japan/ }));
|
||||
expect(useSharedImportStore.getState().placeLink).toEqual({ tripId: 2, url: maps.url });
|
||||
expect(useSharedImportStore.getState().file).toBeNull();
|
||||
expect(navigate).toHaveBeenCalledWith('/trips/2');
|
||||
expect(saveSharedLink).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('offers no place for a link that is not a map', async () => {
|
||||
render(<NativeImportSheet />);
|
||||
act(() => useSharedImportStore.getState().setFile(page(), link()));
|
||||
await screen.findByText('What should TREK do with this link?');
|
||||
expect(screen.queryByRole('button', { name: /Add it as a place/ })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('stays closed with nothing shared', () => {
|
||||
render(<NativeImportSheet />);
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user