A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.

9 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-browser.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-browser.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-browser.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 toolbar: Back and Forward are greyed out when there's nowhere to go cc08c7a 1 week, 2 days ago History
zoom.test.ts · 2.8 KB · 70 lines
1import { describe, expect, it } from "vitest";
2import { MAX_SITES, stepZoom, zoomLabel, zoomSite, ZoomStore, ZOOM_STEPS } from "../src/zoom";
3
4describe("zoom steps", () => {
5 it("go up and down Chrome's steps, and back to 100%", () => {
6 expect(stepZoom(1, "in")).toBe(1.1);
7 expect(stepZoom(1.1, "in")).toBe(1.25);
8 expect(stepZoom(1, "out")).toBe(0.9);
9 expect(stepZoom(0.9, "out")).toBe(0.8);
10 expect(stepZoom(2.5, "reset")).toBe(1);
11 });
12 it("stop at 25% and 500%", () => {
13 expect(stepZoom(5, "in")).toBe(5);
14 expect(stepZoom(0.25, "out")).toBe(0.25);
15 });
16 it("from a size between steps, go to the next step that way (a pinch, an old value)", () => {
17 expect(stepZoom(1.17, "in")).toBe(1.25);
18 expect(stepZoom(1.17, "out")).toBe(1.1);
19 expect(stepZoom(1.1000001, "in")).toBe(1.25); // not stuck on the step it is already at
20 expect(stepZoom(Number.NaN, "in")).toBe(1.1);
21 });
22 it("label as a percent", () => {
23 expect(zoomLabel(1.25)).toBe("125%");
24 expect(zoomLabel(0.33)).toBe("33%");
25 expect(ZOOM_STEPS).toContain(1);
26 });
27});
28
29describe("which site a page's zoom belongs to", () => {
30 it("is the host name of a web page, port and case aside", () => {
31 expect(zoomSite("https://X.com/home")).toBe("x.com");
32 expect(zoomSite("http://127.0.0.1:8899/a")).toBe("127.0.0.1");
33 });
34 it("is none for the browser's own pages and anything else", () => {
35 expect(zoomSite("dbb-cards://view/1")).toBeNull();
36 expect(zoomSite("about:blank")).toBeNull();
37 expect(zoomSite("not a url")).toBeNull();
38 });
39});
40
41describe("the remembered sizes", () => {
42 it("are saved, read back after a restart, and 100% is forgotten", () => {
43 let file: string | null = null;
44 const a = new ZoomStore(null, (t) => (file = t));
45 a.set("x.com", 1.25);
46 a.set("ebay.com", 0.9);
47 expect(a.get("x.com")).toBe(1.25);
48 const b = new ZoomStore(file, () => {});
49 expect(b.get("x.com")).toBe(1.25);
50 expect(b.get("ebay.com")).toBe(0.9);
51 expect(b.get("other.com")).toBe(1);
52 expect(b.get(null)).toBe(1);
53 a.set("x.com", 1);
54 expect(JSON.parse(file!).sites).toEqual({ "ebay.com": 0.9 });
55 });
56 it("ignore a damaged file and values out of range", () => {
57 expect(new ZoomStore("{nope", () => {}).size).toBe(0);
58 const s = new ZoomStore(JSON.stringify({ v: 1, sites: { "a.com": 99, "b.com": "2", "c.com": 1.5 } }), () => {});
59 expect(s.get("a.com")).toBe(1);
60 expect(s.get("b.com")).toBe(1);
61 expect(s.get("c.com")).toBe(1.5);
62 });
63 it("keep at most MAX_SITES, dropping the oldest change", () => {
64 const s = new ZoomStore(null, () => {});
65 for (let i = 0; i <= MAX_SITES; i++) s.set(`s${i}.com`, 1.1);
66 expect(s.size).toBe(MAX_SITES);
67 expect(s.get("s0.com")).toBe(1);
68 expect(s.get(`s${MAX_SITES}.com`)).toBe(1.1);
69 });
70});