@panoramax/web-viewer
Version:
Panoramax web viewer for geolocated pictures
53 lines (43 loc) • 1.42 kB
JavaScript
import CopyButton from "../../../src/components/ui/CopyButton";
window.navigator.clipboard = { writeText: jest.fn() };
describe("constructor", () => {
it("listens to click", () => {
const cb = new CopyButton();
expect(cb._handlers).toMatchSnapshot();
});
});
describe("_onClick", () => {
it("works with text", () => {
const cb = new CopyButton();
cb.text = "I am a copy text";
cb._onClick();
expect(cb._active).toBe(true);
expect(global.navigator.clipboard.writeText.mock.calls).toMatchSnapshot();
return new Promise(resolve => setTimeout(() => {
expect(cb._active).toBe(false);
resolve();
}, 2000));
});
it("works with input", () => {
const i = document.createElement("input");
i.value = "copy me from input";
i.id = "input-to-copy";
document.body.appendChild(i);
const cb = new CopyButton();
cb.input = "input-to-copy";
cb._onClick();
expect(cb._active).toBe(true);
expect(global.navigator.clipboard.writeText.mock.calls).toMatchSnapshot();
});
it("works with textarea", () => {
const i = document.createElement("textarea");
i.appendChild(document.createTextNode("copy me from textarea"));
i.id = "textarea-to-copy";
document.body.appendChild(i);
const cb = new CopyButton();
cb.input = "textarea-to-copy";
cb._onClick();
expect(cb._active).toBe(true);
expect(global.navigator.clipboard.writeText.mock.calls).toMatchSnapshot();
});
});