Skip to content

Commit 37eb56a

Browse files
maurercwadrianfish
andauthored
SAK-50206 Rubrics update all nested components after a rubric title change (#12837)
Co-authored-by: Adrian Fish <[email protected]>
1 parent 51ba177 commit 37eb56a

File tree

3 files changed

+100
-5
lines changed

3 files changed

+100
-5
lines changed

webcomponents/tool/src/main/frontend/packages/sakai-rubrics/src/SakaiRubric.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export class SakaiRubric extends RubricsElement {
257257
if (r.ok) {
258258
this.rubric.title = e.detail;
259259
this.requestUpdate();
260-
this.updateItemDelete();
260+
this.updateOtherItems();
261261
this.dispatchEvent(new SharingChangeEvent());
262262
} else {
263263
throw new Error("Network error while updating rubric title");
@@ -462,13 +462,18 @@ export class SakaiRubric extends RubricsElement {
462462
this.shareValues = this.rubric.title;
463463
}
464464

465-
updateItemDelete() {
465+
updateOtherItems() {
466466

467467
const sakaiItemDelete = this.querySelector("sakai-item-delete");
468468
if (sakaiItemDelete) {
469-
sakaiItemDelete.requestUpdate("item", this.rubric);
470-
sakaiItemDelete.requestUpdate("rubric", this.rubric);
469+
sakaiItemDelete.requestUpdate();
471470
}
471+
472+
const sakaiRubricEdit = this.querySelector("sakai-rubric-edit");
473+
sakaiRubricEdit && sakaiRubricEdit.requestUpdate();
474+
475+
const sakaiRubricPdf = this.querySelector("sakai-rubric-pdf");
476+
sakaiRubricPdf && sakaiRubricPdf.requestUpdate();
472477
}
473478

474479
openEditWithKeyboard(e) {

webcomponents/tool/src/main/frontend/packages/sakai-rubrics/test/data.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,25 @@ export const rubric2 = {
232232
criteria: criteria2,
233233
};
234234

235+
export const rubric3 = {
236+
id: "3",
237+
title: "Rubric 3",
238+
ownerId,
239+
siteTitle,
240+
creatorDisplayName,
241+
formattedModifiedDate,
242+
criteria: criteria1,
243+
locked: true
244+
};
245+
235246
export const evaluatedItemOwnerId = "fisha";
236247

237248
export const rubricsUrl = /api\/sites\/xyz\/rubrics[\?\w=]*$/;
238249
export const rubrics = [ rubric1, rubric2 ];
239250

240251
export const rubric1Url = `/api/sites/${siteId}/rubrics/${rubric1.id}`;
252+
export const rubric1OwnerUrl = `/api/sites/${ownerId}/rubrics/${rubric1.id}`;
253+
export const rubric3OwnerUrl = `/api/sites/${ownerId}/rubrics/${rubric3.id}`;
241254

242255
export const associationUrl = `/api/sites/${siteId}/rubric-associations/tools/${toolId}/items/${entityId}`;
243256

webcomponents/tool/src/main/frontend/packages/sakai-rubrics/test/sakai-rubrics.test.js

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ fetchMock
1818
.get(data.sharedRubricsUrl, data.sharedRubrics, { overwriteRoutes: true })
1919
.get(data.rubricsUrl, data.rubrics, { overwriteRoutes: true })
2020
.get(data.rubric1Url, data.rubric1, { overwriteRoutes: true })
21+
.patch(data.rubric1OwnerUrl, 200, { overwriteRoutes: true })
22+
.patch(data.rubric3OwnerUrl, 200, { overwriteRoutes: true })
2123
.get(data.associationUrl, data.association, { overwriteRoutes: true })
2224
.get(data.evaluationUrl, data.evaluation, { overwriteRoutes: true })
2325
.post(`/api/sites/${data.siteId}/rubric-evaluations`, (url, opts) => {
@@ -241,7 +243,7 @@ describe("sakai-rubrics tests", () => {
241243
expect(modal).to.exist;
242244
});
243245

244-
it ("rubric edit does not keep data changes in the modal after cancel", async () => {
246+
it ("rubric edit does not keep data changes in the modal after cancel", async () => {
245247

246248
let el = await fixture(html`
247249
<sakai-rubric-edit
@@ -372,4 +374,79 @@ it ("rubric edit does not keep data changes in the modal after cancel", async ()
372374

373375
expect(el).to.be.accessible();
374376
});
377+
378+
it ("updating rubric title updates the UI in all appropriate places for an unlocked rubric", async () => {
379+
await checkRubricTitleChanges(data.rubric1);
380+
});
381+
382+
it ("updating rubric title updates the UI in all appropriate places for a locked rubric", async () => {
383+
await checkRubricTitleChanges(data.rubric3);
384+
});
385+
386+
/**
387+
* Perform a title update and make sure all places are changed
388+
**/
389+
async function checkRubricTitleChanges(rubricData) {
390+
let el = await fixture(html`
391+
<sakai-rubric site-id="${data.siteId}"
392+
.rubric=${rubricData}
393+
enable-pdf-export=true>
394+
</sakai-rubric>
395+
`);
396+
397+
await waitUntil(() => el._i18n);
398+
await el.updateComplete;
399+
400+
// Validate that current data is the original title
401+
validateRubricTitle(rubricData, el, rubricData.title);
402+
403+
const newTitle = 'UPDATED TITLE';
404+
const editElement = el.querySelector(`#rubric-edit-${rubricData.id}`);
405+
406+
// Call update-rubric-title event
407+
editElement.dispatchEvent(new CustomEvent("update-rubric-title", { detail: newTitle }));
408+
409+
410+
await elementUpdated(editElement);
411+
await elementUpdated(el);
412+
413+
// Validate that current data is the updated title
414+
validateRubricTitle(rubricData, el, newTitle);
415+
416+
}
417+
418+
/**
419+
* Look for all places in the dom that should render any sort of rubric title
420+
**/
421+
function validateRubricTitle(rubricData, el, titleToCheck) {
422+
console.log(`Validating for '${titleToCheck}'`);
423+
424+
expect(el.querySelector(".rubric-name").textContent).to.equal(titleToCheck);
425+
expect(el.querySelector(`#rubric-toggle-${rubricData.id}`).title).to.equal(`${el._i18n.toggle_details} ${titleToCheck}`);
426+
427+
if (rubricData.locked) {
428+
console.log("Checking locked elements...");
429+
elementChecks(el, "span.locked", titleToCheck);
430+
}
431+
432+
elementChecks(el, "button.share", titleToCheck);
433+
elementChecks(el, "button.clone", titleToCheck);
434+
elementChecks(el, "button.edit-button", titleToCheck);
435+
elementChecks(el, "a.pdf", titleToCheck);
436+
437+
if (!rubricData.locked) {
438+
console.log("Checking delete elements...");
439+
elementChecks(el, `button[aria-controls="delete-rubric-${rubricData.id}"]`, titleToCheck);
440+
}
441+
}
442+
443+
/**
444+
* Check that the element exists, the title matches, and the ariaLabel matches
445+
**/
446+
function elementChecks(el, elementSelector, titleToCheck) {
447+
expect(el.querySelector(elementSelector)).to.exist;
448+
expect(el.querySelector(elementSelector).title).to.contain(titleToCheck);
449+
expect(el.querySelector(elementSelector).ariaLabel).to.contain(titleToCheck);
450+
}
451+
375452
});

0 commit comments

Comments
 (0)