Replaced labels with icons in the SR and Action badges
This commit is contained in:
@@ -3,7 +3,8 @@ const { test } = require("node:test");
|
||||
const { loadApplication } = require("./support/application.cjs");
|
||||
const response = data => new Response(JSON.stringify(data), { status: 200 });
|
||||
function setup(fetch) {
|
||||
const document = { createElement: () => ({ attributes: {}, addEventListener() {}, setAttribute(key, value) { this.attributes[key] = value; } }) };
|
||||
const document = { createElement: () => ({ attributes: {}, append() {}, addEventListener() {}, setAttribute(key, value) { this.attributes[key] = value; } }) };
|
||||
document.createElementNS = (_, tag) => document.createElement(tag);
|
||||
const app = loadApplication("content", { fetch, document, Intl, Date });
|
||||
app.currentUser.allowsCrmActivities = () => true;
|
||||
app.debugContentView.renderDebugPanel = () => {};
|
||||
@@ -18,8 +19,12 @@ test("SR badge shows reported hours, sums linked SRs and preserves missing value
|
||||
for (const [values, expected] of [[[4], "4h"], [[0], "0h"], [[2, "1.5"], "3.5h"], [[0.1, 0.2], "0.3h"], [[null], "N/D"], [[4, null], "N/D"], [[""], "N/D"], [["invalid"], "N/D"]]) {
|
||||
const app = setup(async () => response({ items: values.map((value, index) => ({ ...sr("A", `SR-${index}`), ReportedHours_c: value })), hasMore: false }));
|
||||
await app.opportunityCrmServiceRequests.load("synthetic", 1);
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("A").textContent, `\u2705 SR (${expected})`);
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("OTHER").textContent, "\u26d4 SR");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("A").textContent, expected);
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("OTHER").textContent, "0h");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("A").title, "Whether a Service Request has been created for the opportunities.");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("OTHER").title, "Whether a Service Request has been created for the opportunities.");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("A").attributes["data-state"], "matched");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("OTHER").attributes["data-state"], "missing");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -89,11 +94,11 @@ test("CRM query preserves payload and pagination after opportunities, uses token
|
||||
assert.equal(app.debugContentView.getRequestCategory(log), "serviceRequests");
|
||||
}
|
||||
const found = app.opportunityCrmServiceRequests.createBadge("TEST-1");
|
||||
assert.equal(found.textContent, "\u2705 SR (0h)");
|
||||
assert.equal(found.textContent, "0h");
|
||||
assert.equal(found.attributes["data-state"], "matched");
|
||||
for (const detail of ["SR-0", "SR-1", "Reported Hours: 0", "Test Owner", "test@example.invalid", "<script>synthetic</script>"])
|
||||
assert.ok(found.attributes["aria-label"].includes(detail));
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("OTHER").textContent, "\u26d4 SR");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("OTHER").textContent, "0h");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge(null), null);
|
||||
app.opportunityCrmServiceRequests.reset();
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("TEST-1"), null);
|
||||
@@ -118,7 +123,7 @@ test("CRM failures do not mislabel missing SRs or block the opportunity list", a
|
||||
await app.opportunitiesController.requestOpportunities("token", "Current Quarter", {}, 1);
|
||||
assert.equal(loaded, true);
|
||||
await app.opportunityCrmServiceRequests.load("token", 1);
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("TEST").textContent, "SR ?");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("TEST").textContent, "?");
|
||||
assert.equal(app.debugState.requestLog.at(-1).status, "failed");
|
||||
}
|
||||
});
|
||||
@@ -133,8 +138,8 @@ test("stale CRM results cannot overwrite a reopened modal or continue pagination
|
||||
await app.opportunityCrmServiceRequests.load("token", 2);
|
||||
resolveOld(response({ items: [sr("OLD")], hasMore: true, count: 1, offset: 0 }));
|
||||
await old;
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("NEW").textContent, "\u2705 SR (0h)");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("OLD").textContent, "\u26d4 SR");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("NEW").textContent, "0h");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("OLD").textContent, "0h");
|
||||
assert.equal(app.debugState.requestLog.length, 1);
|
||||
});
|
||||
|
||||
@@ -155,8 +160,8 @@ test("Reference changes share pending pagination and reuse completed CRM results
|
||||
app.opportunitiesQueryState.periodRequestVersion = 3;
|
||||
await app.opportunityCrmServiceRequests.load("token", 3);
|
||||
assert.equal(calls, 2);
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("A").textContent, "\u2705 SR (0h)");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("B").textContent, "\u2705 SR (0h)");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("A").textContent, "0h");
|
||||
assert.equal(app.opportunityCrmServiceRequests.createBadge("B").textContent, "0h");
|
||||
app.opportunityCrmServiceRequests.reset();
|
||||
await app.opportunityCrmServiceRequests.load("token", 3);
|
||||
assert.equal(calls, 3);
|
||||
|
||||
Reference in New Issue
Block a user