From 1bc96ed1118c38b4b18035f8e05f2709b53b746b Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 6 Aug 2019 22:04:31 +0900 Subject: My first e2e test for option page --- e2e/options.test.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 e2e/options.test.js (limited to 'e2e') diff --git a/e2e/options.test.js b/e2e/options.test.js new file mode 100644 index 0000000..d386b20 --- /dev/null +++ b/e2e/options.test.js @@ -0,0 +1,66 @@ +const express = require('express'); +const lanthan = require('lanthan'); +const path = require('path'); +const assert = require('assert'); +const eventually = require('./eventually'); + +describe("options page", () => { + let firefox; + let session; + let browser; + + before(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; + }); + + after(async() => { + if (firefox) { + await firefox.close(); + } + }); + + beforeEach(async() => { + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + }) + + it('saves current config on blur', async () => { + let url = await browser.runtime.getURL("build/settings.html") + await session.navigateTo(url); + + let textarea = await session.findElementByCSS('textarea'); + const updateTextarea = async(value) => { + await session.executeScript(`document.querySelector('textarea').value = '${value}'`) + await textarea.sendKeys(' '); + await session.executeScript(() => document.querySelector('textarea').blur()); + } + + 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:')) + }); +}); + -- cgit v1.2.3 From 6f4812ee062d70246d5ad5b80bb12848f24f58f6 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 7 Aug 2019 22:14:57 +0900 Subject: Add e2e test to verify hot-reload of the settings --- QA.md | 26 -------------------------- e2e/options.test.js | 49 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 34 deletions(-) (limited to 'e2e') diff --git a/QA.md b/QA.md index 5eabd01..8453b78 100644 --- a/QA.md +++ b/QA.md @@ -25,32 +25,6 @@ The behaviors of the console are tested in [Console section](#consoles). ### Settings -#### JSON Settings - -##### Validations - -- [ ] show error on invalid json -- [ ] show error when top-level keys has keys other than `keymaps`, `search`, `blacklist`, and `properties` - -###### `"keymaps"` section - -- [ ] show error on unknown operation name in `"keymaps"` - -###### `"search"` section - -- validations in `"search"` section are not tested in this release - -##### Updating - -- [ ] changes are updated on textarea blure when no errors -- [ ] keymap settings are applied to open tabs without reload -- [ ] search settings are applied to open tabs without reload - -##### Properties - -- [ ] show errors when invalid property name -- [ ] show errors when invalid property type - #### Form Settings diff --git a/e2e/options.test.js b/e2e/options.test.js index d386b20..e8045c2 100644 --- a/e2e/options.test.js +++ b/e2e/options.test.js @@ -4,12 +4,27 @@ const path = require('path'); const assert = require('assert'); const eventually = require('./eventually'); +const newApp = () => { + let app = express(); + app.get('/', (req, res) => { + res.send(` + + +`); + }); + 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) => { @@ -26,6 +41,8 @@ describe("options page", () => { if (firefox) { await firefox.close(); } + + http.close(); }); beforeEach(async() => { @@ -35,17 +52,17 @@ describe("options page", () => { } }) + 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); - let textarea = await session.findElementByCSS('textarea'); - const updateTextarea = async(value) => { - await session.executeScript(`document.querySelector('textarea').value = '${value}'`) - await textarea.sendKeys(' '); - await session.executeScript(() => document.querySelector('textarea').blur()); - } - await updateTextarea(`{ "blacklist": [ "https://example.com" ] }`); let { settings } = await browser.storage.local.get('settings'); @@ -62,5 +79,21 @@ describe("options page", () => { 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); + }) +}); -- cgit v1.2.3 From ac93834ddca15e0929737bc99a5284039f4238b8 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 19 Aug 2019 22:24:50 +0900 Subject: Add option form page --- QA.md | 14 -------- e2e/options_form.test.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 e2e/options_form.test.js (limited to 'e2e') diff --git a/QA.md b/QA.md index 8453b78..7c23e80 100644 --- a/QA.md +++ b/QA.md @@ -37,8 +37,6 @@ The behaviors of the console are tested in [Console section](#consoles). ##### `"blacklist"` section -- [ ] able to add item -- [ ] able to remove item - [ ] `github.com/a` blocks `github.com/a`, and not blocks `github.com/aa` ##### Updating @@ -46,12 +44,6 @@ The behaviors of the console are tested in [Console section](#consoles). - [ ] keymap settings are applied to open tabs without reload - [ ] search settings are applied to open tabs without reload -### Settings source - -- [ ] show confirmation dialog on switched from json to form -- [ ] state is saved on source changed -- [ ] on switching form -> json -> form, first and last form setting is equivalent to first one - ## Find mode - [ ] open console with / @@ -60,9 +52,3 @@ The behaviors of the console are tested in [Console section](#consoles). - [ ] Wrap search by n/N - [ ] Find with last keyword if keyword is empty - [ ] Find keyword last used on new tab opened - -## Misc - -- [ ] Work on `about:blank` -- [ ] Able to map `` key. -- [ ] Open file menu by Alt+F (Other than Mac OS) diff --git a/e2e/options_form.test.js b/e2e/options_form.test.js new file mode 100644 index 0000000..d665f1c --- /dev/null +++ b/e2e/options_form.test.js @@ -0,0 +1,83 @@ +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()`); + } + + 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(); + + let settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.blacklist, []) + + 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']) + + 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']) + }); +}); -- cgit v1.2.3 From cd549234b457e868f11624de9fd2cdd533a63e06 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 20 Aug 2019 22:11:45 +0900 Subject: Add search engine e2e test --- QA.md | 8 -------- e2e/options_form.test.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) (limited to 'e2e') diff --git a/QA.md b/QA.md index 7c23e80..98b8239 100644 --- a/QA.md +++ b/QA.md @@ -27,14 +27,6 @@ The behaviors of the console are tested in [Console section](#consoles). #### Form Settings - - -##### Search Engines - -- [ ] able to change default -- [ ] able to remove item -- [ ] able to add item - ##### `"blacklist"` section - [ ] `github.com/a` blocks `github.com/a`, and not blocks `github.com/aa` diff --git a/e2e/options_form.test.js b/e2e/options_form.test.js index d665f1c..67ab0ba 100644 --- a/e2e/options_form.test.js +++ b/e2e/options_form.test.js @@ -38,6 +38,18 @@ describe("options form page", () => { 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); @@ -58,9 +70,11 @@ describe("options form page", () => { await useFormInput.click(); await session.acceptAlert(); + // 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') @@ -74,10 +88,37 @@ describe("options form page", () => { 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.only('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={}']); + }); }); -- cgit v1.2.3 From 807ba97c4f6e0305d7a319d9133609fc31011990 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 29 Aug 2019 23:25:49 +0900 Subject: Remove only --- e2e/options_form.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'e2e') diff --git a/e2e/options_form.test.js b/e2e/options_form.test.js index 67ab0ba..5779ddc 100644 --- a/e2e/options_form.test.js +++ b/e2e/options_form.test.js @@ -96,7 +96,7 @@ describe("options form page", () => { assert.deepEqual(settings.form.blacklist, ['yahoo.com']) }); - it.only('add search engines', async () => { + it('add search engines', async () => { let url = await browser.runtime.getURL("build/settings.html") await session.navigateTo(url); -- cgit v1.2.3 From fd7509276e5f93666bca57bbfaef0b1ce78f1021 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 2 Sep 2019 22:16:38 +0900 Subject: Scroll to bottom on setting page --- e2e/options_form.test.js | 1 + 1 file changed, 1 insertion(+) (limited to 'e2e') diff --git a/e2e/options_form.test.js b/e2e/options_form.test.js index 5779ddc..f86d995 100644 --- a/e2e/options_form.test.js +++ b/e2e/options_form.test.js @@ -69,6 +69,7 @@ describe("options form page", () => { 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; -- cgit v1.2.3 From f64b7ca320f73dd523113f0eedca35e176843bd6 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 2 Sep 2019 22:42:31 +0900 Subject: Use 404 page --- e2e/completion_open.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'e2e') 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() => { -- cgit v1.2.3