From 6551420e1ae0e91201de72e862e918dd3c97ab43 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 30 Sep 2017 20:27:26 +0900 Subject: move messages to content --- src/actions/operation.js | 2 +- src/background/index.js | 2 +- src/console/completion.js | 27 ------ src/console/console-frame.scss | 12 --- src/console/console.html | 20 ----- src/console/console.js | 186 ---------------------------------------- src/console/console.scss | 92 -------------------- src/console/frames.js | 18 ---- src/content/console-frame.scss | 12 +++ src/content/console-frames.js | 18 ++++ src/content/index.js | 6 +- src/content/messages.js | 14 +++ src/messages/index.js | 14 --- src/pages/completion.js | 27 ++++++ src/pages/console.html | 20 +++++ src/pages/console.js | 186 ++++++++++++++++++++++++++++++++++++++++ src/pages/console.scss | 92 ++++++++++++++++++++ src/pages/settings.html | 18 ++++ src/pages/settings.js | 22 +++++ src/pages/settings.scss | 8 ++ src/settings/index.js | 22 ----- src/settings/settings.html | 18 ---- src/settings/settings.scss | 8 -- test/console/completion.test.js | 48 ----------- test/pages/completion.test.js | 48 +++++++++++ webpack.config.js | 8 +- 26 files changed, 474 insertions(+), 474 deletions(-) delete mode 100644 src/console/completion.js delete mode 100644 src/console/console-frame.scss delete mode 100644 src/console/console.html delete mode 100644 src/console/console.js delete mode 100644 src/console/console.scss delete mode 100644 src/console/frames.js create mode 100644 src/content/console-frame.scss create mode 100644 src/content/console-frames.js create mode 100644 src/content/messages.js delete mode 100644 src/messages/index.js create mode 100644 src/pages/completion.js create mode 100644 src/pages/console.html create mode 100644 src/pages/console.js create mode 100644 src/pages/console.scss create mode 100644 src/pages/settings.html create mode 100644 src/pages/settings.js create mode 100644 src/pages/settings.scss delete mode 100644 src/settings/index.js delete mode 100644 src/settings/settings.html delete mode 100644 src/settings/settings.scss delete mode 100644 test/console/completion.test.js create mode 100644 test/pages/completion.test.js diff --git a/src/actions/operation.js b/src/actions/operation.js index 5646c1c..5b7f127 100644 --- a/src/actions/operation.js +++ b/src/actions/operation.js @@ -1,5 +1,5 @@ import operations from '../operations'; -import messages from '../messages'; +import messages from '../content/messages'; import * as consoleActions from './console'; import * as tabs from '../background/tabs'; import * as zooms from '../background/zooms'; diff --git a/src/background/index.js b/src/background/index.js index 5ae967c..0e75a36 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -5,7 +5,7 @@ import * as commandActions from '../actions/command'; import * as consoleActions from '../actions/console'; import * as tabActions from '../actions/tab'; import reducers from '../reducers'; -import messages from '../messages'; +import messages from '../content/messages'; import * as store from '../store'; let prevInput = []; diff --git a/src/console/completion.js b/src/console/completion.js deleted file mode 100644 index 4c69afb..0000000 --- a/src/console/completion.js +++ /dev/null @@ -1,27 +0,0 @@ -export default class Completion { - constructor(completions) { - if (typeof completions.length !== 'number') { - throw new TypeError('completions does not have a length in number'); - } - this.completions = completions; - this.index = 0; - } - - prev() { - let length = this.completions.length; - if (length === 0) { - return null; - } - this.index = (this.index + length - 1) % length; - return this.completions[this.index]; - } - - next() { - if (this.completions.length === 0) { - return null; - } - let item = this.completions[this.index]; - this.index = (this.index + 1) % this.completions.length; - return item; - } -} diff --git a/src/console/console-frame.scss b/src/console/console-frame.scss deleted file mode 100644 index 33bfff3..0000000 --- a/src/console/console-frame.scss +++ /dev/null @@ -1,12 +0,0 @@ -.vimvixen-console-frame { - margin: 0; - padding: 0; - bottom: 0; - left: 0; - width: 100%; - height: 100%; - position: fixed; - z-index: 10000; - border: none; - pointer-events:none; -} diff --git a/src/console/console.html b/src/console/console.html deleted file mode 100644 index 4222f12..0000000 --- a/src/console/console.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - VimVixen console - - - -

