Revision control
Copy as Markdown
Other Tools
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
"use strict";
const tabmail = document.getElementById("tabmail");
let browser, container;
add_setup(async function () {
const tab = tabmail.openTab("contentTab", {
});
await BrowserTestUtils.browserLoaded(tab.browser, undefined, url =>
url.endsWith("inAppNotificationContainer.xhtml")
);
tab.browser.focus();
browser = tab.browser;
container = browser.contentWindow.document.querySelector(
`in-app-notification-container`
);
registerCleanupFunction(() => {
tabmail.closeOtherTabs(tabmail.tabInfo[0]);
});
});
function subtestTextValue(property) {
const element = container.shadowRoot.querySelector(
`.in-app-notification-${property}`
);
Assert.equal(element.textContent, "", `${property} has no value`);
container.setAttribute(property, "test text");
Assert.equal(
element.textContent,
"test text",
`${property} has correct value`
);
container.setAttribute(property, "new text");
Assert.equal(
element.textContent,
"new text",
`${property} updates correctly`
);
container.removeAttribute(property);
Assert.equal(element.textContent, "", `${property} is correctly removed`);
}
add_task(function test_ctaValue() {
subtestTextValue("cta");
});
add_task(function test_descriptionValue() {
subtestTextValue("description");
});
add_task(function test_headingValue() {
subtestTextValue("heading");
});
add_task(function test_dataIdValue() {
const element = container.shadowRoot.querySelector("a");
Assert.equal(element.href, "", "url is null");
container.dataset.id = "notification-1";
Assert.equal(element.dataset.id, "notification-1", "id is set");
container.dataset.id = "notification-2";
Assert.equal(element.dataset.id, "notification-2", "id is updated");
delete container.dataset.id;
Assert.equal(element.dataset.id, "null", "id is cleared");
});
add_task(async function test_urlValue() {
const element = container.shadowRoot.querySelector("a");
Assert.equal(element.href, "", "url is null");
Assert.equal(
element.href,
"url is updated"
);
container.removeAttribute("url");
Assert.equal(element.href, "", "url is cleared");
});
add_task(async function test_type() {
const element = container.shadowRoot.querySelector(
".in-app-notification-container"
);
container.setAttribute("type", "blog");
Assert.ok(
element.classList.contains("in-app-notification-blog"),
"has correct class for type"
);
container.setAttribute("type", "donation");
Assert.ok(
element.classList.contains("in-app-notification-donation"),
"has correct class for type"
);
});