@salla.sa/twilight-components
Version:
Salla Web Component
119 lines (118 loc) • 4.3 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { newSpecPage } from "@stencil/core/testing";
import { SallaAddProductButton } from "../salla-add-product-button";
describe("salla add product button", () => {
it('should build', () => {
expect(new SallaAddProductButton()).toBeTruthy();
});
describe("checking for prop values", () => {
let page;
let element;
beforeEach(async () => {
page = await newSpecPage({
components: [SallaAddProductButton],
html: '<salla-add-product-button></salla-add-product-button>'
});
element = await page.doc.querySelector('salla-add-product-button');
});
it('should work for channels prop', async () => {
element.channels = 'channelOne';
await page.waitForChanges();
expect(element.channels).toBe('channelOne');
});
it('should work for quantity prop', async () => {
element.quantity = 123;
await page.waitForChanges();
expect(element.quantity).toBe(123);
});
it('should work for productId prop', async () => {
element.productId = 123;
await page.waitForChanges();
expect(element.productId).toBe(123);
});
it('should work for donatingAmount prop', async () => {
element.donatingAmount = 123;
await page.waitForChanges();
expect(element.donatingAmount).toBe(123);
});
it('should work for product-status prop', async () => {
// element.productStatus = 'out-and-notify';
// await page.waitForChanges();
expect(element.productStatus).toBe("sale");
});
it('should work for product-type prop', async () => {
// element.productType = 'service';
// await page.waitForChanges();
expect(element.productType).toBe('product');
});
});
describe("checking for prop values", () => {
let page;
let element;
beforeEach(async () => {
page = await newSpecPage({
components: [SallaAddProductButton],
html: `<salla-add-product-button product-status="out" product-type="donating"></salla-add-product-button>`
});
element = await page.doc.querySelector('salla-add-product-button');
});
it('should work for product-type prop', async () => {
expect(element.productType).toBe('donating');
});
it('should work for product-type prop', async () => {
element.productType = 'service';
await page.waitForChanges();
expect(element.productType).toBe('service');
});
});
describe("checking method calls", () => {
let page;
let element;
beforeEach(async () => {
page = await newSpecPage({
components: [SallaAddProductButton],
html: `<salla-add-product-button></salla-add-product-button>`
});
element = await page.doc.querySelector('salla-add-product-button');
});
it('should emit `failed` event when addProductToCart method call on salla-button click', async () => {
const _callback = jest.fn();
salla.event.on('failed', _callback);
await page.waitForChanges();
element.quantity = -1;
element.productId = 23;
await page.waitForChanges();
const btn = page.root.querySelector('salla-button');
btn.click();
expect(_callback).toHaveBeenCalled();
});
it('should emit `success` event when addProductToCart method call on salla-button click', async () => {
const _callback = jest.fn();
salla.event.on("success", _callback);
element.quantity = 2;
element.productId = 23;
element.donatingAmount = 3;
await page.waitForChanges();
const btn = page.doc.querySelector('salla-button');
btn.click();
expect(_callback).toHaveBeenCalled();
});
});
describe("checking method calls on `submit` button type", () => {
it('should not emit any event', async () => {
const page = await newSpecPage({
components: [SallaAddProductButton],
html: `<salla-add-product-button type="submit"></salla-add-product-button>`
});
const cb = jest.fn();
salla.event.on('success', cb);
await page.waitForChanges();
const btn = page.root.querySelector('salla-button');
btn.click();
expect(cb).not.toHaveBeenCalled();
});
});
});
//# sourceMappingURL=salla-add-product-button.spec.js.map