Table sorting preferences will be saved and reused based on the user’s selections

This commit is contained in:
2026-10-25 00:39:55 -03:00
parent 19edee4e11
commit 0f1f399d1a
40 changed files with 896 additions and 230 deletions

View File

@@ -125,7 +125,9 @@ class Element {
constructor(tag, document) { this.tag = tag; this.document = document; this.children = []; this.dataset = {}; this.attributes = {}; this.listeners = {}; }
append(...nodes) { nodes.forEach(node => { node.parent = this; }); this.children.push(...nodes); }
set textContent(value) { this.text = value; this.children = []; }
get textContent() { return this.text || ""; }
get textContent() { return (this.text || "") + this.children.map(child => child.textContent).join(""); }
querySelectorAll(selector) { return walk(this).filter(node => node !== this && node.tag === selector); }
querySelector(selector) { return walk(this).find(node => node.attributes["data-sort-key"] === selector.match(/data-sort-key="([^"]+)"/)?.[1]); }
setAttribute(key, value) { this.attributes[key] = value; }
addEventListener(key, fn) { this.listeners[key] = fn; }
focus() { this.document.activeElement = this; }
@@ -134,13 +136,28 @@ class Element {
click() { return this.listeners.click(); }
}
const walk = node => [node, ...node.children.flatMap(walk)];
function setup() {
function setup(localStorage) {
const document = { createElement: tag => new Element(tag, document), createElementNS: (_, tag) => new Element(tag, document),
getElementById: id => id === app.contracts.MODAL_ID ? overlay : null };
const overlay = new Element("main", document);
const app = loadApplication("content", { document, Intl, Date });
const app = loadApplication("content", { document, Intl, Date, localStorage });
return { app, overlay, document };
}
test("serviceRequests sorts typed values and restores the selected header across application instances", () => {
const saved = new Map();
const storage = { getItem: key => saved.get(key), setItem: (key, value) => saved.set(key, value) };
const items = [{ id: "Later", created: "2026-02-01" }, { id: "Earlier", created: "2026-01-31" }] ;
const first = setup(storage);
first.app.serviceRequestsView.openServiceRequestsModal(customer).render(items);
walk(first.overlay).find(node => node.attributes["data-sort-key"] === "created").click();
const second = setup(storage);
second.app.serviceRequestsView.openServiceRequestsModal(customer).render(items);
const rows = walk(second.overlay).find(node => node.tag === "tbody").children;
assert.equal(rows[0].children[2].textContent, "Earlier");
assert.equal(walk(second.overlay).find(node => node.attributes["data-sort-key"] === "created").parent.attributes["aria-sort"], "ascending");
assert.equal(items[0].id, "Later");
});
const customer = { CustomerAccount: { PartyNumber: "customer-test", PartyUniqueName: "Synthetic customer" } };
test("service request search covers nested and formatted columns and preserves errors and full results on clearing", () => {