Loading comcipapic to establish a session for SR requests
This commit is contained in:
@@ -35,6 +35,89 @@ function setup() {
|
||||
return { app, host, document, nodes, form };
|
||||
}
|
||||
|
||||
test("missing SR plus opens pillar form, handles retry, ignores closed requests and respects roles", async () => {
|
||||
const h = setup();
|
||||
h.app.opportunitiesTableState.opportunitiesTableState.items = [
|
||||
{ OptyNumber: "A", Name: "<Opportunity A>", CustomerAccount: { PartyUniqueName: "Customer A" }, EffectiveDate: "2026-11-30" }
|
||||
];
|
||||
h.app.opportunitiesQueryState.periodRequestVersion = 1;
|
||||
h.app.fusionCrmServiceRequests.requestCrmServiceRequest = async () => [{ SrNumber: "SR1", OpportunityName_Id_c: { OptyNumber: "B" } }];
|
||||
h.app.debugContentView.renderDebugPanel = () => {};
|
||||
await h.app.opportunityCrmServiceRequests.load("test", 1);
|
||||
const calls = [];
|
||||
const extraCalls = [];
|
||||
h.app.currentUser.getUserId = () => "user@example.invalid";
|
||||
h.app.platformContentMessages.sendRuntimeMessage = message => {
|
||||
if (message.type.endsWith("requestSrLookupPrimaryPillar")) return new Promise(resolve => calls.push({ message, resolve }));
|
||||
extraCalls.push(message);
|
||||
return Promise.resolve({ ok: true, items: message.type.endsWith("requestSrLookupOpportunityBusiness")
|
||||
? [{ Id: "123", RecordName: "Service", Abstract_c: "<Description>" }]
|
||||
: [{ code: "CODE", name: "Label" }] });
|
||||
};
|
||||
const badge = h.app.opportunityCrmServiceRequests.createBadge("A");
|
||||
const plus = badge.children.find(node => node.tag === "button");
|
||||
assert.ok(plus);
|
||||
assert.equal(plus.textContent, "+");
|
||||
assert.ok(!h.app.opportunityCrmServiceRequests.createBadge("B").children.some(node => node.className === "opportunities-extension-add-action"));
|
||||
plus.click();
|
||||
assert.deepEqual(h.nodes().filter(node => node.tag === "dt").map(node => node.textContent), ["Customer", "Name", "Close Date"]);
|
||||
assert.deepEqual(h.nodes().filter(node => node.tag === "dd").map(node => node.textContent), ["Customer A", "<Opportunity A>", "30/11/2026"]);
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0].message.type, "opportunitiesExtension.requestSrLookupPrimaryPillar");
|
||||
const field = () => h.nodes().find(node => node.name === "primaryPillar");
|
||||
assert.equal(field().disabled, true);
|
||||
calls[0].resolve({ ok: false, error: "Unauthorized" });
|
||||
await flush();
|
||||
assert.equal(h.form().attributes["data-state"], "error");
|
||||
assert.equal(extraCalls.length, 3);
|
||||
assert.equal(extraCalls.find(call => call.type.endsWith("requestSrLookupOpportunityBusiness")).emailAddress, "user@example.invalid");
|
||||
assert.equal(h.nodes().find(node => node.name === "customerDeadline").type, "date");
|
||||
assert.equal(h.nodes().find(node => node.name === "description").tag, "textarea");
|
||||
assert.equal(h.nodes().find(node => node.name === "language").children[1].value, "CODE");
|
||||
assert.equal(h.nodes().find(node => node.name === "platform").children[1].textContent, "Label");
|
||||
assert.equal(h.nodes().find(node => node.name === "service").value, "123");
|
||||
assert.equal(h.nodes().find(node => node.name === "service").type, "radio");
|
||||
assert.ok(h.nodes().some(node => node.textContent === "<Description>"));
|
||||
h.nodes().find(node => node.textContent === "Retry" && !node.hidden).click();
|
||||
calls[1].resolve({ ok: true, items: [{ code: "SaaS_HCM", name: "SaaS - HCM" }] });
|
||||
await flush();
|
||||
assert.equal(field().disabled, false);
|
||||
assert.equal(field().children[1].value, "SaaS_HCM");
|
||||
assert.equal(field().children[1].textContent, "SaaS - HCM");
|
||||
const search = h.nodes().find(node => node.id === `${field().id}-search`);
|
||||
assert.equal(field().hidden, true);
|
||||
assert.equal(search.disabled, false);
|
||||
search.value = "hcm";
|
||||
search.listeners.input();
|
||||
const options = h.nodes().find(node => node.id === search.attributes["aria-controls"]);
|
||||
assert.equal(options.children.length, 1);
|
||||
assert.equal(options.children[0].textContent, "SaaS - HCM");
|
||||
search.listeners.keydown({ key: "ArrowDown", preventDefault() {} });
|
||||
search.listeners.keydown({ key: "Enter", preventDefault() {} });
|
||||
assert.equal(field().value, "SaaS_HCM");
|
||||
assert.equal(search.value, "SaaS - HCM");
|
||||
assert.equal(options.hidden, true);
|
||||
search.value = "does not exist";
|
||||
search.listeners.input();
|
||||
assert.equal(options.textContent, "No results");
|
||||
search.listeners.keydown({ key: "Escape", preventDefault() {}, stopPropagation() {} });
|
||||
assert.equal(search.value, "SaaS - HCM");
|
||||
assert.ok(h.form(), "Escape closes only the options");
|
||||
assert.equal(calls.length, 2, "searching does not issue another request");
|
||||
h.nodes().find(node => node.textContent === "Cancel").click();
|
||||
assert.equal(h.host.children.length, 0);
|
||||
h.app.opportunitiesTableState.opportunitiesTableState.items = [];
|
||||
plus.click();
|
||||
assert.deepEqual(h.nodes().filter(node => node.tag === "dd").map(node => node.textContent), ["-", "-", "-"]);
|
||||
h.app.opportunityCrmServiceRequests.reset();
|
||||
calls[2].resolve({ ok: true, items: [] });
|
||||
await flush();
|
||||
assert.equal(h.host.children.length, 0);
|
||||
h.app.currentUser.allowsCrmActivities = () => false;
|
||||
plus.click();
|
||||
assert.equal(h.host.children.length, 0);
|
||||
});
|
||||
|
||||
test("only plus opens the nine-field form; a missing workload stays disabled without a save operation", () => {
|
||||
const h = setup();
|
||||
const badge = h.app.opportunityWorkloadActions.createBadge("A");
|
||||
|
||||
Reference in New Issue
Block a user