aboutsummaryrefslogtreecommitdiff
path: root/test/content
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-08-22 22:00:42 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-08-22 22:00:42 +0900
commitab5fd9a336166cab75ff00e65afb4be991ff0765 (patch)
treef2e933c927baf64cc393ea1a83ed57cc1fcc9bb2 /test/content
parent13fb726332e9638cb3fafc477cf9fe641cb906ce (diff)
parentdcebe336281d068649927a8bb8d3c0403807ef01 (diff)
Merge branch 'follow-hints'
Diffstat (limited to 'test/content')
-rw-r--r--test/content/follow.html9
-rw-r--r--test/content/follow.test.js25
-rw-r--r--test/content/hint-key-producer.test.js25
-rw-r--r--test/content/hint.html1
-rw-r--r--test/content/hint.test.js58
5 files changed, 118 insertions, 0 deletions
diff --git a/test/content/follow.html b/test/content/follow.html
new file mode 100644
index 0000000..6bd8f87
--- /dev/null
+++ b/test/content/follow.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <a href='#' >link</a>
+ <a href='#' style='display:none'>invisible 1</a>
+ <a href='#' style='visibility:hidden'>invisible 2</a>
+ <i>not link<i>
+ </body>
+</html>
diff --git a/test/content/follow.test.js b/test/content/follow.test.js
new file mode 100644
index 0000000..fd4f0bc
--- /dev/null
+++ b/test/content/follow.test.js
@@ -0,0 +1,25 @@
+import { expect } from "chai";
+import Follow from '../../src/content/follow';
+
+describe('Follow class', () => {
+ describe('#codeChars', () => {
+ it('returns a string for key codes', () => {
+ let chars = [
+ KeyboardEvent.DOM_VK_0, KeyboardEvent.DOM_VK_1,
+ KeyboardEvent.DOM_VK_A, KeyboardEvent.DOM_VK_B];
+ expect(Follow.codeChars(chars)).to.equal('01ab');
+ expect(Follow.codeChars([])).to.be.equal('');
+ });
+ });
+
+ describe('#getTargetElements', () => {
+ beforeEach(() => {
+ document.body.innerHTML = __html__['test/content/follow.html'];
+ });
+
+ it('returns visible links', () => {
+ let links = Follow.getTargetElements(window.document);
+ expect(links).to.have.lengthOf(1);
+ });
+ });
+});
diff --git a/test/content/hint-key-producer.test.js b/test/content/hint-key-producer.test.js
new file mode 100644
index 0000000..74fb462
--- /dev/null
+++ b/test/content/hint-key-producer.test.js
@@ -0,0 +1,25 @@
+import { expect } from "chai";
+import HintKeyProducer from '../../src/content/hint-key-producer';
+
+describe('HintKeyProducer class', () => {
+ describe('#constructor', () => {
+ it('throws an exception on empty charset', () => {
+ expect(() => new HintKeyProducer([])).to.throw(TypeError);
+ });
+ });
+
+ describe('#produce', () => {
+ it('produce incremented keys', () => {
+ let charset = 'abc';
+ let sequences = [
+ 'a', 'b', 'c',
+ 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc',
+ 'aaa', 'aab', 'aac', 'aba']
+
+ let producer = new HintKeyProducer(charset);
+ for (let i = 0; i < sequences.length; ++i) {
+ expect(producer.produce()).to.equal(sequences[i]);
+ }
+ });
+ });
+});
diff --git a/test/content/hint.html b/test/content/hint.html
new file mode 100644
index 0000000..b50c5fe
--- /dev/null
+++ b/test/content/hint.html
@@ -0,0 +1 @@
+<a id='test-link' href='javascript:window.vimvixenTest="hello"' >link</a>
diff --git a/test/content/hint.test.js b/test/content/hint.test.js
new file mode 100644
index 0000000..9b2ab6e
--- /dev/null
+++ b/test/content/hint.test.js
@@ -0,0 +1,58 @@
+import { expect } from "chai";
+import Hint from '../../src/content/hint';
+
+describe('Hint class', () => {
+ beforeEach(() => {
+ document.body.innerHTML = __html__['test/content/hint.html'];
+ });
+
+ describe('#constructor', () => {
+ it('creates a hint element with tag name', () => {
+ let link = document.getElementById('test-link');
+ let hint = new Hint(link, 'abc');
+ expect(hint.element.textContent.trim()).to.be.equal('abc');
+ });
+
+ it('throws an exception when non-element given', () => {
+ expect(() => new Hint(window, 'abc')).to.throw(TypeError);
+ });
+ });
+
+ describe('#show', () => {
+ it('shows an element', () => {
+ let link = document.getElementById('test-link');
+ let hint = new Hint(link, 'abc');
+ hint.hide();
+ hint.show();
+
+ expect(hint.element.style.display).to.not.equal('none');
+ });
+ });
+
+ describe('#hide', () => {
+ it('hides an element', () => {
+ let link = document.getElementById('test-link');
+ let hint = new Hint(link, 'abc');
+ hint.hide();
+
+ expect(hint.element.style.display).to.equal('none');
+ });
+ });
+
+ describe('#remove', () => {
+ it('removes an element', () => {
+ let link = document.getElementById('test-link');
+ let hint = new Hint(link, 'abc');
+
+ expect(hint.element.parentElement).to.not.be.null;
+ hint.remove();
+ expect(hint.element.parentElement).to.be.null;
+ });
+ });
+
+ describe('#activate', () => {
+ // TODO test activations
+ });
+});
+
+