Implemented a tooltip on the SR to display the Internal SR

This commit is contained in:
2026-09-29 13:53:38 -03:00
parent a182609415
commit 4d3f1f9760
21 changed files with 400 additions and 28 deletions

View File

@@ -1,6 +1,31 @@
const assert = require("node:assert/strict");
const { test } = require("node:test");
const { loadApplication } = require("./support/application.cjs");
const flush = () => new Promise(resolve => setImmediate(resolve));
test("internal SR uses Session without TokenRelay or retries on 401", async () => {
const h = setup();
let renewals = 0;
const sent = [];
h.app.authSessionState.accessToken = "stale-token";
h.app.authTokenRelay.requestTokenRelay = async () => `fresh-${++renewals}`;
h.app.debugContentView.renderDebugPanel = () => {};
h.app.platformContentMessages.sendRuntimeMessage = async message => {
sent.push(message);
return { ok: false, httpStatus: 401, error: "Unauthorized" };
};
h.app.fusionCrmServiceRequests.requestCrmServiceRequest = async () => [{ SrId: "123", SrNumber: "SR123", OpportunityName_Id_c: { OptyNumber: "OP1" } }];
await h.app.opportunityCrmServiceRequests.load("synthetic", 1);
const badge = h.app.opportunityCrmServiceRequests.createBadge("OP1");
h.modal.append(badge);
badge.listeners.pointerenter();
await flush();
assert.equal(renewals, 0);
assert.equal(sent.length, 1);
assert.equal(sent[0].token, undefined);
assert.ok(sent.every(item => item.type === "opportunitiesExtension.requestInternalServiceRequest"));
assert.ok(h.walk(h.panel()).some(node => node.textContent === "Unauthorized"));
});
function setup() {
const document = { activeElement: null, listeners: new Map() };
@@ -104,3 +129,42 @@ test("SR popover pins on click, closes on Escape/outside/scroll/reset and remove
assert.equal(panel(), undefined);
assert.equal(document.listeners.size, 0);
});
test("SR tooltip loads nested details with copy/link and empty text, discarding stale responses", async () => {
const h = setup();
const calls = [];
h.app.authSessionState.accessToken = "crm-token";
h.app.authTokenRelay.requestTokenRelay = async () => "fresh-crm-token";
h.app.debugContentView.renderDebugPanel = () => {};
h.app.platformContentMessages.sendRuntimeMessage = message => new Promise(resolve => calls.push({ message, resolve }));
await h.app.opportunityCrmServiceRequests.load("synthetic", 1);
const badge = h.app.opportunityCrmServiceRequests.createBadge("OP1");
h.modal.append(badge);
badge.listeners.pointerenter();
await flush();
assert.equal(calls.length, 2);
assert.equal(calls[0].message.token, undefined);
assert.equal(calls[0].message.srId, "NOT-THE-URL-ID");
assert.ok(h.walk(h.panel()).some(node => node.textContent === "Loading SR details..."));
calls[0].resolve({ ok: true, items: [{ SrId: 99, SrNumber: "SR &child", Title: "<child>", ServiceNew_c: "Queue" }] });
calls[1].resolve({ ok: true, items: [] });
await flush();
const nodes = h.walk(h.panel());
const link = nodes.find(node => node.tag === "a" && node.textContent === "SR &child");
assert.equal(link.parent.children[0].textContent, "Internal SR Number:");
assert.ok(link.href.endsWith("srNumber=SR%20%26child&srId=99"));
assert.equal(link.parent.children[2].title, "Copy SR number");
assert.ok(nodes.some(node => node.textContent.includes("Service Queue: Queue")));
assert.ok(nodes.some(node => node.textContent === "No further details."));
h.app.crmSrPopover?.close();
h.app.opportunityCrmServiceRequests.reset();
badge.listeners.pointerenter();
const oldPanel = h.panel();
await flush();
h.app.opportunityCrmServiceRequests.reset();
calls[2].resolve({ ok: true, items: [{ SrNumber: "STALE" }] });
calls[3].resolve({ ok: false, error: "Forbidden" });
await flush();
assert.equal(h.panel(), undefined);
assert.ok(!h.walk(oldPanel).some(node => node.textContent === "STALE"));
});