lit-components-1
Version:
Inclusive UI elements library based on web components
68 lines (67 loc) • 3.41 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 { assert, expect, fixture, html } from '@open-wc/testing';
import { Card } from './card';
describe('Card Component', () => {
let el;
const card = {
altText: 'Je suis a image',
ctaText: 'Click me',
image: 'http://example.com/image/',
link: 'http://example.com/link/',
text: 'amazing text',
textDesc: 'other amazing text for test',
textDescLink: 'http://example.com/author/',
title: 'amazing title',
};
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
el = yield fixture(html ` <card-image .card=${card}></card-image> `);
}));
it('is defined', () => {
assert.instanceOf(el, Card);
});
it('it renders the image', () => {
var _a;
const image = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('img');
expect(image).to.exist;
expect(image === null || image === void 0 ? void 0 : image.alt).to.equal(card.altText);
expect(image === null || image === void 0 ? void 0 : image.src).to.equal(card.image);
});
it('it renders the title', () => {
var _a;
const title = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#card-link');
expect(title).to.exist;
expect(title === null || title === void 0 ? void 0 : title.getAttribute('href')).to.equal(card.link);
expect(title === null || title === void 0 ? void 0 : title.textContent).to.equal(card.title);
});
it('it renders the text', () => {
var _a;
const text = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('p');
expect(text).to.exist;
expect(text === null || text === void 0 ? void 0 : text.textContent).to.equal(card.text);
});
it('it renders the cta text', () => {
var _a;
const ctaText = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.cta a');
expect(ctaText).to.exist;
expect(ctaText === null || ctaText === void 0 ? void 0 : ctaText.textContent).to.equal(card.ctaText);
});
it('it renders the description link', () => {
var _a;
const textDesc = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('small a');
expect(textDesc).to.exist;
expect(textDesc === null || textDesc === void 0 ? void 0 : textDesc.getAttribute('href')).to.equal(card.textDescLink);
expect(textDesc === null || textDesc === void 0 ? void 0 : textDesc.textContent).to.equal(card.textDesc);
});
it('dispatch the mousedown event', () => {
el.mouseDown();
expect(el.down).to.be.a('number');
});
});