-
- -
- -
-
- - diff --git a/src/console/console.js b/src/console/console.js deleted file mode 100644 index 4471446..0000000 --- a/src/console/console.js +++ /dev/null @@ -1,186 +0,0 @@ -import './console.scss'; -import Completion from './completion'; -import messages from '../messages'; - -// TODO consider object-oriented -let prevValue = ''; -let completion = null; -let completionOrigin = ''; -let prevState = {}; - -const handleBlur = () => { - return browser.runtime.sendMessage({ - type: messages.CONSOLE_BLURRED, - }); -}; - -const selectCompletion = (target) => { - let container = window.document.querySelector('#vimvixen-console-completion'); - Array.prototype.forEach.call(container.children, (ele) => { - if (!ele.classList.contains('vimvixen-console-completion-item')) { - return; - } - if (ele === target) { - ele.classList.add('vimvixen-completion-selected'); - } else { - ele.classList.remove('vimvixen-completion-selected'); - } - }); -}; - -const completeNext = () => { - if (!completion) { - return; - } - let item = completion.next(); - if (!item) { - return; - } - - let input = window.document.querySelector('#vimvixen-console-command-input'); - input.value = completionOrigin + ' ' + item[0].content; - - selectCompletion(item[1]); -}; - -const completePrev = () => { - if (!completion) { - return; - } - let item = completion.prev(); - if (!item) { - return; - } - - let input = window.document.querySelector('#vimvixen-console-command-input'); - input.value = completionOrigin + ' ' + item[0].content; - - selectCompletion(item[1]); -}; - -const handleKeydown = (e) => { - let input = window.document.querySelector('#vimvixen-console-command-input'); - - switch (e.keyCode) { - case KeyboardEvent.DOM_VK_ESCAPE: - return input.blur(); - case KeyboardEvent.DOM_VK_RETURN: - return browser.runtime.sendMessage({ - type: messages.CONSOLE_ENTERED, - text: e.target.value - }); - case KeyboardEvent.DOM_VK_TAB: - if (e.shiftKey) { - completePrev(); - } else { - completeNext(); - } - e.stopPropagation(); - e.preventDefault(); - break; - } -}; - -const handleKeyup = (e) => { - if (e.keyCode === KeyboardEvent.DOM_VK_TAB) { - return; - } - if (e.target.value === prevValue) { - return; - } - prevValue = e.target.value; - return browser.runtime.sendMessage({ - type: messages.CONSOLE_CHANGEED, - text: e.target.value - }); -}; - -window.addEventListener('load', () => { - let input = window.document.querySelector('#vimvixen-console-command-input'); - input.addEventListener('blur', handleBlur); - input.addEventListener('keydown', handleKeydown); - input.addEventListener('keyup', handleKeyup); -}); - -const createCompletionTitle = (text) => { - let li = document.createElement('li'); - li.className = 'vimvixen-console-completion-title'; - li.textContent = text; - return li; -}; - -const createCompletionItem = (icon, caption, url) => { - let captionEle = document.createElement('span'); - captionEle.className = 'vimvixen-console-completion-item-caption'; - captionEle.textContent = caption; - - let urlEle = document.createElement('span'); - urlEle.className = 'vimvixen-console-completion-item-url'; - urlEle.textContent = url; - - let li = document.createElement('li'); - li.style.backgroundImage = 'url(' + icon + ')'; - li.className = 'vimvixen-console-completion-item'; - li.append(captionEle); - li.append(urlEle); - return li; -}; - -const updateCompletions = (completions) => { - let completionsContainer = - window.document.querySelector('#vimvixen-console-completion'); - let input = window.document.querySelector('#vimvixen-console-command-input'); - - completionsContainer.innerHTML = ''; - - let pairs = []; - - for (let group of completions) { - let title = createCompletionTitle(group.name); - completionsContainer.append(title); - - for (let item of group.items) { - let li = createCompletionItem(item.icon, item.caption, item.url); - completionsContainer.append(li); - - pairs.push([item, li]); - } - } - - completion = new Completion(pairs); - completionOrigin = input.value.split(' ')[0]; -}; - -const update = (state) => { - let error = window.document.querySelector('#vimvixen-console-error'); - let command = window.document.querySelector('#vimvixen-console-command'); - let input = window.document.querySelector('#vimvixen-console-command-input'); - - error.style.display = state.errorShown ? 'block' : 'none'; - error.textContent = state.errorText; - - command.style.display = state.commandShown ? 'block' : 'none'; - if (state.commandShown && !prevState.commandShown) { - input.value = state.commandText; - input.focus(); - } - if (JSON.stringify(state.completions) !== - JSON.stringify(prevState.completions)) { - updateCompletions(state.completions); - } - - prevState = state; -}; - -browser.runtime.onMessage.addListener((action) => { - if (action.type === messages.STATE_UPDATE) { - return update(action.state.console); - } -}); - -window.addEventListener('load', () => { - let error = window.document.querySelector('#vimvixen-console-error'); - let command = window.document.querySelector('#vimvixen-console-command'); - error.style.display = 'none'; - command.style.display = 'none'; -}); diff --git a/src/console/console.scss b/src/console/console.scss deleted file mode 100644 index 5823dce..0000000 --- a/src/console/console.scss +++ /dev/null @@ -1,92 +0,0 @@ -html, body, * { - margin: 0; - padding: 0; -} - -body { - position: absolute; - bottom: 0; - left: 0; - right: 0; - overflow: hidden; -} - -.vimvixen-console { - border-top: 1px solid gray; - bottom: 0; - margin: 0; - padding: 0; - - @mixin consoole-font { - font-style: normal; - font-family: monospace; - font-size: 12px; - line-height: 16px; - } - - &-completion { - background-color: white; - - @include consoole-font; - - &-title { - background-color: lightgray; - font-weight: bold; - margin: 0; - padding: 0; - } - - &-item { - padding-left: 1.5rem; - background-position: 0 center; - background-size: contain; - background-repeat: no-repeat; - white-space: nowrap; - - &.vimvixen-completion-selected { - background-color: yellow; - } - - &-caption { - display: inline-block; - width: 40%; - text-overflow: ellipsis; - overflow: hidden; - } - - &-url { - display: inline-block; - color: green; - width: 60%; - text-overflow: ellipsis; - overflow: hidden; - } - } - } - - &-error { - background-color: red; - font-weight: bold; - color: white; - - @include consoole-font; - } - - &-command { - background-color: white; - display: flex; - - &-prompt:before { - content: ':'; - - @include consoole-font; - } - - &-input { - border: none; - flex-grow: 1; - - @include consoole-font; - } - } -} diff --git a/src/console/frames.js b/src/console/frames.js deleted file mode 100644 index 3f06466..0000000 --- a/src/console/frames.js +++ /dev/null @@ -1,18 +0,0 @@ -import './console-frame.scss'; - -const initialize = (doc) => { - let iframe = doc.createElement('iframe'); - iframe.src = browser.runtime.getURL('build/console.html'); - iframe.id = 'vimvixen-console-frame'; - iframe.className = 'vimvixen-console-frame'; - doc.body.append(iframe); - - return iframe; -}; - -const blur = (doc) => { - let iframe = doc.getElementById('vimvixen-console-frame'); - iframe.blur(); -}; - -export { initialize, blur }; diff --git a/src/content/console-frame.scss b/src/content/console-frame.scss new file mode 100644 index 0000000..33bfff3 --- /dev/null +++ b/src/content/console-frame.scss @@ -0,0 +1,12 @@ +.vimvixen-console-frame { + margin: 0; + padding: 0; + bottom: 0; + left: 0; + width: 100%; + height: 100%; + position: fixed; + z-index: 10000; + border: none; + pointer-events:none; +} diff --git a/src/content/console-frames.js b/src/content/console-frames.js new file mode 100644 index 0000000..3f06466 --- /dev/null +++ b/src/content/console-frames.js @@ -0,0 +1,18 @@ +import './console-frame.scss'; + +const initialize = (doc) => { + let iframe = doc.createElement('iframe'); + iframe.src = browser.runtime.getURL('build/console.html'); + iframe.id = 'vimvixen-console-frame'; + iframe.className = 'vimvixen-console-frame'; + doc.body.append(iframe); + + return iframe; +}; + +const blur = (doc) => { + let iframe = doc.getElementById('vimvixen-console-frame'); + iframe.blur(); +}; + +export { initialize, blur }; diff --git a/src/content/index.js b/src/content/index.js index 812fbc5..2e64af2 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -1,10 +1,10 @@ -import '../console/console-frame.scss'; -import * as consoleFrames from '../console/frames'; +import './console-frame.scss'; +import * as consoleFrames from './console-frames'; import * as scrolls from '../content/scrolls'; import * as navigates from '../content/navigates'; import Follow from '../content/follow'; import operations from '../operations'; -import messages from '../messages'; +import messages from './messages'; consoleFrames.initialize(window.document); diff --git a/src/content/messages.js b/src/content/messages.js new file mode 100644 index 0000000..df9fba2 --- /dev/null +++ b/src/content/messages.js @@ -0,0 +1,14 @@ +export default { + STATE_UPDATE: 'state.update', + CONTENT_OPERATION: 'content.operation', + + CONSOLE_BLURRED: 'console.blured', + CONSOLE_ENTERED: 'console.entered', + CONSOLE_CHANGEED: 'console.changed', + + KEYDOWN: 'keydown', + + OPEN_URL: 'open.url', + + SETTINGS_RELOAD: 'settings.reload', +}; diff --git a/src/messages/index.js b/src/messages/index.js deleted file mode 100644 index df9fba2..0000000 --- a/src/messages/index.js +++ /dev/null @@ -1,14 +0,0 @@ -export default { - STATE_UPDATE: 'state.update', - CONTENT_OPERATION: 'content.operation', - - CONSOLE_BLURRED: 'console.blured', - CONSOLE_ENTERED: 'console.entered', - CONSOLE_CHANGEED: 'console.changed', - - KEYDOWN: 'keydown', - - OPEN_URL: 'open.url', - - SETTINGS_RELOAD: 'settings.reload', -}; diff --git a/src/pages/completion.js b/src/pages/completion.js new file mode 100644 index 0000000..4c69afb --- /dev/null +++ b/src/pages/completion.js @@ -0,0 +1,27 @@ +export default class Completion { + constructor(completions) { + if (typeof completions.length !== 'number') { + throw new TypeError('completions does not have a length in number'); + } + this.completions = completions; + this.index = 0; + } + + prev() { + let length = this.completions.length; + if (length === 0) { + return null; + } + this.index = (this.index + length - 1) % length; + return this.completions[this.index]; + } + + next() { + if (this.completions.length === 0) { + return null; + } + let item = this.completions[this.index]; + this.index = (this.index + 1) % this.completions.length; + return item; + } +} diff --git a/src/pages/console.html b/src/pages/console.html new file mode 100644 index 0000000..4222f12 --- /dev/null +++ b/src/pages/console.html @@ -0,0 +1,20 @@ + + + + + VimVixen console + + + +

