@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
73 lines (72 loc) • 4.78 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { ESLCarousel } from '../../../core/esl-carousel';
import { ESLCarouselTouchMixin } from '../../../plugin/touch/esl-carousel.touch.mixin';
import { ESLCarouselDummyRenderer } from '../../common/esl-carousel.dummy.renderer';
describe('ESLCarousel: Touch Plugin', () => {
ESLCarousel.register();
ESLCarouselTouchMixin.register();
ESLCarouselDummyRenderer.register();
describe('ESLCarouselTouchMixin initialization', () => {
const $carousel = ESLCarousel.create();
beforeEach(() => document.body.appendChild($carousel));
afterEach(() => document.body.removeChild($carousel));
test('Plugin attached to carousel correctly', () => __awaiter(void 0, void 0, void 0, function* () {
$carousel.setAttribute('esl-carousel-touch', '');
yield Promise.resolve();
expect(ESLCarouselTouchMixin.get($carousel)).not.toBeFalsy();
}));
test('Plugin attaches with drug action by default', () => __awaiter(void 0, void 0, void 0, function* () {
$carousel.setAttribute('esl-carousel-touch', '');
yield Promise.resolve();
const plugin = ESLCarouselTouchMixin.get($carousel);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isDragMode).toBe(true);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isSwipeMode).toBe(false);
}));
test('Plugin attaches with swipe action', () => __awaiter(void 0, void 0, void 0, function* () {
$carousel.setAttribute('esl-carousel-touch', 'swipe');
yield Promise.resolve();
const plugin = ESLCarouselTouchMixin.get($carousel);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isDragMode).toBe(false);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isSwipeMode).toBe(true);
}));
test('Plugin attaches with drag action', () => __awaiter(void 0, void 0, void 0, function* () {
$carousel.setAttribute('esl-carousel-touch', 'drag');
yield Promise.resolve();
const plugin = ESLCarouselTouchMixin.get($carousel);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isDragMode).toBe(true);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isSwipeMode).toBe(false);
}));
test('Plugin could be attached with none action', () => __awaiter(void 0, void 0, void 0, function* () {
$carousel.setAttribute('esl-carousel-touch', 'none');
yield Promise.resolve();
const plugin = ESLCarouselTouchMixin.get($carousel);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isDragMode).toBe(false);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isSwipeMode).toBe(false);
}));
test('Plugin attaches with multiple actions', () => __awaiter(void 0, void 0, void 0, function* () {
$carousel.setAttribute('esl-carousel-touch', 'none | @XS => swipe | @+SM => drag');
yield Promise.resolve();
const plugin = ESLCarouselTouchMixin.get($carousel);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isDragMode).toBe(false);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isSwipeMode).toBe(false);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.configQuery.rules.length).toBe(3);
}));
test('Plugin touch action observed to handle changes', () => __awaiter(void 0, void 0, void 0, function* () {
$carousel.setAttribute('esl-carousel-touch', '');
yield Promise.resolve();
const plugin = ESLCarouselTouchMixin.get($carousel);
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isDragMode).toBe(true);
$carousel.setAttribute('esl-carousel-touch', 'swipe');
yield Promise.resolve();
expect(plugin === null || plugin === void 0 ? void 0 : plugin.isSwipeMode).toBe(true);
}));
});
});