diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-09-03 03:11:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-03 03:11:10 +0000 |
commit | ab6295d0f136b77534e6e290e165b1035c7abdc2 (patch) | |
tree | 5e435a9396979e4307c783f131f251581b955aac /e2e | |
parent | 07bcc15e7b487fb5815b151e8c7e84a31f875dce (diff) | |
parent | f64b7ca320f73dd523113f0eedca35e176843bd6 (diff) |
Merge pull request #638 from ueokande/qa-0.24
QA 0.24
Diffstat (limited to 'e2e')
-rw-r--r-- | e2e/completion_open.test.js | 2 | ||||
-rw-r--r-- | e2e/options.test.js | 99 | ||||
-rw-r--r-- | e2e/options_form.test.js | 125 |
3 files changed, 225 insertions, 1 deletions
diff --git a/e2e/completion_open.test.js b/e2e/completion_open.test.js index 80628b3..5828768 100644 --- a/e2e/completion_open.test.js +++ b/e2e/completion_open.test.js @@ -44,7 +44,7 @@ describe("completion on open/tabopen/winopen commands", () => { }); // Add item into hitories - await session.navigateTo(`https://i-beam.org`); + await session.navigateTo(`https://i-beam.org/404`); }); after(async() => { diff --git a/e2e/options.test.js b/e2e/options.test.js new file mode 100644 index 0000000..e8045c2 --- /dev/null +++ b/e2e/options.test.js @@ -0,0 +1,99 @@ +const express = require('express'); +const lanthan = require('lanthan'); +const path = require('path'); +const assert = require('assert'); +const eventually = require('./eventually'); + +const newApp = () => { + let app = express(); + app.get('/', (req, res) => { + res.send(`<!DOCTYPEhtml> +<html lang="en"> + <body style="width:10000px; height:10000px"></body> +</html">`); + }); + return app; +}; + +describe("options page", () => { + const port = 12321; + let http; + let firefox; + let session; + let browser; + + before(async() => { + http = newApp().listen(port); + + firefox = await lanthan.firefox({ + spy: path.join(__dirname, '..'), + builderf: (builder) => { + builder.addFile('build/settings.js'); + builder.addFile('build/settings.html'); + }, + }); + await firefox.session.installAddonFromPath(path.join(__dirname, '..')); + session = firefox.session; + browser = firefox.browser; + }); + + after(async() => { + if (firefox) { + await firefox.close(); + } + + http.close(); + }); + + beforeEach(async() => { + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + }) + + const updateTextarea = async(value) => { + let textarea = await session.findElementByCSS('textarea'); + await session.executeScript(`document.querySelector('textarea').value = '${value}'`) + await textarea.sendKeys(' '); + await session.executeScript(() => document.querySelector('textarea').blur()); + } + + it('saves current config on blur', async () => { + let url = await browser.runtime.getURL("build/settings.html") + await session.navigateTo(url); + + await updateTextarea(`{ "blacklist": [ "https://example.com" ] }`); + + let { settings } = await browser.storage.local.get('settings'); + assert.equal(settings.source, 'json') + assert.equal(settings.json, '{ "blacklist": [ "https://example.com" ] } ') + + await updateTextarea(`invalid json`); + + settings = (await browser.storage.local.get('settings')).settings; + assert.equal(settings.source, 'json') + assert.equal(settings.json, '{ "blacklist": [ "https://example.com" ] } ') + + let error = await session.findElementByCSS('.settings-ui-input-error'); + let text = await error.getText(); + assert.ok(text.startsWith('SyntaxError:')) + }); + + it('updates keymaps without reloading', async () => { + await browser.tabs.create({ url: `http://127.0.0.1:${port}`, active: false }); + let url = await browser.runtime.getURL("build/settings.html") + await session.navigateTo(url); + + let handles = await session.getWindowHandles(); + await updateTextarea(`{ "keymaps": { "zz": { "type": "scroll.vertically", "count": 10 } } }`); + + await session.switchToWindow(handles[1]); + + let body = await session.findElementByCSS('body'); + await body.sendKeys('zz') + + let y = await session.executeScript(() => window.pageYOffset); + assert.equal(y, 640); + }) +}); diff --git a/e2e/options_form.test.js b/e2e/options_form.test.js new file mode 100644 index 0000000..f86d995 --- /dev/null +++ b/e2e/options_form.test.js @@ -0,0 +1,125 @@ +const lanthan = require('lanthan'); +const path = require('path'); +const assert = require('assert'); + +describe("options form page", () => { + let firefox; + let session; + let browser; + + beforeEach(async() => { + firefox = await lanthan.firefox({ + spy: path.join(__dirname, '..'), + builderf: (builder) => { + builder.addFile('build/settings.js'); + builder.addFile('build/settings.html'); + }, + }); + await firefox.session.installAddonFromPath(path.join(__dirname, '..')); + session = firefox.session; + browser = firefox.browser; + + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + }) + + afterEach(async() => { + if (firefox) { + await firefox.close(); + } + }) + + const setBlacklistValue = async(nth, value) => { + let selector = '.form-blacklist-form .column-url'; + let input = (await session.findElementsByCSS(selector))[nth]; + await input.sendKeys(value); + await session.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + } + + const setSearchEngineValue = async(nth, name, url) => { + let selector = '.form-search-form input.column-name'; + let input = (await session.findElementsByCSS(selector))[nth]; + await input.sendKeys(name); + await session.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + + selector = '.form-search-form input.column-url'; + input = (await session.findElementsByCSS(selector))[nth]; + await input.sendKeys(url); + await session.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + } + + it('switch to form settings', async () => { + let url = await browser.runtime.getURL("build/settings.html") + await session.navigateTo(url); + + let useFormInput = await session.findElementByCSS('#setting-source-form'); + await useFormInput.click(); + await session.acceptAlert(); + + let { settings } = await browser.storage.local.get('settings'); + assert.equal(settings.source, 'form') + }) + + it('add blacklist', async () => { + let url = await browser.runtime.getURL("build/settings.html") + await session.navigateTo(url); + + let useFormInput = await session.findElementByCSS('#setting-source-form'); + await useFormInput.click(); + await session.acceptAlert(); + await session.executeScript(() => window.scrollBy(0, 1000)); + + // assert default + let settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.blacklist, []) + + // add blacklist items + let addButton = await session.findElementByCSS('.form-blacklist-form .ui-add-button'); + await addButton.click(); + await setBlacklistValue(0, 'google.com') + + settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.blacklist, ['google.com']) + + await addButton.click(); + await setBlacklistValue(1, 'yahoo.com') + + settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.blacklist, ['google.com', 'yahoo.com']) + + // delete first item + let deleteButton = (await session.findElementsByCSS('.form-blacklist-form .ui-delete-button'))[0]; + await deleteButton.click() + + settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.blacklist, ['yahoo.com']) + }); + + it('add search engines', async () => { + let url = await browser.runtime.getURL("build/settings.html") + await session.navigateTo(url); + + let useFormInput = await session.findElementByCSS('#setting-source-form'); + await useFormInput.click(); + await session.acceptAlert(); + + // assert default + let settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.search.default, 'google'); + + // change default + let radio = (await session.findElementsByCSS('.form-search-form input[type=radio]'))[2]; + await radio.click(); + settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.search.default, 'bing'); + + let addButton = await session.findElementByCSS('.form-search-form .ui-add-button'); + await addButton.click(); + await setSearchEngineValue(6, 'yippy', 'https://www.yippy.com/search?query={}'); + + settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.search.engines[6], ['yippy', 'https://www.yippy.com/search?query={}']); + }); +}); |