+
+ +
+ +
+
+ + diff --git a/src/pages/console.js b/src/pages/console.js new file mode 100644 index 0000000..31f2643 --- /dev/null +++ b/src/pages/console.js @@ -0,0 +1,186 @@ +import './console.scss'; +import Completion from './completion'; +import messages from '../content/messages'; + +// TODO consider object-oriented +let prevValue = ''; +let completion = null; +let completionOrigin = ''; +let prevState = {}; + +const handleBlur = () => { + return browser.runtime.sendMessage({ + type: messages.CONSOLE_BLURRED, + }); +}; + +const selectCompletion = (target) => { + let container = window.document.querySelector('#vimvixen-console-completion'); + Array.prototype.forEach.call(container.children, (ele) => { + if (!ele.classList.contains('vimvixen-console-completion-item')) { + return; + } + if (ele === target) { + ele.classList.add('vimvixen-completion-selected'); + } else { + ele.classList.remove('vimvixen-completion-selected'); + } + }); +}; + +const completeNext = () => { + if (!completion) { + return; + } + let item = completion.next(); + if (!item) { + return; + } + + let input = window.document.querySelector('#vimvixen-console-command-input'); + input.value = completionOrigin + ' ' + item[0].content; + + selectCompletion(item[1]); +}; + +const completePrev = () => { + if (!completion) { + return; + } + let item = completion.prev(); + if (!item) { + return; + } + + let input = window.document.querySelector('#vimvixen-console-command-input'); + input.value = completionOrigin + ' ' + item[0].content; + + selectCompletion(item[1]); +}; + +const handleKeydown = (e) => { + let input = window.document.querySelector('#vimvixen-console-command-input'); + + switch (e.keyCode) { + case KeyboardEvent.DOM_VK_ESCAPE: + return input.blur(); + case KeyboardEvent.DOM_VK_RETURN: + return browser.runtime.sendMessage({ + type: messages.CONSOLE_ENTERED, + text: e.target.value + }); + case KeyboardEvent.DOM_VK_TAB: + if (e.shiftKey) { + completePrev(); + } else { + completeNext(); + } + e.stopPropagation(); + e.preventDefault(); + break; + } +}; + +const handleKeyup = (e) => { + if (e.keyCode === KeyboardEvent.DOM_VK_TAB) { + return; + } + if (e.target.value === prevValue) { + return; + } + prevValue = e.target.value; + return browser.runtime.sendMessage({ + type: messages.CONSOLE_CHANGEED, + text: e.target.value + }); +}; + +window.addEventListener('load', () => { + let input = window.document.querySelector('#vimvixen-console-command-input'); + input.addEventListener('blur', handleBlur); + input.addEventListener('keydown', handleKeydown); + input.addEventListener('keyup', handleKeyup); +}); + +const createCompletionTitle = (text) => { + let li = document.createElement('li'); + li.className = 'vimvixen-console-completion-title'; + li.textContent = text; + return li; +}; + +const createCompletionItem = (icon, caption, url) => { + let captionEle = document.createElement('span'); + captionEle.className = 'vimvixen-console-completion-item-caption'; + captionEle.textContent = caption; + + let urlEle = document.createElement('span'); + urlEle.className = 'vimvixen-console-completion-item-url'; + urlEle.textContent = url; + + let li = document.createElement('li'); + li.style.backgroundImage = 'url(' + icon + ')'; + li.className = 'vimvixen-console-completion-item'; + li.append(captionEle); + li.append(urlEle); + return li; +}; + +const updateCompletions = (completions) => { + let completionsContainer = + window.document.querySelector('#vimvixen-console-completion'); + let input = window.document.querySelector('#vimvixen-console-command-input'); + + completionsContainer.innerHTML = ''; + + let pairs = []; + + for (let group of completions) { + let title = createCompletionTitle(group.name); + completionsContainer.append(title); + + for (let item of group.items) { + let li = createCompletionItem(item.icon, item.caption, item.url); + completionsContainer.append(li); + + pairs.push([item, li]); + } + } + + completion = new Completion(pairs); + completionOrigin = input.value.split(' ')[0]; +}; + +const update = (state) => { + let error = window.document.querySelector('#vimvixen-console-error'); + let command = window.document.querySelector('#vimvixen-console-command'); + let input = window.document.querySelector('#vimvixen-console-command-input'); + + error.style.display = state.errorShown ? 'block' : 'none'; + error.textContent = state.errorText; + + command.style.display = state.commandShown ? 'block' : 'none'; + if (state.commandShown && !prevState.commandShown) { + input.value = state.commandText; + input.focus(); + } + if (JSON.stringify(state.completions) !== + JSON.stringify(prevState.completions)) { + updateCompletions(state.completions); + } + + prevState = state; +}; + +browser.runtime.onMessage.addListener((action) => { + if (action.type === messages.STATE_UPDATE) { + return update(action.state.console); + } +}); + +window.addEventListener('load', () => { + let error = window.document.querySelector('#vimvixen-console-error'); + let command = window.document.querySelector('#vimvixen-console-command'); + error.style.display = 'none'; + command.style.display = 'none'; +}); diff --git a/src/pages/console.scss b/src/pages/console.scss new file mode 100644 index 0000000..5823dce --- /dev/null +++ b/src/pages/console.scss @@ -0,0 +1,92 @@ +html, body, * { + margin: 0; + padding: 0; +} + +body { + position: absolute; + bottom: 0; + left: 0; + right: 0; + overflow: hidden; +} + +.vimvixen-console { + border-top: 1px solid gray; + bottom: 0; + margin: 0; + padding: 0; + + @mixin consoole-font { + font-style: normal; + font-family: monospace; + font-size: 12px; + line-height: 16px; + } + + &-completion { + background-color: white; + + @include consoole-font; + + &-title { + background-color: lightgray; + font-weight: bold; + margin: 0; + padding: 0; + } + + &-item { + padding-left: 1.5rem; + background-position: 0 center; + background-size: contain; + background-repeat: no-repeat; + white-space: nowrap; + + &.vimvixen-completion-selected { + background-color: yellow; + } + + &-caption { + display: inline-block; + width: 40%; + text-overflow: ellipsis; + overflow: hidden; + } + + &-url { + display: inline-block; + color: green; + width: 60%; + text-overflow: ellipsis; + overflow: hidden; + } + } + } + + &-error { + background-color: red; + font-weight: bold; + color: white; + + @include consoole-font; + } + + &-command { + background-color: white; + display: flex; + + &-prompt:before { + content: ':'; + + @include consoole-font; + } + + &-input { + border: none; + flex-grow: 1; + + @include consoole-font; + } + } +} diff --git a/src/pages/settings.html b/src/pages/settings.html new file mode 100644 index 0000000..99d6c6b --- /dev/null +++ b/src/pages/settings.html @@ -0,0 +1,18 @@ + + + + + + +

