feat(dashboard): map latest user locations
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { UserWorldMap } from "./user-world-map";
|
||||
|
||||
describe("UserWorldMap", () => {
|
||||
it("renders an accessible linked marker, text fallback, and open-data attribution", () => {
|
||||
const markup = renderToStaticMarkup(<UserWorldMap locations={[{
|
||||
userId: "11111111-1111-4111-8111-111111111111",
|
||||
name: "Dani",
|
||||
discordUsername: "dani",
|
||||
latitude: 37.4056,
|
||||
longitude: -122.0775,
|
||||
location: "Mountain View, California, US",
|
||||
classification: "clear",
|
||||
source: "game",
|
||||
observedAt: new Date("2026-08-01T12:00:00Z"),
|
||||
}]} unavailableCount={2} />);
|
||||
|
||||
expect(markup).toContain('role="group"');
|
||||
expect(markup).toContain('class="map-marker-target"');
|
||||
expect(markup).toContain("Latest approximate location for registered users");
|
||||
expect(markup).toContain('href="/admin/users/11111111-1111-4111-8111-111111111111"');
|
||||
expect(markup).toContain("Mountain View, California, US");
|
||||
expect(markup).toContain("Natural Earth, public domain");
|
||||
expect(markup).toContain("2 without coordinates");
|
||||
|
||||
const countryPaths = [...markup.matchAll(/<path d="([^"]+)"/g)].map((match) => match[1] ?? "");
|
||||
expect(countryPaths.length).toBeGreaterThan(100);
|
||||
for (const path of countryPaths) {
|
||||
const subpaths = path.split("M").slice(1);
|
||||
for (const subpath of subpaths) {
|
||||
const xCoordinates = [...subpath.matchAll(/(?:^|L)(-?\d+(?:\.\d+)?),/g)].map((match) => Number(match[1]));
|
||||
for (let index = 1; index < xCoordinates.length; index += 1) {
|
||||
expect(Math.abs(xCoordinates[index]! - xCoordinates[index - 1]!)).toBeLessThan(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user