/**
* @jest-environment jsdom
*/
import AbstractHint, {
LinkHint,
InputHint,
} from "../../../src/content/presenters/Hint";
class Hint extends AbstractHint {}
describe("Hint", () => {
beforeEach(() => {
document.body.innerHTML = `link`;
});
describe("#constructor", () => {
it("creates a hint element with tag name", () => {
const link = document.getElementById("test-link")!;
new Hint(link, "abc");
const elem = document.querySelector(".vimvixen-hint");
expect(elem!.textContent!.trim()).toEqual("abc");
});
});
describe("#show", () => {
it("shows an element", () => {
const link = document.getElementById("test-link")!;
const hint = new Hint(link, "abc");
hint.hide();
hint.show();
const elem = document.querySelector(".vimvixen-hint") as HTMLElement;
expect(elem.style.display).not.toEqual("none");
});
});
describe("#hide", () => {
it("hides an element", () => {
const link = document.getElementById("test-link") as HTMLElement;
const hint = new Hint(link, "abc");
hint.hide();
const elem = document.querySelector(".vimvixen-hint") as HTMLElement;
expect(elem.style.display).toEqual("none");
});
});
describe("#remove", () => {
it("removes an element", () => {
const link = document.getElementById("test-link")!;
const hint = new Hint(link, "abc");
const elem = document.querySelector(".vimvixen-hint")!;
expect(elem.parentElement).not.toBeNull;
hint.remove();
expect(elem.parentElement).toBeNull;
});
});
});
describe("LinkHint", () => {
beforeEach(() => {
document.body.innerHTML = `
link
link
link
`;
});
describe("#getLink()", () => {
it('returns value of "href" attribute', () => {
const link = document.getElementById("test-link1") as HTMLAnchorElement;
const hint = new LinkHint(link, "abc");
expect(hint.getLink()).toEqual("https://google.com/");
});
});
describe("#getLinkTarget()", () => {
it('returns value of "target" attribute', () => {
let link = document.getElementById("test-link1") as HTMLAnchorElement;
let hint = new LinkHint(link, "abc");
expect(hint.getLinkTarget()).toBeNull;
link = document.getElementById("test-link2") as HTMLAnchorElement;
hint = new LinkHint(link, "abc");
expect(hint.getLinkTarget()).toEqual("_blank");
});
});
describe("#click()", () => {
it("clicks a element", (done) => {
const link = document.getElementById("test-link3") as HTMLAnchorElement;
const hint = new LinkHint(link, "abc");
link.onclick = () => {
done();
};
hint.click();
});
});
});
describe("InputHint", () => {
describe("#activate()", () => {
describe("", () => {
beforeEach(() => {
document.body.innerHTML = ``;
});
it("focuses to the input", () => {
const input = document.getElementById("test-input") as HTMLInputElement;
const hint = new InputHint(input, "abc");
hint.activate();
expect(document.activeElement).toEqual(input);
});
});
describe('', () => {
beforeEach(() => {
document.body.innerHTML = ``;
});
it("checks and focuses to the input", () => {
const input = document.getElementById("test-input") as HTMLInputElement;
const hint = new InputHint(input, "abc");
hint.activate();
expect(input.checked).toBeTruthy;
});
});
describe("