mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
782e613506
- GPX files drop onto the map or a day; the import lands on that day - wanderer connection per user in Integrations; the workspace offers the user's own trails only, behind an admin switch under the Tours addon - wanderer difficulty is stored on the SAC scale (T1 to T3), backfilled - a GPX or wanderer import can be planned as an editable tour, either in place (the recorded track is kept and can be restored) or as a new tour that remembers the import it came from - rails, rows and detail dialog follow the plan sidebar's cards and badges - admin addon shelves with more than one row fold, collapsed by default - reverse-geocoded waypoint names are cached on the device
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { fireEvent } from '@testing-library/react';
|
|
import { vi } from 'vitest';
|
|
|
|
/**
|
|
* Presses a control that opens the browser's file picker by building an
|
|
* `<input type="file">` and clicking it, and hands that picker `files` the way
|
|
* a user choosing them would. Returns the picker, or null when the press built none.
|
|
*/
|
|
export function pickFiles(control: HTMLElement, files: File[]): HTMLInputElement | null {
|
|
const createElement = document.createElement.bind(document);
|
|
let picker: HTMLInputElement | null = null;
|
|
const spy = vi.spyOn(document, 'createElement').mockImplementation(((
|
|
tagName: string,
|
|
options?: ElementCreationOptions
|
|
) => {
|
|
const element = createElement(tagName, options);
|
|
if (tagName.toLowerCase() === 'input') {
|
|
picker = element as HTMLInputElement;
|
|
vi.spyOn(picker, 'click').mockImplementation(() => undefined);
|
|
}
|
|
return element;
|
|
}) as typeof document.createElement);
|
|
fireEvent.click(control);
|
|
spy.mockRestore();
|
|
if (!picker) return null;
|
|
const input: HTMLInputElement = picker;
|
|
Object.defineProperty(input, 'files', { value: files, configurable: true });
|
|
fireEvent.change(input);
|
|
return input;
|
|
}
|