@ithaka/bonsai
Version:
ITHAKA core styling
56 lines (42 loc) • 2.12 kB
JavaScript
import { BonsaiSocialBase } from "../bonsai.socialbase";
class BonsaiTestSocial extends BonsaiSocialBase {
constructor(container, uuid) {
super(container, uuid);
this.platformName = "testbook";
this.accessibleText = "Share with Test";
this.buttonDataAttribute = "data-test-share";
this.iconClass = "icon-test";
this.buttonBackgroundColor = "test-blue-background";
this.shareUrl = `https://test.com/shareme?url=${this.getCurrentUrl()}`;
this.windowName = "Test";
}
}
beforeEach(() => {
document.body.innerHTML = `<div id="test"></div>`;
let bonsaiTestSocial = new BonsaiTestSocial("#test", "1502fe6a-4ffd-4ac1-8d5e-9dcbfc0c3945").addButton();
});
describe("Button added properly", () => {
test("button attributes are correct", () => {
const $testSharingButton = $("[data-test-share]");
expect($testSharingButton.length).toBe(1);
expect($testSharingButton.hasClass("test-blue-background")).toBe(true);
expect($testSharingButton.attr("aria-label")).toBe("Share with Test");
expect($testSharingButton.children("i").hasClass("icon-test")).toBe(true);
});
test("button click event works", () => {
global.open = jest.fn();
const expectedShareUrl = "https://test.com/shareme?url=http%3A%2F%2Fwww.jstor.org%2Fstyleguide%3Fsocuuid%3D1502fe6a-4ffd-4ac1-8d5e-9dcbfc0c3945%26socplat%3Dtestbook";
$("[data-test-share]").trigger("click");
expect(global.open).toBeCalledWith(expectedShareUrl, "Test", "width=500,height=300");
});
});
describe("Button event triggering", () => {
test("can listen for events", () => {
$("#test").on("bonsai-social-click", (event, dataAttribute, url, uuid) => {
expect(dataAttribute).toBe("data-test-share");
expect(url).toBe("http%3A%2F%2Fwww.jstor.org%2Fstyleguide%3Fsocuuid%3D1502fe6a-4ffd-4ac1-8d5e-9dcbfc0c3945%26socplat%3Dtestbook");
expect(uuid).toBe("1502fe6a-4ffd-4ac1-8d5e-9dcbfc0c3945");
});
$("[data-test-share]").trigger("click");
});
});