Configure

+ +

Home page

+
+ + + + +
+ + + diff --git a/src/pages/settings.js b/src/pages/settings.js new file mode 100644 index 0000000..6e00ed3 --- /dev/null +++ b/src/pages/settings.js @@ -0,0 +1,22 @@ +import './settings.scss'; +import messages from '../content/messages'; + +document.addEventListener('DOMContentLoaded', () => { + let form = document.getElementById('vimvixen-settings-form'); + form.addEventListener('submit', (e) => { + e.preventDefault(); + browser.storage.local.set({ + settings: { + json: e.target.elements['plain-json'].value + } + }).then(() => { + return browser.runtime.sendMessage({ + type: messages.SETTINGS_RELOAD + }); + }); + }); + + browser.storage.local.get('settings').then((value) => { + form.elements['plain-json'].value = value.settings.json; + }, console.error); +}); diff --git a/src/pages/settings.scss b/src/pages/settings.scss new file mode 100644 index 0000000..5707c8a --- /dev/null +++ b/src/pages/settings.scss @@ -0,0 +1,8 @@ +.vimvixen-settings-form { + textarea[name=plain-json] { + font-family: monospace; + width: 100%; + min-height: 64ex; + resize: vertical; + } +} diff --git a/src/settings/index.js b/src/settings/index.js deleted file mode 100644 index 2ed060c..0000000 --- a/src/settings/index.js +++ /dev/null @@ -1,22 +0,0 @@ -import './settings.scss'; -import messages from '../messages'; - -document.addEventListener('DOMContentLoaded', () => { - let form = document.getElementById('vimvixen-settings-form'); - form.addEventListener('submit', (e) => { - e.preventDefault(); - browser.storage.local.set({ - settings: { - json: e.target.elements['plain-json'].value - } - }).then(() => { - return browser.runtime.sendMessage({ - type: messages.SETTINGS_RELOAD - }); - }); - }); - - browser.storage.local.get('settings').then((value) => { - form.elements['plain-json'].value = value.settings.json; - }, console.error); -}); diff --git a/src/settings/settings.html b/src/settings/settings.html deleted file mode 100644 index 99d6c6b..0000000 --- a/src/settings/settings.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - -

