@salla.sa/twilight-components
Version:
Salla Web Component
74 lines (73 loc) • 2.75 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { newSpecPage } from "@stencil/core/testing";
import { SallaGifting } from "../salla-gifting";
describe('salla-gifting', () => {
it("should build", () => {
expect(new SallaGifting()).toBeTruthy();
});
describe('rendering', () => {
let page;
beforeEach(async () => {
page = await newSpecPage({
components: [SallaGifting],
html: '<salla-gifting product-id="1153090815"></salla-gifting>'
});
});
it('should be able to render component', async () => {
await page.waitForChanges();
let component = page.doc.querySelector('salla-gifting');
expect(component.productId).toBe(1153090815);
});
});
describe("testing methods", () => {
let page;
beforeEach(async () => {
page = await newSpecPage({
components: [SallaGifting],
html: '<salla-gifting product-id="123"></salla-gifting>'
});
});
it("should redirect the guest user to login without opening gifting modal", async () => {
let gifting = await page.doc.querySelector('salla-gifting');
salla.config.isGuest = () => true;
const cb = jest.fn();
salla.event.on('login::open', () => cb());
await page.waitForChanges();
await gifting.open()
.then(() => {
expect(cb).toHaveBeenCalled();
});
});
it("should open the gifting dialog by calling a method", async () => {
salla.config.isGuest = () => false;
let gifting = await page.doc.querySelector('salla-gifting');
await gifting.open();
await page.waitForChanges();
let modal = page.doc.getElementsByClassName('s-gifting-modal-header');
expect(modal.length).toBeGreaterThan(0);
});
it("should call method to close the modal", async () => {
salla.config.isGuest = () => false;
let gifting = await page.doc.querySelector('salla-gifting');
await gifting.open();
await page.waitForChanges();
await gifting.close();
await page.waitForChanges();
let errorPlaceholder = await page.doc.querySelector('salla-modal');
expect(errorPlaceholder.style.display).toBe("none");
});
it("should set image to preview", async () => {
let giftingComponent = await page.doc.querySelector('salla-gifting');
await giftingComponent.open();
await page.waitForChanges();
let giftImageItem = await page.doc.querySelector("img");
giftImageItem.click();
await page.waitForChanges();
let imageBgElement = await page.doc.querySelector('.filepond-bg');
expect(imageBgElement.style.backgroundImage).toBe(`url("https://picsum.photos/350/165?random")`);
});
});
});
//# sourceMappingURL=salla-gifting.spec.js.map