Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import { PWA_CODES, PwaError } from "../errors/errors";
import { ManifestBuilder } from "./manifest";
describe("ManifestBuilder", () => {
it("builds a valid minimal manifest", { timeout: 5000 }, () => {
const m = new ManifestBuilder()
.setName("App")
.addIcon({ src: "/i.png", sizes: "1x1" })
.build();
expect(m.name).toBe("App");
expect(m.icons.length).toBe(1);
});
it("raises MANIFEST_VALIDATION when required fields are missing", {
timeout: 5000,
}, () => {
try {
new ManifestBuilder().build();
throw new Error("did not throw");
} catch (e) {
expect(e).toBeInstanceOf(PwaError);
expect((e as PwaError).code).toBe(PWA_CODES.MANIFEST_VALIDATION);
}
});
it("raises MANIFEST_VALIDATION when no icons are added", {
timeout: 5000,
}, () => {
try {
new ManifestBuilder().setName("X").build();
throw new Error("did not throw");
} catch (e) {
expect((e as PwaError).code).toBe(PWA_CODES.MANIFEST_VALIDATION);
}
});
it("supports every documented setter", { timeout: 5000 }, () => {
const m = new ManifestBuilder()
.setName("X")
.setShortName("X")
.setDescription("desc")
.setStartUrl("/")
.setScope("/")
.setDisplay("standalone")
.setOrientation("portrait")
.setBackgroundColor("#fff")
.setThemeColor("#000")
.setLang("en")
.setDir("ltr")
.setPreferRelatedApplications(false)
.addIcon({ src: "/i.png", sizes: "1x1" })
.addShortcut({
name: "S",
url: "/s",
icons: [{ src: "/s.png", sizes: "1x1" }],
})
.addRelatedApplication({ platform: "ios", id: "app.id" })
.setShareTarget({
action: "/share",
method: "POST",
enctype: "multipart/form-data",
params: { title: "t", url: "u" },
})
.build();
expect(m.short_name).toBe("X");
expect(m.display).toBe("standalone");
expect(m.orientation).toBe("portrait");
expect(m.dir).toBe("ltr");
expect(m.shortcuts?.length).toBe(1);
expect(m.related_applications?.length).toBe(1);
expect(m.share_target?.action).toBe("/share");
expect(m.prefer_related_applications).toBe(false);
});
it("toBlob produces application/manifest+json", {
timeout: 5000,
}, async () => {
const blob = new ManifestBuilder()
.setName("App")
.addIcon({ src: "/i.png", sizes: "1x1" })
.toBlob();
expect(blob.type).toBe("application/manifest+json");
const text = await blob.text();
const parsed = JSON.parse(text) as { name: string };
expect(parsed.name).toBe("App");
});
});