Configure

- -

Home page

-
- - - - -
- - - diff --git a/src/settings/settings.scss b/src/settings/settings.scss deleted file mode 100644 index 5707c8a..0000000 --- a/src/settings/settings.scss +++ /dev/null @@ -1,8 +0,0 @@ -.vimvixen-settings-form { - textarea[name=plain-json] { - font-family: monospace; - width: 100%; - min-height: 64ex; - resize: vertical; - } -} diff --git a/test/console/completion.test.js b/test/console/completion.test.js deleted file mode 100644 index a789c15..0000000 --- a/test/console/completion.test.js +++ /dev/null @@ -1,48 +0,0 @@ -import { expect } from "chai"; -import Completion from '../../src/console/completion'; - -describe('Completion class', () => { - describe('#constructor', () => { - it('creates new object by iterable items', () => { - new Completion([1,2,3,4,5]); - new Completion([]); - new Completion('hello'); - new Completion(''); - }); - - it('creates new object by iterable items', () => { - expect(() => new Completion({ key: 'value' })).to.throw(TypeError); - expect(() => new Completion(12345)).to.throw(TypeError); - }); - }); - - describe('#next', () => { - it('complete next items', () => { - let completion = new Completion([3, 4, 5]); - expect(completion.next()).to.equal(3); - expect(completion.next()).to.equal(4); - expect(completion.next()).to.equal(5); - expect(completion.next()).to.equal(3); - }); - - it('returns null when empty completions', () => { - let completion = new Completion([]); - expect(completion.next()).to.be.null; - }); - }); - - describe('#prev', () => { - it('complete prev items', () => { - let completion = new Completion([3, 4, 5]); - expect(completion.prev()).to.equal(5); - expect(completion.prev()).to.equal(4); - expect(completion.prev()).to.equal(3); - expect(completion.prev()).to.equal(5); - }); - - it('returns null when empty completions', () => { - let completion = new Completion([]); - expect(completion.prev()).to.be.null; - }); - }); -}); diff --git a/test/pages/completion.test.js b/test/pages/completion.test.js new file mode 100644 index 0000000..28dd9a7 --- /dev/null +++ b/test/pages/completion.test.js @@ -0,0 +1,48 @@ +import { expect } from "chai"; +import Completion from '../../src/pages/completion'; + +describe('Completion class', () => { + describe('#constructor', () => { + it('creates new object by iterable items', () => { + new Completion([1,2,3,4,5]); + new Completion([]); + new Completion('hello'); + new Completion(''); + }); + + it('creates new object by iterable items', () => { + expect(() => new Completion({ key: 'value' })).to.throw(TypeError); + expect(() => new Completion(12345)).to.throw(TypeError); + }); + }); + + describe('#next', () => { + it('complete next items', () => { + let completion = new Completion([3, 4, 5]); + expect(completion.next()).to.equal(3); + expect(completion.next()).to.equal(4); + expect(completion.next()).to.equal(5); + expect(completion.next()).to.equal(3); + }); + + it('returns null when empty completions', () => { + let completion = new Completion([]); + expect(completion.next()).to.be.null; + }); + }); + + describe('#prev', () => { + it('complete prev items', () => { + let completion = new Completion([3, 4, 5]); + expect(completion.prev()).to.equal(5); + expect(completion.prev()).to.equal(4); + expect(completion.prev()).to.equal(3); + expect(completion.prev()).to.equal(5); + }); + + it('returns null when empty completions', () => { + let completion = new Completion([]); + expect(completion.prev()).to.be.null; + }); + }); +}); diff --git a/webpack.config.js b/webpack.config.js index bf121d1..f1ba07a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,9 +7,9 @@ const dist = path.resolve(__dirname, 'build'); module.exports = { entry: { index: path.join(src, 'content'), - settings: path.join(src, 'settings'), + settings: path.join(src, 'pages/settings'), background: path.join(src, 'background'), - console: path.join(src, 'console', 'console.js') + console: path.join(src, 'pages', 'console.js') }, output: { @@ -44,12 +44,12 @@ module.exports = { plugins: [ new HtmlWebpackPlugin({ - template: path.join(src, 'console', 'console.html'), + template: path.join(src, 'pages', 'console.html'), filename: path.join(dist, 'console.html'), inject: false }), new HtmlWebpackPlugin({ - template: path.join(src, 'settings', 'settings.html'), + template: path.join(src, 'pages', 'settings.html'), filename: path.join(dist, 'settings.html'), inject: false }) -- cgit v1.2.3