function assertBasicProperties(card, expectedValues) {
info(`Testing card with ID: ${card.id}`);
ok(card, "The card element should exist");
is(card.localName, "moz-card", "The card should have the correct tag");
let l10nId = card.getAttribute("data-l10n-id");
let l10nAttrs = card.getAttribute("data-l10n-attrs");
if (expectedValues["data-l10n-id"]) {
is(l10nId, expectedValues["data-l10n-id"], "l10n id should be unchanged");
}
if (expectedValues["data-l10n-attrs"]) {
is(l10nAttrs, expectedValues["data-l10n-attrs"], "l10n attrs should be unchanged");
}
let cardContent = card.firstElementChild;
ok(cardContent, "The content should exist");
is(cardContent.textContent, expectedValues.contentText, "The content should be unchanged");
is(card.contentSlotEl.id, "content", "The content container should have the correct ID");
if (card.type != "accordion") {
is(card.contentSlotEl.getAttribute("aria-describedby"), "content", "The content container should be described by the 'content' slot");
}
if (expectedValues.headingText) {
ok(card.headingEl, "Heading should exist");
is(card.headingEl.textContent, expectedValues.headingText, "Heading should match the 'heading' attribute value");
}
}
async function assertAccordionCardProperties(card) {
ok(card.detailsEl, "The details element should exist");
ok(card.detailsEl.querySelector("summary"), "There should be a summary element within the details element");
ok(card.detailsEl.querySelector("summary").querySelector(".chevron-icon"), "There should be a chevron icon div within the summary element");
let cardToggled = BrowserTestUtils.waitForEvent(card, "toggle");
card.detailsEl.querySelector("summary").click();
let openEvent = await cardToggled;
is(openEvent.newState, "open", "Event shows new state is open");
is(openEvent.oldState, "closed", "Event shows old state is closed");
ok(card.detailsEl.open, "When the accordion is closed, it should expand when clicked");
cardToggled = BrowserTestUtils.waitForEvent(card, "toggle");
card.detailsEl.querySelector("summary").click();
let closeEvent = await cardToggled;
is(closeEvent.newState, "closed", "Event shows new state is closed");
is(closeEvent.oldState, "open", "Event shows old state is open");
ok(!card.detailsEl.open, "When the accordion is open, it should collapse when clicked");
}
function assertHeadingIconCardProperties(card) {
ok(card.shadowRoot.querySelector("#heading-wrapper").querySelector("#heading-icon"), "The heading icon element should exist");
}
async function generateCard(values) {
let card = document.createElement("moz-card");
for (let [key, value] of Object.entries(values)) {
card.setAttribute(key, value);
}
let div = document.createElement("div"); div.innerText = generatedSlotText;
card.appendChild(div);
document.body.appendChild(card);
await card.updateComplete;
document.body.appendChild(document.createElement("hr"));
return card;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.