Add an icon size setting (#3)
This commit was merged in pull request #3.
This commit is contained in:
1 parent
3070db4fb4
commit
472a48f4bd
22 files changed
+901
-51
No files matched your search
@@ -235,6 +235,101 @@ const serve = () => new Promise((resolve) => {
|
||||
assert.ok(!(await p.$(".widget-slot")));
|
||||
await p.evaluate(() => { window.launcher.reload(); }); await settle();
|
||||
assert.equal(await p.$$eval(".slots > li", (ls) => ls.length), 4);
|
||||
// ---- icon size: a slider in the home menu resizes every icon grid live, is saved, and survives a reload
|
||||
const grid = () => p.$eval(".slots", (g) => {
|
||||
const gs = g.getBoundingClientRect(), tiles = [...g.querySelectorAll(".tile")].map((t) => {
|
||||
const r = t.getBoundingClientRect(), i = t.querySelector(".icon").getBoundingClientRect();
|
||||
return { r, i, name: t.querySelector(".name").getBoundingClientRect(), font: parseFloat(getComputedStyle(t.querySelector(".name")).fontSize) };
|
||||
});
|
||||
return {
|
||||
cols: getComputedStyle(g).gridTemplateColumns.split(" ").length,
|
||||
row: parseFloat(getComputedStyle(g).gridTemplateRows.split(" ")[0]),
|
||||
icon: tiles[0].i.width, font: tiles[0].font, gridLeft: gs.left, gridRight: gs.right,
|
||||
tiles: tiles.map((t) => ({ l: t.r.left, r: t.r.right, t: t.r.top, b: t.r.bottom, il: t.i.left, ir: t.i.right, it: t.i.top, ib: t.i.bottom, nb: t.name.bottom })),
|
||||
};
|
||||
});
|
||||
const noOverlapOrClip = (g, what) => {
|
||||
for (const [n, a] of g.tiles.entries()) {
|
||||
assert.ok(a.il >= a.l - 0.5 && a.ir <= a.r + 0.5, `${what}: icon ${n} inside its tile (x)`);
|
||||
assert.ok(a.it >= a.t - 0.5 && a.nb <= a.b + 1, `${what}: icon and label ${n} inside its tile (y)`);
|
||||
assert.ok(a.l >= g.gridLeft - 0.5 && a.r <= g.gridRight + 0.5, `${what}: tile ${n} inside the grid`);
|
||||
for (const c of g.tiles.slice(n + 1)) {
|
||||
assert.ok(a.r <= c.l + 0.5 || c.r <= a.l + 0.5 || a.b <= c.t + 0.5 || c.b <= a.t + 0.5, `${what}: tiles ${n} overlap`);
|
||||
}
|
||||
}
|
||||
};
|
||||
const base = await grid();
|
||||
noOverlapOrClip(base, "100%");
|
||||
assert.equal(base.icon, 40, "the default icon is today's 40px");
|
||||
assert.equal(base.row, 64);
|
||||
assert.equal(base.cols, 5);
|
||||
await shot(p, "06-icon-size-before");
|
||||
await longpress(".home", 0.95);
|
||||
await p.click(".sheet-item >> text=Icon size"); await settle();
|
||||
assert.equal(await p.$eval(".icon-size-slider", (e) => e.value), "100");
|
||||
assert.equal((await p.textContent(".icon-size-value")).trim(), "100%");
|
||||
const setSlider = async (v) => { await p.$eval(".icon-size-slider", (e, v) => { e.value = v; e.dispatchEvent(new Event("input", { bubbles: true })); }, v); await settle(); };
|
||||
await setSlider("130");
|
||||
const big = await grid();
|
||||
noOverlapOrClip(big, "130%");
|
||||
assert.equal(big.icon, 52, "icon 40 -> 52");
|
||||
assert.equal(big.row, 83);
|
||||
assert.equal(big.cols, 4, "fewer columns at a larger size");
|
||||
assert.ok(big.font > base.font, "label text grows with the icon");
|
||||
const pv = await p.$eval(".icon-preview .icon", (i) => i.getBoundingClientRect().width);
|
||||
assert.equal(pv, 52, "the preview shows the size");
|
||||
assert.equal((await p.textContent(".icon-size-value")).trim(), "130%");
|
||||
await shot(p, "07-icon-size-large");
|
||||
await p.click(".icon-presets >> text=Small"); await settle();
|
||||
assert.equal(await p.$eval(".icon-size-slider", (e) => e.value), "80");
|
||||
const small = await grid();
|
||||
noOverlapOrClip(small, "80%");
|
||||
assert.ok(small.icon < base.icon && small.cols > base.cols && small.row < base.row);
|
||||
await setSlider("160");
|
||||
noOverlapOrClip(await grid(), "160%");
|
||||
await setSlider("70");
|
||||
noOverlapOrClip(await grid(), "70%");
|
||||
await shot(p, "08-icon-size-small");
|
||||
await setSlider("130");
|
||||
assert.equal(await p.evaluate(() => localStorage.getItem("launcher.iconSize")), "130");
|
||||
await p.click(".sheet >> text=Done"); await settle();
|
||||
// the drawer follows: bigger icons, fewer columns
|
||||
await p.click(".search-pill"); await settle();
|
||||
const dr = await p.$eval(".drawer .apps", (u) => ({
|
||||
cols: getComputedStyle(u).gridTemplateColumns.split(" ").length,
|
||||
icon: u.querySelector(".icon").getBoundingClientRect().width,
|
||||
}));
|
||||
assert.equal(dr.cols, 3, "drawer: 4 columns -> 3");
|
||||
assert.ok(Math.abs(dr.icon - 67.6) < 0.1, `drawer icon 52px -> 67.6px: ${dr.icon}`);
|
||||
await shot(p, "09-icon-size-drawer-large");
|
||||
await p.click(".drawer-head >> text=Close"); await settle();
|
||||
// saved: it survives a reload, and 100% is saved as 100
|
||||
await p.reload(); await p.waitForSelector(".slots .tile");
|
||||
const again = await grid();
|
||||
assert.equal(again.icon, 52);
|
||||
assert.equal(again.cols, 4);
|
||||
await longpress(".home", 0.95);
|
||||
await p.click(".sheet-item >> text=Icon size"); await settle();
|
||||
await p.click(".icon-presets >> text=Medium"); await settle();
|
||||
await p.click(".sheet >> text=Done"); await settle();
|
||||
const back = await grid();
|
||||
assert.equal(back.icon, 40); assert.equal(back.row, 64); assert.equal(back.cols, 5);
|
||||
// a corrupt saved value is reported (alert and console), not silently replaced
|
||||
const errors = [];
|
||||
p.on("console", (m) => { if (m.type() === "error") errors.push(m.text()); });
|
||||
await p.evaluate(() => localStorage.setItem("launcher.iconSize", "huge"));
|
||||
await p.reload(); await p.waitForSelector(".slots .tile");
|
||||
assert.ok(errors.some((e) => e.includes("saved icon size \"huge\" is not a whole number")), `logged: ${errors}`);
|
||||
assert.ok((await p.textContent("#app")).includes("Icon size problem"), "a notice shows");
|
||||
assert.equal(await p.evaluate(() => localStorage.getItem("launcher.iconSize")), "huge", "the bad value is left alone");
|
||||
await longpress(".home", 0.95);
|
||||
await p.click(".sheet-item >> text=Icon size"); await settle();
|
||||
assert.ok(await p.$(".sheet .alert.destructive"), "the sheet shows the error");
|
||||
await shot(p, "10-icon-size-corrupt");
|
||||
await p.click(".icon-presets >> text=Medium"); await settle();
|
||||
assert.equal(await p.evaluate(() => localStorage.getItem("launcher.iconSize")), "100", "choosing a size replaces it");
|
||||
assert.ok(!(await p.$(".sheet .alert")), "and clears the error");
|
||||
await p.click(".sheet >> text=Done"); await settle();
|
||||
console.log("launcher ok");
|
||||
|
||||
await b.close();
|
||||
|
||||
Reference in new issue
Block a user