@salla.sa/twilight-components
Version:
Salla Web Component
96 lines (95 loc) • 4.17 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { newSpecPage } from "@stencil/core/testing";
import { SallaQuantityInput } from "../salla-quantity-input";
describe("salla quantity input", () => {
it("should build", () => {
expect(new SallaQuantityInput()).toBeTruthy();
});
describe("checking for method calls", () => {
let page;
let element;
beforeEach(async () => {
page = await newSpecPage({
components: [SallaQuantityInput],
html: '<salla-quantity-input max="6"></salla-quantity-input>'
});
element = await page.doc.querySelector('salla-quantity-input');
});
it("should have a default quantity of 1", async () => {
let inputField = await page.doc.getElementsByClassName('s-quantity-input-input');
const defaultQuantityValue = inputField[0].getAttribute('value');
expect(parseInt(defaultQuantityValue)).toBe(1);
});
it("should increase the quantity by 1", async () => {
await element.increase();
await page.waitForChanges();
let inputField = await page.doc.getElementsByClassName('s-quantity-input-input');
const defaultQuantityValue = inputField[0].getAttribute('value');
expect(parseInt(defaultQuantityValue)).toBe(2);
});
it("should set number value to quantity", async () => {
await element.setValue(5);
await page.waitForChanges();
let inputField = await page.doc.getElementsByClassName('s-quantity-input-input');
const defaultQuantityValue = inputField[0].getAttribute('value');
expect(parseInt(defaultQuantityValue)).toBe(5);
});
it("should decrease the quantity by 1", async () => {
await element.setValue(4);
await page.waitForChanges();
await element.decrease();
await page.waitForChanges();
const inputField = await page.doc.getElementsByClassName('s-quantity-input-input');
const defaultQuantityValue = inputField[0].getAttribute('value');
expect(parseInt(defaultQuantityValue)).toBe(3);
});
it("should set a value of 1 to quantity for values less than 1", async () => {
await element.setValue(0);
await page.waitForChanges();
let inputField = await page.doc.getElementsByClassName('s-quantity-input-input');
const defaultQuantityValue = inputField[0].getAttribute('value');
expect(parseInt(defaultQuantityValue)).toBe(1);
});
it("should set the maximum value if the value exceeds the threshold", async () => {
await element.setValue(8);
await page.waitForChanges();
let inputField = await page.doc.getElementsByClassName('s-quantity-input-input');
const defaultQuantityValue = inputField[0].getAttribute('value');
expect(parseInt(defaultQuantityValue)).toBe(6);
});
});
describe("checking for user activities", () => {
let page;
let element;
beforeEach(async () => {
page = await newSpecPage({
components: [SallaQuantityInput],
html: '<salla-quantity-input max="6"></salla-quantity-input>'
});
element = await page.doc.querySelector('salla-quantity-input');
});
it('should increase quantity using a button', async () => {
await element.setValue(2);
await page.waitForChanges();
const increaseButton = page.doc.querySelector('.s-quantity-input-increase-button');
increaseButton.click();
await page.waitForChanges();
const inputField = await page.doc.getElementsByClassName('s-quantity-input-input');
const quantityValue = inputField[0].getAttribute('value');
expect(parseInt(quantityValue)).toBe(3);
});
it('should decrease quantity using a button', async () => {
await element.setValue(2);
await page.waitForChanges();
const decreaseButton = page.doc.querySelector('.s-quantity-input-increase-button');
decreaseButton.click();
await page.waitForChanges();
const inputField = await page.doc.getElementsByClassName('s-quantity-input-input');
const quantityValue = inputField[0].getAttribute('value');
expect(parseInt(quantityValue)).toBe(3);
});
});
});
//# sourceMappingURL=salla-quantity-input.spec.js.map