Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion app/src/test/web/app.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ test("a stop tap from the list opens the session to ask there", () => {
const page = load();
const row = page.window.row({ ...SESSIONS[1], name: "mhm a/1", ended: false });
row.querySelectorAll("button")[0].onclick();
assert.equal(page.location.hash, "s=mhm%20a%2F1");
assert.equal(page.location.hash, "#s=mhm%20a%2F1");
});

test("folder names come from Mac and Windows paths alike", () => {
Expand Down Expand Up @@ -423,6 +423,37 @@ test("starting a session takes the form's place, so back from it is the list", a
assert.deepEqual(plain(page.steps), [["replace", "#s=mhm-new"], ["back"]]);
});

test("a link to a session opens its view, titled by its name until the server says more", () => {
const page = load({ hash: "s=mhm-a" });
page.window.route();
assert.equal(page.$("session-view").hidden, false);
assert.equal(page.$("list-view").hidden, true);
assert.equal(page.$("session-title").textContent, "mhm-a");
assert.equal(page.app.current, "mhm-a");
});

test("a session from the list is titled by its display name at once", () => {
const page = load();
page.app.sessions = [{ name: "mhm-a", display: "fix the login", state: "WAITING" }];
page.location.hash = "s=mhm-a";
page.window.route();
assert.equal(page.$("session-title").textContent, "fix the login");
});

test("a session started with a name shows that name before its first screen arrives", async () => {
const page = load({ server: (path) => ({ body: path === "/api/spawn" ? { ok: true, text: "mhm-new started (shell in /tmp)" } : { sessions: [], ended: [], harnesses: ["shell"] } }) });
page.window.route();
page.$("new-button").onclick();
page.window.route();
await page.settle();
page.$("new-project").value = "/tmp";
page.$("new-name").value = "my-shell";
await page.window.startSession({ preventDefault() {} });
page.window.route();
assert.equal(page.$("session-view").hidden, false);
assert.equal(page.$("session-title").textContent, "my-shell");
});

test("a session reached by a link or a reload has no list below: its entry becomes the list", () => {
const page = load({ hash: "s=mhm-a" });
page.window.route();
Expand Down
15 changes: 12 additions & 3 deletions app/src/test/web/fake-browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ export function load({ hash = "", storage = new Map(), storageFails = false, ser
head: new FakeElement("head"),
visibilityState: "visible",
getElementById: byId,
createElement: (tag) => new FakeElement(tag),
createElement: (tag) => {
const el = new FakeElement(tag);
// a canvas measures text as if every character were 7px wide
if (el.tagName === "CANVAS") el.getContext = () => ({ font: "", measureText: (text) => ({ width: 7 * text.length }) });
return el;
},
querySelectorAll: (selector) => [...elements.values()].filter((el) => el.matches(selector)),
addEventListener() {},
};
Expand All @@ -172,9 +177,13 @@ export function load({ hash = "", storage = new Map(), storageFails = false, ser
addEventListener() {}
close() { this.readyState = EventSource.CLOSED; }
}
// like a browser's: the hash reads with its "#" (or as "" when empty), set with or without
let fragment = hash.replace(/^#/, "");
const location = {
hash, pathname: "/",
replace(url) { page.steps.push(["replace", url]); location.hash = url.replace(/^#/, ""); },
get hash() { return fragment ? "#" + fragment : ""; },
set hash(value) { fragment = String(value).replace(/^#/, ""); },
pathname: "/",
replace(url) { page.steps.push(["replace", url]); location.hash = url; },
};
// new Option(text, value), as a select or datalist holds them
function Option(text, value) {
Expand Down
Loading