Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAK-50206 Rubrics update all nested components after a rubric title change #12837

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class SakaiRubric extends RubricsElement {
if (r.ok) {
this.rubric.title = e.detail;
this.requestUpdate();
this.updateItemDelete();
this.updateOtherItems();
this.dispatchEvent(new SharingChangeEvent());
} else {
throw new Error("Network error while updating rubric title");
Expand Down Expand Up @@ -462,12 +462,21 @@ export class SakaiRubric extends RubricsElement {
this.shareValues = this.rubric.title;
}

updateItemDelete() {
updateOtherItems() {

const sakaiItemDelete = this.querySelector("sakai-item-delete");
if (sakaiItemDelete) {
sakaiItemDelete.requestUpdate("item", this.rubric);
sakaiItemDelete.requestUpdate("rubric", this.rubric);
sakaiItemDelete.requestUpdate();
}

const sakaiRubricEdit = this.querySelector("sakai-rubric-edit");
if (sakaiRubricEdit) {
sakaiRubricEdit.requestUpdate();
}
adrianfish marked this conversation as resolved.
Show resolved Hide resolved

const sakaiRubricPdf = this.querySelector("sakai-rubric-pdf");
if (sakaiRubricPdf) {
sakaiRubricPdf.requestUpdate();
}
adrianfish marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,25 @@ export const rubric2 = {
criteria: criteria2,
};

export const rubric3 = {
id: "3",
title: "Rubric 3",
ownerId,
siteTitle,
creatorDisplayName,
formattedModifiedDate,
criteria: criteria1,
locked: true
};

export const evaluatedItemOwnerId = "fisha";

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ fetchMock
.get(data.sharedRubricsUrl, data.sharedRubrics, { overwriteRoutes: true })
.get(data.rubricsUrl, data.rubrics, { overwriteRoutes: true })
.get(data.rubric1Url, data.rubric1, { overwriteRoutes: true })
.patch(data.rubric1OwnerUrl, 200, { overwriteRoutes: true })
.patch(data.rubric3OwnerUrl, 200, { overwriteRoutes: true })
.get(data.associationUrl, data.association, { overwriteRoutes: true })
.get(data.evaluationUrl, data.evaluation, { overwriteRoutes: true })
.post(`/api/sites/${data.siteId}/rubric-evaluations`, (url, opts) => {
Expand Down Expand Up @@ -241,7 +243,7 @@ describe("sakai-rubrics tests", () => {
expect(modal).to.exist;
});

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

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

expect(el).to.be.accessible();
});

it ("updating rubric title updates the UI in all appropriate places for an unlocked rubric", async () => {
await checkRubricTitleChanges(data.rubric1);
});

it ("updating rubric title updates the UI in all appropriate places for a locked rubric", async () => {
await checkRubricTitleChanges(data.rubric3);
});

/**
* Perform a title update and make sure all places are changed
**/
async function checkRubricTitleChanges(rubricData) {
let el = await fixture(html`
<sakai-rubric site-id="${data.siteId}"
.rubric=${rubricData}
enable-pdf-export=true>
</sakai-rubric>
`);

await waitUntil(() => el._i18n);
await el.updateComplete;

// Validate that current data is the original title
validateRubricTitle(rubricData, el, rubricData.title);

const newTitle = 'UPDATED TITLE';
const editElement = el.querySelector(`#rubric-edit-${rubricData.id}`);

// Call update-rubric-title event
editElement.dispatchEvent(new CustomEvent("update-rubric-title", { detail: newTitle }));


await elementUpdated(editElement);
await elementUpdated(el);

// Validate that current data is the updated title
validateRubricTitle(rubricData, el, newTitle);

}

/**
* Look for all places in the dom that should render any sort of rubric title
**/
function validateRubricTitle(rubricData, el, titleToCheck) {
console.log(`Validating for '${titleToCheck}'`);

expect(el.querySelector(".rubric-name").textContent).to.equal(titleToCheck);
expect(el.querySelector(`#rubric-toggle-${rubricData.id}`).title).to.equal(`${el._i18n.toggle_details} ${titleToCheck}`);

if (rubricData.locked) {
console.log("Checking locked elements...");
elementChecks(el, "span.locked", titleToCheck);
}

elementChecks(el, "button.share", titleToCheck);
elementChecks(el, "button.clone", titleToCheck);
elementChecks(el, "button.edit-button", titleToCheck);
elementChecks(el, "a.pdf", titleToCheck);

if (!rubricData.locked) {
console.log("Checking delete elements...");
elementChecks(el, `button[aria-controls="delete-rubric-${rubricData.id}"]`, titleToCheck);
}
}

/**
* Check that the element exists, the title matches, and the ariaLabel matches
**/
function elementChecks(el, elementSelector, titleToCheck) {
expect(el.querySelector(elementSelector)).to.exist;
expect(el.querySelector(elementSelector).title).to.contain(titleToCheck);
expect(el.querySelector(elementSelector).ariaLabel).to.contain(titleToCheck);
}

});
Loading