Remove unneeded unit tests.

This commit is contained in:
HarelM
2026-07-12 10:02:36 +03:00
parent c22f7404e7
commit 10d47c561b
5 changed files with 0 additions and 273 deletions
-24
View File
@@ -1,24 +0,0 @@
import { describe, it, expect } from "vitest";
import type { StyleSpecification } from "maplibre-gl";
import { undoMessages, redoMessages } from "./diffmessage";
const before = { version: 8, sources: {}, layers: [] } as StyleSpecification;
const after = {
version: 8,
sources: {},
layers: [{ id: "bg", type: "background" }],
} as StyleSpecification;
describe("diff messages", () => {
it("prefixes undo messages with 'Undo'", () => {
const messages = undoMessages(before, after);
expect(messages.length).toBeGreaterThan(0);
expect(messages.every((m) => m.startsWith("Undo "))).toBe(true);
});
it("prefixes redo messages with 'Redo'", () => {
const messages = redoMessages(before, after);
expect(messages.length).toBeGreaterThan(0);
expect(messages.every((m) => m.startsWith("Redo "))).toBe(true);
});
});
-33
View File
@@ -1,33 +0,0 @@
import { describe, it, expect, vi, afterEach } from "vitest";
import { downloadGlyphsMetadata, downloadSpriteMetadata } from "./metadata";
afterEach(() => vi.restoreAllMocks());
describe("downloadGlyphsMetadata", () => {
it("returns an empty list for an empty url", async () => {
expect(await downloadGlyphsMetadata("")).toEqual([]);
});
it("fetches the fontstacks list and de-duplicates it", async () => {
vi.stubGlobal("fetch", vi.fn(async () => ({ ok: true, json: async () => ["A", "A", "B"] })));
const fonts = await downloadGlyphsMetadata("https://example.com/{fontstack}/{range}.pbf");
expect(fonts.sort()).toEqual(["A", "B"]);
});
it("returns the default on a failed request", async () => {
vi.stubGlobal("fetch", vi.fn(async () => ({ ok: false })));
expect(await downloadGlyphsMetadata("https://example.com/x/{fontstack}/{range}.pbf")).toEqual([]);
});
});
describe("downloadSpriteMetadata", () => {
it("returns the sprite icon names", async () => {
vi.stubGlobal("fetch", vi.fn(async () => ({ ok: true, json: async () => ({ airport: {}, park: {} }) })));
const icons = await downloadSpriteMetadata("https://example.com/sprite");
expect(icons.sort()).toEqual(["airport", "park"]);
});
it("returns an empty list for an empty base url", async () => {
expect(await downloadSpriteMetadata("")).toEqual([]);
});
});
-34
View File
@@ -1,34 +0,0 @@
import { describe, it, expect } from "vitest";
import { RevisionStore } from "./revisions";
const rev = (id: string) => ({ version: 8, id, sources: {}, layers: [] }) as any;
describe("RevisionStore", () => {
it("tracks latest/current as revisions are added", () => {
const store = new RevisionStore();
store.addRevision(rev("a"));
store.addRevision(rev("b"));
expect(store.latest.id).toBe("b");
expect(store.current.id).toBe("b");
});
it("undo and redo move through history", () => {
const store = new RevisionStore();
store.addRevision(rev("a"));
store.addRevision(rev("b"));
expect(store.undo().id).toBe("a");
expect(store.undo().id).toBe("a"); // clamped at start
expect(store.redo().id).toBe("b");
expect(store.redo().id).toBe("b"); // clamped at end
});
it("clears redo history when a new revision is added after undo", () => {
const store = new RevisionStore();
store.addRevision(rev("a"));
store.addRevision(rev("b"));
store.undo();
store.addRevision(rev("c"));
expect(store.latest.id).toBe("c");
expect(store.redo().id).toBe("c");
});
});
-23
View File
@@ -1,23 +0,0 @@
import { describe, it, expect } from "vitest";
import { addSource, changeSource, deleteSource } from "./source";
const style = { version: 8, id: "s", sources: { a: { type: "vector" } }, layers: [] } as any;
describe("source helpers", () => {
it("adds a source", () => {
const result = addSource(style, "b", { type: "geojson", data: {} } as any);
expect(result.sources.b).toEqual({ type: "geojson", data: {} });
expect(result.sources.a).toBeDefined();
});
it("changes an existing source", () => {
const result = changeSource(style, "a", { type: "raster" } as any);
expect(result.sources.a).toEqual({ type: "raster" });
});
it("deletes a source without mutating the input", () => {
const result = deleteSource(style, "a");
expect(result.sources.a).toBeUndefined();
expect(style.sources.a).toBeDefined();
});
});
-159
View File
@@ -1,159 +0,0 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { validate, ErrorType } from "./urlopen";
// Mock window.location if not in browser environment
const mockLocation = {
protocol: "http:",
hostname: "localhost",
};
Object.defineProperty(global, "window", {
value: {
location: mockLocation,
},
writable: true,
});
describe("validate", () => {
let originalProtocol: string;
beforeEach(() => {
// Save original protocol
originalProtocol = window.location.protocol;
});
afterEach(() => {
// Restore original protocol
Object.defineProperty(window.location, "protocol", {
writable: true,
value: originalProtocol,
});
});
describe("when URL is empty", () => {
it("should return ErrorType.None", () => {
expect(validate("")).toBe(ErrorType.None);
});
});
describe("when URL is root relative", () => {
it("should return ErrorType.None", () => {
expect(validate("/static/style.json")).toBe(ErrorType.None);
});
});
describe("when window.location.protocol is https:", () => {
beforeEach(() => {
Object.defineProperty(window.location, "protocol", {
writable: true,
value: "https:",
});
});
it("should return EmptyHttpsProtocol when URL has no protocol", () => {
expect(validate("example.com")).toBe(ErrorType.EmptyHttpsProtocol);
expect(validate("www.example.com/path")).toBe(ErrorType.EmptyHttpsProtocol);
});
it("should return None for valid https URLs", () => {
expect(validate("https://example.com")).toBe(ErrorType.None);
expect(validate("https://www.example.com/path")).toBe(ErrorType.None);
});
it("should return CorsError for http URLs pointing to non-local hosts", () => {
expect(validate("http://example.com")).toBe(ErrorType.CorsError);
expect(validate("http://api.example.com/endpoint")).toBe(ErrorType.CorsError);
});
it("should return None for http URLs pointing to localhost", () => {
expect(validate("http://localhost")).toBe(ErrorType.None);
expect(validate("http://localhost:3000")).toBe(ErrorType.None);
expect(validate("http://127.0.0.1")).toBe(ErrorType.None);
expect(validate("http://127.0.0.1:8080")).toBe(ErrorType.None);
expect(validate("http://127.255.255.255")).toBe(ErrorType.None);
});
it("should return None for http URLs pointing to IPv6 localhost", () => {
expect(validate("http://[::1]")).toBe(ErrorType.None);
expect(validate("http://[::1]:3000")).toBe(ErrorType.None);
});
it("should return None for other protocols", () => {
expect(validate("ftp://example.com")).toBe(ErrorType.None);
expect(validate("ws://example.com")).toBe(ErrorType.None);
expect(validate("wss://example.com")).toBe(ErrorType.None);
});
});
describe("when window.location.protocol is http:", () => {
beforeEach(() => {
Object.defineProperty(window.location, "protocol", {
writable: true,
value: "http:",
});
});
it("should return EmptyHttpOrHttpsProtocol when URL has no protocol", () => {
expect(validate("example.com")).toBe(ErrorType.EmptyHttpOrHttpsProtocol);
expect(validate("www.example.com/path")).toBe(ErrorType.EmptyHttpOrHttpsProtocol);
});
it("should return None for valid http URLs", () => {
expect(validate("http://example.com")).toBe(ErrorType.None);
expect(validate("http://www.example.com/path")).toBe(ErrorType.None);
});
it("should return None for valid https URLs", () => {
expect(validate("https://example.com")).toBe(ErrorType.None);
expect(validate("https://www.example.com/path")).toBe(ErrorType.None);
});
it("should return None for localhost URLs", () => {
expect(validate("http://localhost")).toBe(ErrorType.None);
expect(validate("http://127.0.0.1")).toBe(ErrorType.None);
});
});
describe("edge cases", () => {
it("should handle URLs with ports", () => {
Object.defineProperty(window.location, "protocol", {
writable: true,
value: "https:",
});
expect(validate("https://example.com:8443")).toBe(ErrorType.None);
expect(validate("http://example.com:8080")).toBe(ErrorType.CorsError);
expect(validate("http://localhost:3000")).toBe(ErrorType.None);
});
it("should handle URLs with paths and query strings", () => {
Object.defineProperty(window.location, "protocol", {
writable: true,
value: "https:",
});
expect(validate("https://example.com/path?query=value")).toBe(ErrorType.None);
expect(validate("http://example.com/path?query=value")).toBe(ErrorType.CorsError);
});
it("should handle malformed URLs that cannot be parsed", () => {
Object.defineProperty(window.location, "protocol", {
writable: true,
value: "https:",
});
expect(validate("not a url at all")).toBe(ErrorType.EmptyHttpsProtocol);
expect(validate("://")).toBe(ErrorType.EmptyHttpsProtocol);
});
it("should handle localhost variations case-insensitively", () => {
Object.defineProperty(window.location, "protocol", {
writable: true,
value: "https:",
});
expect(validate("http://LOCALHOST")).toBe(ErrorType.None);
expect(validate("http://LocalHost:3000")).toBe(ErrorType.None);
});
});
});