aboutsummaryrefslogtreecommitdiff
path: root/test/content
diff options
context:
space:
mode:
Diffstat (limited to 'test/content')
-rw-r--r--test/content/actions/setting.test.js23
-rw-r--r--test/content/components/common/input.test.js41
-rw-r--r--test/content/navigates.test.js156
-rw-r--r--test/content/reducers/find.test.js23
-rw-r--r--test/content/reducers/input.test.js12
-rw-r--r--test/content/reducers/setting.test.js2
6 files changed, 176 insertions, 81 deletions
diff --git a/test/content/actions/setting.test.js b/test/content/actions/setting.test.js
index 8855f04..1248edf 100644
--- a/test/content/actions/setting.test.js
+++ b/test/content/actions/setting.test.js
@@ -7,7 +7,28 @@ describe("setting actions", () => {
it('create SETTING_SET action', () => {
let action = settingActions.set({ red: 'apple', yellow: 'banana' });
expect(action.type).to.equal(actions.SETTING_SET);
- expect(action.value).to.deep.equal({ red: 'apple', yellow: 'banana' });
+ expect(action.value.red).to.equal('apple');
+ expect(action.value.yellow).to.equal('banana');
+ expect(action.value.keymaps).to.be.empty;
+ });
+
+ it('converts keymaps', () => {
+ let action = settingActions.set({
+ keymaps: {
+ 'dd': 'remove current tab',
+ 'z<C-A>': 'increment',
+ }
+ });
+ let keymaps = action.value.keymaps;
+ let map = new Map(keymaps);
+ expect(map).to.have.deep.all.keys(
+ [
+ [{ key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false },
+ { key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }],
+ [{ key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false },
+ { key: 'a', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false }],
+ ]
+ );
});
});
});
diff --git a/test/content/components/common/input.test.js b/test/content/components/common/input.test.js
index 912ac34..a346cf6 100644
--- a/test/content/components/common/input.test.js
+++ b/test/content/components/common/input.test.js
@@ -4,20 +4,21 @@ import { expect } from "chai";
describe('InputComponent', () => {
it('register callbacks', () => {
let component = new InputComponent(window.document);
+ let key = { key: 'a', ctrlKey: true, shiftKey: false, altKey: false, metaKey: false };
component.onKey((key) => {
- expect(key).is.equals('a');
+ expect(key).to.deep.equal(key);
});
- component.onKeyDown({ key: 'a' });
+ component.onKeyDown(key);
});
it('invoke callback once', () => {
let component = new InputComponent(window.document);
let a = 0, b = 0;
component.onKey((key) => {
- if (key == 'a') {
+ if (key.key == 'a') {
++a;
} else {
- key == 'b'
+ key.key == 'b'
++b;
}
});
@@ -32,38 +33,6 @@ describe('InputComponent', () => {
expect(b).is.equals(1);
})
- it('add prefix when ctrl pressed', () => {
- let component = new InputComponent(window.document);
- component.onKey((key) => {
- expect(key).is.equals('<C-A>');
- });
- component.onKeyDown({ key: 'a', ctrlKey: true });
- })
-
- it('press X', () => {
- let component = new InputComponent(window.document);
- component.onKey((key) => {
- expect(key).is.equals('X');
- });
- component.onKeyDown({ key: 'X', shiftKey: true });
- })
-
- it('press <Shift> + <Esc>', () => {
- let component = new InputComponent(window.document);
- component.onKey((key) => {
- expect(key).is.equals('<S-Esc>');
- });
- component.onKeyDown({ key: 'Escape', shiftKey: true });
- })
-
- it('press <Ctrl> + <Esc>', () => {
- let component = new InputComponent(window.document);
- component.onKey((key) => {
- expect(key).is.equals('<C-Esc>');
- });
- component.onKeyDown({ key: 'Escape', ctrlKey: true });
- })
-
it('does not invoke only meta keys', () => {
let component = new InputComponent(window.document);
component.onKey((key) => {
diff --git a/test/content/navigates.test.js b/test/content/navigates.test.js
index b5144e9..d8a3316 100644
--- a/test/content/navigates.test.js
+++ b/test/content/navigates.test.js
@@ -1,56 +1,138 @@
-import { expect } from "chai";
+import { expect } from 'chai';
import * as navigates from 'content/navigates';
+const testRel = (done, rel, html) => {
+ const method = rel === 'prev' ? 'linkPrev' : 'linkNext';
+ document.body.innerHTML = html;
+ navigates[method](window);
+ setTimeout(() => {
+ expect(document.location.hash).to.equal(`#${rel}`);
+ done();
+ }, 0);
+};
+
+const testPrev = html => done => testRel(done, 'prev', html);
+const testNext = html => done => testRel(done, 'next', html);
+
describe('navigates module', () => {
describe('#linkPrev', () => {
- it('clicks prev link by text content', (done) => {
- document.body.innerHTML = '<a href="#dummy">xprevx</a> <a href="#prev">go to prev</a>';
- navigates.linkPrev(window);
- setTimeout(() => {
- expect(document.location.hash).to.equal('#prev');
- done();
- }, 0);
- });
+ it('navigates to <link> elements whose rel attribute is "prev"', testPrev(
+ '<link rel="prev" href="#prev" />'
+ ));
- it('clicks a[rel=prev] element preferentially', (done) => {
- document.body.innerHTML = '<a href="#dummy">prev</a> <a rel="prev" href="#prev">rel</a>';
- navigates.linkPrev(window);
- setTimeout(() => {
- expect(document.location.hash).to.equal('#prev');
- done();
- }, 0);
- });
- });
+ it('navigates to <link> elements whose rel attribute starts with "prev"', testPrev(
+ '<link rel="prev bar" href="#prev" />'
+ ));
+
+ it('navigates to <link> elements whose rel attribute ends with "prev"', testPrev(
+ '<link rel="foo prev" href="#prev" />'
+ ));
+
+ it('navigates to <link> elements whose rel attribute contains "prev"', testPrev(
+ '<link rel="foo prev bar" href="#prev" />'
+ ));
+
+ it('navigates to <a> elements whose rel attribute is "prev"', testPrev(
+ '<a rel="prev" href="#prev">click me</a>'
+ ));
+
+ it('navigates to <a> elements whose rel attribute starts with "prev"', testPrev(
+ '<a rel="prev bar" href="#prev">click me</a>'
+ ));
+
+ it('navigates to <a> elements whose rel attribute ends with "prev"', testPrev(
+ '<a rel="foo prev" href="#prev">click me</a>'
+ ));
+
+ it('navigates to <a> elements whose rel attribute contains "prev"', testPrev(
+ '<a rel="foo prev bar" href="#prev">click me</a>'
+ ));
+
+ it('navigates to <a> elements whose text matches "prev"', testPrev(
+ '<a href="#dummy">preview</a><a href="#prev">go to prev</a>'
+ ));
+
+ it('navigates to <a> elements whose text matches "previous"', testPrev(
+ '<a href="#dummy">preview</a><a href="#prev">go to previous</a>'
+ ));
+
+ it('navigates to <a> elements whose decoded text matches "<<"', testPrev(
+ '<a href="#dummy">click me</a><a href="#prev">&lt;&lt;</a>'
+ ));
+
+ it('navigates to matching <a> elements by clicking', testPrev(
+ `<a rel="prev" href="#dummy" onclick="return location = '#prev', false">go to prev</a>`
+ ));
+
+ it('prefers link[rel~=prev] to a[rel~=prev]', testPrev(
+ '<a rel="prev" href="#dummy">click me</a><link rel="prev" href="#prev" />'
+ ));
+ it('prefers a[rel~=prev] to a::text(pattern)', testPrev(
+ '<a href="#dummy">go to prev</a><a rel="prev" href="#prev">click me</a>'
+ ));
+ });
describe('#linkNext', () => {
- it('clicks next link by text content', (done) => {
- document.body.innerHTML = '<a href="#dummy">xnextx</a> <a href="#next">go to next</a>';
- navigates.linkNext(window);
- setTimeout(() => {
- expect(document.location.hash).to.equal('#next');
- done();
- }, 0);
- });
+ it('navigates to <link> elements whose rel attribute is "next"', testNext(
+ '<link rel="next" href="#next" />'
+ ));
- it('clicks a[rel=next] element preferentially', (done) => {
- document.body.innerHTML = '<a href="#dummy">next</a> <a rel="next" href="#next">rel</a>';
- navigates.linkNext(window);
- setTimeout(() => {
- expect(document.location.hash).to.equal('#next');
- done();
- }, 0);
- });
+ it('navigates to <link> elements whose rel attribute starts with "next"', testNext(
+ '<link rel="next bar" href="#next" />'
+ ));
+
+ it('navigates to <link> elements whose rel attribute ends with "next"', testNext(
+ '<link rel="foo next" href="#next" />'
+ ));
+
+ it('navigates to <link> elements whose rel attribute contains "next"', testNext(
+ '<link rel="foo next bar" href="#next" />'
+ ));
+
+ it('navigates to <a> elements whose rel attribute is "next"', testNext(
+ '<a rel="next" href="#next">click me</a>'
+ ));
+
+ it('navigates to <a> elements whose rel attribute starts with "next"', testNext(
+ '<a rel="next bar" href="#next">click me</a>'
+ ));
+
+ it('navigates to <a> elements whose rel attribute ends with "next"', testNext(
+ '<a rel="foo next" href="#next">click me</a>'
+ ));
+
+ it('navigates to <a> elements whose rel attribute contains "next"', testNext(
+ '<a rel="foo next bar" href="#next">click me</a>'
+ ));
+
+ it('navigates to <a> elements whose text matches "next"', testNext(
+ '<a href="#dummy">inextricable</a><a href="#next">go to next</a>'
+ ));
+
+ it('navigates to <a> elements whose decoded text matches ">>"', testNext(
+ '<a href="#dummy">click me</a><a href="#next">&gt;&gt;</a>'
+ ));
+
+ it('navigates to matching <a> elements by clicking', testNext(
+ `<a rel="next" href="#dummy" onclick="return location = '#next', false">go to next</a>`
+ ));
+
+ it('prefers link[rel~=next] to a[rel~=next]', testNext(
+ '<a rel="next" href="#dummy">click me<><link rel="next" href="#next" />'
+ ));
+
+ it('prefers a[rel~=next] to a::text(pattern)', testNext(
+ '<a href="#dummy">go to next</a><a rel="next" href="#next">click me</a>'
+ ));
});
describe('#parent', () => {
// NOTE: not able to test location
it('removes hash', () => {
- window.location.hash = "#section-1";
+ window.location.hash = '#section-1';
navigates.parent(window);
expect(document.location.hash).to.be.empty;
});
});
});
-
-
diff --git a/test/content/reducers/find.test.js b/test/content/reducers/find.test.js
new file mode 100644
index 0000000..93625da
--- /dev/null
+++ b/test/content/reducers/find.test.js
@@ -0,0 +1,23 @@
+import { expect } from "chai";
+import actions from 'content/actions';
+import findReducer from 'content/reducers/find';
+
+describe("find reducer", () => {
+ it('return the initial state', () => {
+ let state = findReducer(undefined, {});
+ expect(state).to.have.property('keyword', '');
+ expect(state).to.have.property('found', false);
+ });
+
+ it('return next state for FIND_SET_KEYWORD', () => {
+ let action = {
+ type: actions.FIND_SET_KEYWORD,
+ keyword: 'xyz',
+ found: true,
+ };
+ let state = findReducer({}, action);
+
+ expect(state.keyword).is.equal('xyz');
+ expect(state.found).to.be.true;
+ });
+});
diff --git a/test/content/reducers/input.test.js b/test/content/reducers/input.test.js
index d5e5f6b..d0b5655 100644
--- a/test/content/reducers/input.test.js
+++ b/test/content/reducers/input.test.js
@@ -5,22 +5,22 @@ import inputReducer from 'content/reducers/input';
describe("input reducer", () => {
it('return the initial state', () => {
let state = inputReducer(undefined, {});
- expect(state).to.have.deep.property('keys', '');
+ expect(state).to.have.deep.property('keys', []);
});
it('return next state for INPUT_KEY_PRESS', () => {
let action = { type: actions.INPUT_KEY_PRESS, key: 'a' };
let state = inputReducer(undefined, action);
- expect(state).to.have.deep.property('keys', 'a');
+ expect(state).to.have.deep.property('keys', ['a']);
- action = { type: actions.INPUT_KEY_PRESS, key: '<C-B>' };
+ action = { type: actions.INPUT_KEY_PRESS, key: 'b' };
state = inputReducer(state, action);
- expect(state).to.have.deep.property('keys', 'a<C-B>');
+ expect(state).to.have.deep.property('keys', ['a', 'b']);
});
it('return next state for INPUT_CLEAR_KEYS', () => {
let action = { type: actions.INPUT_CLEAR_KEYS };
- let state = inputReducer({ keys: 'abc' }, action);
- expect(state).to.have.deep.property('keys', '');
+ let state = inputReducer({ keys: [1, 2, 3] }, action);
+ expect(state).to.have.deep.property('keys', []);
});
});
diff --git a/test/content/reducers/setting.test.js b/test/content/reducers/setting.test.js
index ef49594..634b299 100644
--- a/test/content/reducers/setting.test.js
+++ b/test/content/reducers/setting.test.js
@@ -5,7 +5,7 @@ import settingReducer from 'content/reducers/setting';
describe("content setting reducer", () => {
it('return the initial state', () => {
let state = settingReducer(undefined, {});
- expect(state).to.deep.equal({ keymaps: {} });
+ expect(state.keymaps).to.be.empty;
});
it('return next state for SETTING_SET', () => {