update code style

This commit is contained in:
vitormalencar
2021-01-21 11:45:33 +01:00
parent d8a51544bd
commit 971834388c
16 changed files with 216 additions and 216 deletions

View File

@@ -1,63 +1,63 @@
import ClipboardAction from "../src/clipboard-action";
import Emitter from "tiny-emitter";
import ClipboardAction from '../src/clipboard-action';
import Emitter from 'tiny-emitter';
describe("ClipboardAction", () => {
describe('ClipboardAction', () => {
before(() => {
global.input = document.createElement("input");
global.input.setAttribute("id", "input");
global.input.setAttribute("value", "abc");
global.input = document.createElement('input');
global.input.setAttribute('id', 'input');
global.input.setAttribute('value', 'abc');
document.body.appendChild(global.input);
global.paragraph = document.createElement("p");
global.paragraph.setAttribute("id", "paragraph");
global.paragraph.textContent = "abc";
global.paragraph = document.createElement('p');
global.paragraph.setAttribute('id', 'paragraph');
global.paragraph.textContent = 'abc';
document.body.appendChild(global.paragraph);
});
after(() => {
document.body.innerHTML = "";
document.body.innerHTML = '';
});
describe("#resolveOptions", () => {
it("should set base properties", () => {
describe('#resolveOptions', () => {
it('should set base properties', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
text: "foo",
text: 'foo',
});
assert.property(clip, "action");
assert.property(clip, "container");
assert.property(clip, "emitter");
assert.property(clip, "target");
assert.property(clip, "text");
assert.property(clip, "trigger");
assert.property(clip, "selectedText");
assert.property(clip, 'action');
assert.property(clip, 'container');
assert.property(clip, 'emitter');
assert.property(clip, 'target');
assert.property(clip, 'text');
assert.property(clip, 'trigger');
assert.property(clip, 'selectedText');
});
});
describe("#initSelection", () => {
it("should set the position right style property", (done) => {
describe('#initSelection', () => {
it('should set the position right style property', (done) => {
// Set document direction
document.documentElement.setAttribute("dir", "rtl");
document.documentElement.setAttribute('dir', 'rtl');
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
text: "foo",
text: 'foo',
});
assert.equal(clip.fakeElem.style.right, "-9999px");
assert.equal(clip.fakeElem.style.right, '-9999px');
done();
});
});
describe("#set action", () => {
describe('#set action', () => {
it('should throw an error since "action" is invalid', (done) => {
try {
new ClipboardAction({
text: "foo",
action: "paste",
text: 'foo',
action: 'paste',
});
} catch (e) {
assert.equal(
@@ -69,11 +69,11 @@ describe("ClipboardAction", () => {
});
});
describe("#set target", () => {
describe('#set target', () => {
it('should throw an error since "target" do not match any element', (done) => {
try {
new ClipboardAction({
target: document.querySelector("#foo"),
target: document.querySelector('#foo'),
});
} catch (e) {
assert.equal(e.message, 'Invalid "target" value, use a valid Element');
@@ -82,24 +82,24 @@ describe("ClipboardAction", () => {
});
});
describe("#selectText", () => {
it("should create a fake element and select its value", () => {
describe('#selectText', () => {
it('should create a fake element and select its value', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
text: "blah",
text: 'blah',
});
assert.equal(clip.selectedText, clip.fakeElem.value);
});
});
describe("#removeFake", () => {
it("should remove a temporary fake element", () => {
describe('#removeFake', () => {
it('should remove a temporary fake element', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
text: "blah",
text: 'blah',
});
clip.removeFake();
@@ -108,81 +108,81 @@ describe("ClipboardAction", () => {
});
});
describe("#selectTarget", () => {
it("should select text from editable element", () => {
describe('#selectTarget', () => {
it('should select text from editable element', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
target: document.querySelector("#input"),
target: document.querySelector('#input'),
});
assert.equal(clip.selectedText, clip.target.value);
});
it("should select text from non-editable element", () => {
it('should select text from non-editable element', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
target: document.querySelector("#paragraph"),
target: document.querySelector('#paragraph'),
});
assert.equal(clip.selectedText, clip.target.textContent);
});
});
describe("#copyText", () => {
describe('#copyText', () => {
before(() => {
global.stub = sinon.stub(document, "execCommand");
global.stub = sinon.stub(document, 'execCommand');
});
after(() => {
global.stub.restore();
});
it("should fire a success event on browsers that support copy command", (done) => {
it('should fire a success event on browsers that support copy command', (done) => {
global.stub.returns(true);
let emitter = new Emitter();
emitter.on("success", () => {
emitter.on('success', () => {
done();
});
let clip = new ClipboardAction({
emitter,
target: document.querySelector("#input"),
target: document.querySelector('#input'),
});
});
it("should fire an error event on browsers that support copy command", (done) => {
it('should fire an error event on browsers that support copy command', (done) => {
global.stub.returns(false);
let emitter = new Emitter();
emitter.on("error", () => {
emitter.on('error', () => {
done();
});
let clip = new ClipboardAction({
emitter,
target: document.querySelector("#input"),
target: document.querySelector('#input'),
});
});
});
describe("#handleResult", () => {
it("should fire a success event with certain properties", (done) => {
describe('#handleResult', () => {
it('should fire a success event with certain properties', (done) => {
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
target: document.querySelector("#input"),
target: document.querySelector('#input'),
});
clip.emitter.on("success", (e) => {
assert.property(e, "action");
assert.property(e, "text");
assert.property(e, "trigger");
assert.property(e, "clearSelection");
clip.emitter.on('success', (e) => {
assert.property(e, 'action');
assert.property(e, 'text');
assert.property(e, 'trigger');
assert.property(e, 'clearSelection');
done();
});
@@ -190,17 +190,17 @@ describe("ClipboardAction", () => {
clip.handleResult(true);
});
it("should fire a error event with certain properties", (done) => {
it('should fire a error event with certain properties', (done) => {
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
target: document.querySelector("#input"),
target: document.querySelector('#input'),
});
clip.emitter.on("error", (e) => {
assert.property(e, "action");
assert.property(e, "trigger");
assert.property(e, "clearSelection");
clip.emitter.on('error', (e) => {
assert.property(e, 'action');
assert.property(e, 'trigger');
assert.property(e, 'clearSelection');
done();
});
@@ -209,12 +209,12 @@ describe("ClipboardAction", () => {
});
});
describe("#clearSelection", () => {
it("should remove focus from target and text selection", () => {
describe('#clearSelection', () => {
it('should remove focus from target and text selection', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
target: document.querySelector("#input"),
target: document.querySelector('#input'),
});
clip.clearSelection();
@@ -223,16 +223,16 @@ describe("ClipboardAction", () => {
let selectedText = window.getSelection().toString();
assert.equal(selectedElem, document.body);
assert.equal(selectedText, "");
assert.equal(selectedText, '');
});
});
describe("#destroy", () => {
it("should destroy an existing fake element", () => {
describe('#destroy', () => {
it('should destroy an existing fake element', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),
container: document.body,
text: "blah",
text: 'blah',
});
clip.selectFake();