From 4d36a203c09d2e04bf4304ba4a5b63f66b3e2adf Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 21 Sep 2019 15:32:30 +0900 Subject: Use latest lanthan --- e2e/zoom.test.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'e2e/zoom.test.js') diff --git a/e2e/zoom.test.js b/e2e/zoom.test.js index 186f67f..c11ed1e 100644 --- a/e2e/zoom.test.js +++ b/e2e/zoom.test.js @@ -1,36 +1,34 @@ const express = require('express'); -const lanthan = require('lanthan'); +const { Builder } = require('lanthan'); const path = require('path'); const assert = require('assert'); const eventually = require('./eventually'); - -const Key = lanthan.Key; +const { Key, By } = require('selenium-webdriver'); describe("zoom test", () => { - - let firefox; - let session; + let lanthan; + let webdriver; let browser; let tab; let body; before(async() => { - firefox = await lanthan.firefox(); - await firefox.session.installAddonFromPath(path.join(__dirname, '..')); - session = firefox.session; - browser = firefox.browser; + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); tab = (await browser.tabs.query({}))[0] }); after(async() => { - if (firefox) { - await firefox.close(); - } + await lanthan.quit(); }); beforeEach(async() => { - await session.navigateTo('about:blank'); - body = await session.findElementByCSS('body'); + await webdriver.navigate().to('about:blank'); + body = await webdriver.findElement(By.css('body')); }); it('should zoom in by zi', async () => { -- cgit v1.2.3 From 7e77e31ad64c3649888eae337e0c984fd9c2ea2a Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 22 Sep 2019 16:13:12 +0900 Subject: Migrate e2e tests to TypeScript --- e2e/blacklist.test.js | 76 ----------- e2e/blacklist.test.ts | 74 +++++++++++ e2e/clipboard.test.js | 123 ------------------ e2e/clipboard.test.ts | 125 ++++++++++++++++++ e2e/command_addbookmark.test.js | 64 ---------- e2e/command_addbookmark.test.ts | 66 ++++++++++ e2e/command_bdelete.test.js | 199 ----------------------------- e2e/command_bdelete.test.ts | 201 +++++++++++++++++++++++++++++ e2e/command_buffer.test.js | 198 ---------------------------- e2e/command_buffer.test.ts | 200 +++++++++++++++++++++++++++++ e2e/command_open.test.js | 146 --------------------- e2e/command_open.test.ts | 148 +++++++++++++++++++++ e2e/command_quit.test.js | 121 ------------------ e2e/command_quit.test.ts | 124 ++++++++++++++++++ e2e/command_tabopen.test.js | 157 ----------------------- e2e/command_tabopen.test.ts | 160 +++++++++++++++++++++++ e2e/command_winopen.test.js | 168 ------------------------ e2e/command_winopen.test.ts | 170 +++++++++++++++++++++++++ e2e/completion.test.js | 133 ------------------- e2e/completion.test.ts | 135 ++++++++++++++++++++ e2e/completion_buffers.test.js | 211 ------------------------------ e2e/completion_buffers.test.ts | 213 +++++++++++++++++++++++++++++++ e2e/completion_open.test.js | 256 ------------------------------------- e2e/completion_open.test.ts | 257 +++++++++++++++++++++++++++++++++++++ e2e/completion_set.test.js | 73 ----------- e2e/completion_set.test.ts | 71 +++++++++++ e2e/console.test.js | 128 ------------------- e2e/console.test.ts | 126 ++++++++++++++++++ e2e/eventually.js | 23 ---- e2e/eventually.ts | 30 +++++ e2e/follow.test.js | 263 -------------------------------------- e2e/follow.test.ts | 265 ++++++++++++++++++++++++++++++++++++++ e2e/follow_properties.test.js | 180 -------------------------- e2e/follow_properties.test.ts | 174 +++++++++++++++++++++++++ e2e/lib/Console.js | 43 ------- e2e/lib/Console.ts | 49 +++++++ e2e/lib/clipboard.js | 63 --------- e2e/lib/clipboard.ts | 66 ++++++++++ e2e/mark.test.js | 124 ------------------ e2e/mark.test.ts | 126 ++++++++++++++++++ e2e/navigate.test.js | 274 --------------------------------------- e2e/navigate.test.ts | 276 ++++++++++++++++++++++++++++++++++++++++ e2e/options.test.js | 97 -------------- e2e/options.test.ts | 98 ++++++++++++++ e2e/options_form.test.js | 122 ------------------ e2e/options_form.test.ts | 124 ++++++++++++++++++ e2e/repeat.test.js | 95 -------------- e2e/repeat.test.ts | 94 ++++++++++++++ e2e/scroll.test.js | 153 ---------------------- e2e/scroll.test.ts | 154 ++++++++++++++++++++++ e2e/settings.js | 86 ------------- e2e/settings.ts | 86 +++++++++++++ e2e/tab.test.js | 222 -------------------------------- e2e/tab.test.ts | 222 ++++++++++++++++++++++++++++++++ e2e/zoom.test.js | 64 ---------- e2e/zoom.test.ts | 65 ++++++++++ 56 files changed, 3899 insertions(+), 3862 deletions(-) delete mode 100644 e2e/blacklist.test.js create mode 100644 e2e/blacklist.test.ts delete mode 100644 e2e/clipboard.test.js create mode 100644 e2e/clipboard.test.ts delete mode 100644 e2e/command_addbookmark.test.js create mode 100644 e2e/command_addbookmark.test.ts delete mode 100644 e2e/command_bdelete.test.js create mode 100644 e2e/command_bdelete.test.ts delete mode 100644 e2e/command_buffer.test.js create mode 100644 e2e/command_buffer.test.ts delete mode 100644 e2e/command_open.test.js create mode 100644 e2e/command_open.test.ts delete mode 100644 e2e/command_quit.test.js create mode 100644 e2e/command_quit.test.ts delete mode 100644 e2e/command_tabopen.test.js create mode 100644 e2e/command_tabopen.test.ts delete mode 100644 e2e/command_winopen.test.js create mode 100644 e2e/command_winopen.test.ts delete mode 100644 e2e/completion.test.js create mode 100644 e2e/completion.test.ts delete mode 100644 e2e/completion_buffers.test.js create mode 100644 e2e/completion_buffers.test.ts delete mode 100644 e2e/completion_open.test.js create mode 100644 e2e/completion_open.test.ts delete mode 100644 e2e/completion_set.test.js create mode 100644 e2e/completion_set.test.ts delete mode 100644 e2e/console.test.js create mode 100644 e2e/console.test.ts delete mode 100644 e2e/eventually.js create mode 100644 e2e/eventually.ts delete mode 100644 e2e/follow.test.js create mode 100644 e2e/follow.test.ts delete mode 100644 e2e/follow_properties.test.js create mode 100644 e2e/follow_properties.test.ts delete mode 100644 e2e/lib/Console.js create mode 100644 e2e/lib/Console.ts delete mode 100644 e2e/lib/clipboard.js create mode 100644 e2e/lib/clipboard.ts delete mode 100644 e2e/mark.test.js create mode 100644 e2e/mark.test.ts delete mode 100644 e2e/navigate.test.js create mode 100644 e2e/navigate.test.ts delete mode 100644 e2e/options.test.js create mode 100644 e2e/options.test.ts delete mode 100644 e2e/options_form.test.js create mode 100644 e2e/options_form.test.ts delete mode 100644 e2e/repeat.test.js create mode 100644 e2e/repeat.test.ts delete mode 100644 e2e/scroll.test.js create mode 100644 e2e/scroll.test.ts delete mode 100644 e2e/settings.js create mode 100644 e2e/settings.ts delete mode 100644 e2e/tab.test.js create mode 100644 e2e/tab.test.ts delete mode 100644 e2e/zoom.test.js create mode 100644 e2e/zoom.test.ts (limited to 'e2e/zoom.test.js') diff --git a/e2e/blacklist.test.js b/e2e/blacklist.test.js deleted file mode 100644 index 8a8996e..0000000 --- a/e2e/blacklist.test.js +++ /dev/null @@ -1,76 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By } = require('selenium-webdriver'); - -const newApp = () => { - let app = express(); - app.get('/*', (req, res) => { - res.status(200).send(` - - -`); - }); - return app; -}; - -describe("navigate test", () => { - - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - - before(async() => { - http = newApp().listen(port); - - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - }); - - after(async() => { - if (lanthan) { - await lanthan.quit(); - } - http.close(); - }); - - it('should disable add-on if the URL is in the blacklist', async () => { - await browser.storage.local.set({ - settings: { - source: 'json', - json: `{ - "keymaps": { - "j": { "type": "scroll.vertically", "count": 1 } - }, - "blacklist": [ "127.0.0.1:${port}/a" ] - }`, - }, - }); - - await webdriver.navigate().to(`http://127.0.0.1:${port}/a`); - - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys('j'); - - // not works - let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); - assert.equal(pageYOffset, 0); - - await webdriver.navigate().to(`http://127.0.0.1:${port}/ab`); - body = await webdriver.findElement(By.css('body')); - await body.sendKeys('j'); - - // works - pageYOffset = await webdriver.executeScript(() => window.pageYOffset); - assert.equal(pageYOffset, 64); - }); -}); - diff --git a/e2e/blacklist.test.ts b/e2e/blacklist.test.ts new file mode 100644 index 0000000..c88f655 --- /dev/null +++ b/e2e/blacklist.test.ts @@ -0,0 +1,74 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By } from 'selenium-webdriver'; +import * as http from 'http'; + +const newApp = () => { + let app = express(); + app.get('/*', (_req, res) => { + res.status(200).send(` + + +`); + }); + return app; +}; + +describe("navigate test", () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + + before(async() => { + http = newApp().listen(port); + + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + }); + + after(async() => { + if (lanthan) { + await lanthan.quit(); + } + http.close(); + }); + + it('should disable add-on if the URL is in the blacklist', async () => { + await browser.storage.local.set({ + settings: { + source: 'json', + json: `{ + "keymaps": { + "j": { "type": "scroll.vertically", "count": 1 } + }, + "blacklist": [ "127.0.0.1:${port}/a" ] + }`, + }, + }); + + await webdriver.navigate().to(`http://127.0.0.1:${port}/a`); + + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys('j'); + + // not works + let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); + assert.equal(pageYOffset, 0); + + await webdriver.navigate().to(`http://127.0.0.1:${port}/ab`); + body = await webdriver.findElement(By.css('body')); + await body.sendKeys('j'); + + // works + pageYOffset = await webdriver.executeScript(() => window.pageYOffset); + assert.equal(pageYOffset, 64); + }); +}); diff --git a/e2e/clipboard.test.js b/e2e/clipboard.test.js deleted file mode 100644 index df31770..0000000 --- a/e2e/clipboard.test.js +++ /dev/null @@ -1,123 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const clipboard = require('./lib/clipboard'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); - -const newApp = () => { - let app = express(); - app.get('/', (req, res) => { - res.status(200).send(``); - }); - return app; -}; - -describe("navigate test", () => { - - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - - before(async() => { - http = newApp().listen(port); - - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - - await browser.storage.local.set({ - settings, - }); - }); - - after(async() => { - if (lanthan) { - await lanthan.quit(); - } - http.close(); - }); - - beforeEach(async() => { - let tabs = await browser.tabs.query({}); - for (let tab of tabs.slice(1)) { - await browser.tabs.remove(tab.id); - } - }) - - it('should copy current URL by y', async () => { - await webdriver.navigate().to(`http://127.0.0.1:${port}/#should_copy_url`); - let body = await webdriver.findElement(By.css('body')); - - await body.sendKeys('y'); - await eventually(async() => { - let data = await clipboard.read(); - assert.equal(data, `http://127.0.0.1:${port}/#should_copy_url`); - }); - }); - - it('should open an URL from clipboard by p', async () => { - await webdriver.navigate().to(`http://127.0.0.1:${port}/`); - let body = await webdriver.findElement(By.css('body')); - - await clipboard.write(`http://127.0.0.1:${port}/#open_from_clipboard`); - await body.sendKeys('p'); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }); - assert.equal(tabs[0].url, `http://127.0.0.1:${port}/#open_from_clipboard`); - }); - }); - - it('should open an URL from clipboard to new tab by P', async () => { - await webdriver.navigate().to(`http://127.0.0.1:${port}/`); - let body = await webdriver.findElement(By.css('body')); - - await clipboard.write(`http://127.0.0.1:${port}/#open_to_new_tab`); - await body.sendKeys(Key.SHIFT, 'p'); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ - `http://127.0.0.1:${port}/`, - `http://127.0.0.1:${port}/#open_to_new_tab`, - ]); - }); - }); - - it('should open search result with keywords in clipboard by p', async () => { - await webdriver.navigate().to(`http://127.0.0.1:${port}/`); - let body = await webdriver.findElement(By.css('body')); - - await clipboard.write(`an apple`); - await body.sendKeys('p'); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs[0].url, `http://127.0.0.1:${port}/google?q=an%20apple`); - }); - }); - - it('should open search result with keywords in clipboard to new tabby P', async () => { - await webdriver.navigate().to(`http://127.0.0.1:${port}/`); - let body = await webdriver.findElement(By.css('body')); - - await clipboard.write(`an apple`); - await body.sendKeys(Key.SHIFT, 'p'); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ - `http://127.0.0.1:${port}/`, - `http://127.0.0.1:${port}/google?q=an%20apple`, - ]); - }); - }); -}); diff --git a/e2e/clipboard.test.ts b/e2e/clipboard.test.ts new file mode 100644 index 0000000..dbc00de --- /dev/null +++ b/e2e/clipboard.test.ts @@ -0,0 +1,125 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import * as clipboard from './lib/clipboard'; +import settings from './settings'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; + +const newApp = () => { + let app = express(); + app.get('/', (_req, res) => { + res.status(200).send(``); + }); + return app; +}; + +describe("navigate test", () => { + + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + + before(async() => { + http = newApp().listen(port); + + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + + await browser.storage.local.set({ + settings, + }); + }); + + after(async() => { + if (lanthan) { + await lanthan.quit(); + } + http.close(); + }); + + beforeEach(async() => { + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + }) + + it('should copy current URL by y', async () => { + await webdriver.navigate().to(`http://127.0.0.1:${port}/#should_copy_url`); + let body = await webdriver.findElement(By.css('body')); + + await body.sendKeys('y'); + await eventually(async() => { + let data = await clipboard.read(); + assert.equal(data, `http://127.0.0.1:${port}/#should_copy_url`); + }); + }); + + it('should open an URL from clipboard by p', async () => { + await webdriver.navigate().to(`http://127.0.0.1:${port}/`); + let body = await webdriver.findElement(By.css('body')); + + await clipboard.write(`http://127.0.0.1:${port}/#open_from_clipboard`); + await body.sendKeys('p'); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }); + assert.equal(tabs[0].url, `http://127.0.0.1:${port}/#open_from_clipboard`); + }); + }); + + it('should open an URL from clipboard to new tab by P', async () => { + await webdriver.navigate().to(`http://127.0.0.1:${port}/`); + let body = await webdriver.findElement(By.css('body')); + + await clipboard.write(`http://127.0.0.1:${port}/#open_to_new_tab`); + await body.sendKeys(Key.SHIFT, 'p'); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.deepEqual(tabs.map((t: any) => t.url), [ + `http://127.0.0.1:${port}/`, + `http://127.0.0.1:${port}/#open_to_new_tab`, + ]); + }); + }); + + it('should open search result with keywords in clipboard by p', async () => { + await webdriver.navigate().to(`http://127.0.0.1:${port}/`); + let body = await webdriver.findElement(By.css('body')); + + await clipboard.write(`an apple`); + await body.sendKeys('p'); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs[0].url, `http://127.0.0.1:${port}/google?q=an%20apple`); + }); + }); + + it('should open search result with keywords in clipboard to new tabby P', async () => { + await webdriver.navigate().to(`http://127.0.0.1:${port}/`); + let body = await webdriver.findElement(By.css('body')); + + await clipboard.write(`an apple`); + await body.sendKeys(Key.SHIFT, 'p'); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.deepEqual(tabs.map((t: any) => t.url), [ + `http://127.0.0.1:${port}/`, + `http://127.0.0.1:${port}/google?q=an%20apple`, + ]); + }); + }); +}); diff --git a/e2e/command_addbookmark.test.js b/e2e/command_addbookmark.test.js deleted file mode 100644 index 68d1c6d..0000000 --- a/e2e/command_addbookmark.test.js +++ /dev/null @@ -1,64 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); - -const newApp = () => { - let app = express(); - app.get('/happy', (req, res) => { - res.send(` - - - how to be happy - -`); - }); - return app; -}; - -describe('addbookmark command test', () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - - before(async() => { - http = newApp().listen(port); - - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - await webdriver.navigate().to(`http://127.0.0.1:${port}/happy`); - }); - - it('should add a bookmark from the current page', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('addbookmark how to be happy', Key.ENTER); - - await eventually(async() => { - var bookmarks = await browser.bookmarks.search({ title: 'how to be happy' }); - assert.equal(bookmarks.length, 1); - assert.equal(bookmarks[0].url, `http://127.0.0.1:${port}/happy`); - }); - }); -}); diff --git a/e2e/command_addbookmark.test.ts b/e2e/command_addbookmark.test.ts new file mode 100644 index 0000000..ad94494 --- /dev/null +++ b/e2e/command_addbookmark.test.ts @@ -0,0 +1,66 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; + +const newApp = () => { + let app = express(); + app.get('/happy', (_req, res) => { + res.send(` + + + how to be happy + +`); + }); + return app; +}; + +describe('addbookmark command test', () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + + before(async() => { + http = newApp().listen(port); + + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + await webdriver.navigate().to(`http://127.0.0.1:${port}/happy`); + }); + + it('should add a bookmark from the current page', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('addbookmark how to be happy', Key.ENTER); + + await eventually(async() => { + var bookmarks = await browser.bookmarks.search({ title: 'how to be happy' }); + assert.equal(bookmarks.length, 1); + assert.equal(bookmarks[0].url, `http://127.0.0.1:${port}/happy`); + }); + }); +}); diff --git a/e2e/command_bdelete.test.js b/e2e/command_bdelete.test.js deleted file mode 100644 index aae5b67..0000000 --- a/e2e/command_bdelete.test.js +++ /dev/null @@ -1,199 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); - -const newApp = () => { - let app = express(); - app.get('/*', (req, res) => { - res.send(` - - - my_${req.path.slice(1)} - -

${req.path}

-`); - }); - return app; -}; - -describe('bdelete/bdeletes command test', () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - - before(async() => { - http = newApp().listen(port); - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - let tabs = await browser.tabs.query({}); - for (let tab of tabs.slice(1)) { - await browser.tabs.remove(tab.id); - } - await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1`, pinned: true }); - await browser.tabs.create({ url: `http://127.0.0.1:${port}/site2`, pinned: true }) - await browser.tabs.create({ url: `http://127.0.0.1:${port}/site3`, pinned: true }) - await browser.tabs.create({ url: `http://127.0.0.1:${port}/site4` }) - await browser.tabs.create({ url: `http://127.0.0.1:${port}/site5` }) - - await eventually(async() => { - let handles = await webdriver.getAllWindowHandles(); - assert.equal(handles.length, 5); - await webdriver.switchTo().window(handles[2]); - await webdriver.findElement(By.css('iframe')); - }); - - await new Promise((resolve) => setTimeout(resolve, 100)); - }); - - it('should delete an unpinned tab by bdelete command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('bdelete site5', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ - `http://127.0.0.1:${port}/site1`, - `http://127.0.0.1:${port}/site2`, - `http://127.0.0.1:${port}/site3`, - `http://127.0.0.1:${port}/site4`, - ]) - }); - }); - - it('should not delete an pinned tab by bdelete command by bdelete command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('bdelete site1', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 5); - }); - }); - - it('should show an error when no tabs are matched by bdelete command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('bdelete xyz', Key.ENTER); - - await eventually(async() => { - let p = await webdriver.findElement(By.css('.vimvixen-console-error')); - let text = await p.getText(); - assert.equal(text, 'No matching buffer for xyz'); - }); - }); - - it('should show an error when more than one tabs are matched by bdelete command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('bdelete site', Key.ENTER); - - await eventually(async() => { - let p = await webdriver.findElement(By.css('.vimvixen-console-error')); - let text = await p.getText(); - assert.equal(text, 'More than one match for site'); - }); - }); - - it('should delete an unpinned tab by bdelete! command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('bdelete! site5', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ - `http://127.0.0.1:${port}/site1`, - `http://127.0.0.1:${port}/site2`, - `http://127.0.0.1:${port}/site3`, - `http://127.0.0.1:${port}/site4`, - ]) - }); - }); - - it('should delete an pinned tab by bdelete! command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('bdelete! site1', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ - `http://127.0.0.1:${port}/site2`, - `http://127.0.0.1:${port}/site3`, - `http://127.0.0.1:${port}/site4`, - `http://127.0.0.1:${port}/site5`, - ]) - }); - }); - - it('should delete unpinned tabs by bdeletes command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('bdeletes site', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ - `http://127.0.0.1:${port}/site1`, - `http://127.0.0.1:${port}/site2`, - `http://127.0.0.1:${port}/site3`, - ]) - }); - }); - - it('should delete both pinned and unpinned tabs by bdeletes! command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('bdeletes! site', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 1); - }); - }); -}); diff --git a/e2e/command_bdelete.test.ts b/e2e/command_bdelete.test.ts new file mode 100644 index 0000000..ce54b23 --- /dev/null +++ b/e2e/command_bdelete.test.ts @@ -0,0 +1,201 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; + +const newApp = () => { + let app = express(); + app.get('/*', (req, res) => { + res.send(` + + + my_${req.path.slice(1)} + +

${req.path}

+`); + }); + return app; +}; + +describe('bdelete/bdeletes command test', () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + + before(async() => { + http = newApp().listen(port); + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1`, pinned: true }); + await browser.tabs.create({ url: `http://127.0.0.1:${port}/site2`, pinned: true }) + await browser.tabs.create({ url: `http://127.0.0.1:${port}/site3`, pinned: true }) + await browser.tabs.create({ url: `http://127.0.0.1:${port}/site4` }) + await browser.tabs.create({ url: `http://127.0.0.1:${port}/site5` }) + + await eventually(async() => { + let handles = await webdriver.getAllWindowHandles(); + assert.equal(handles.length, 5); + await webdriver.switchTo().window(handles[2]); + await webdriver.findElement(By.css('iframe')); + }); + + await new Promise((resolve) => setTimeout(resolve, 100)); + }); + + it('should delete an unpinned tab by bdelete command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('bdelete site5', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.deepEqual(tabs.map((t: any) => t.url), [ + `http://127.0.0.1:${port}/site1`, + `http://127.0.0.1:${port}/site2`, + `http://127.0.0.1:${port}/site3`, + `http://127.0.0.1:${port}/site4`, + ]) + }); + }); + + it('should not delete an pinned tab by bdelete command by bdelete command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('bdelete site1', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 5); + }); + }); + + it('should show an error when no tabs are matched by bdelete command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('bdelete xyz', Key.ENTER); + + await eventually(async() => { + let p = await webdriver.findElement(By.css('.vimvixen-console-error')); + let text = await p.getText(); + assert.equal(text, 'No matching buffer for xyz'); + }); + }); + + it('should show an error when more than one tabs are matched by bdelete command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('bdelete site', Key.ENTER); + + await eventually(async() => { + let p = await webdriver.findElement(By.css('.vimvixen-console-error')); + let text = await p.getText(); + assert.equal(text, 'More than one match for site'); + }); + }); + + it('should delete an unpinned tab by bdelete! command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('bdelete! site5', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.deepEqual(tabs.map((t: any) => t.url), [ + `http://127.0.0.1:${port}/site1`, + `http://127.0.0.1:${port}/site2`, + `http://127.0.0.1:${port}/site3`, + `http://127.0.0.1:${port}/site4`, + ]) + }); + }); + + it('should delete an pinned tab by bdelete! command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('bdelete! site1', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.deepEqual(tabs.map((t: any) => t.url), [ + `http://127.0.0.1:${port}/site2`, + `http://127.0.0.1:${port}/site3`, + `http://127.0.0.1:${port}/site4`, + `http://127.0.0.1:${port}/site5`, + ]) + }); + }); + + it('should delete unpinned tabs by bdeletes command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('bdeletes site', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.deepEqual(tabs.map((t: any) => t.url), [ + `http://127.0.0.1:${port}/site1`, + `http://127.0.0.1:${port}/site2`, + `http://127.0.0.1:${port}/site3`, + ]) + }); + }); + + it('should delete both pinned and unpinned tabs by bdeletes! command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('bdeletes! site', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 1); + }); + }); +}); diff --git a/e2e/command_buffer.test.js b/e2e/command_buffer.test.js deleted file mode 100644 index b3336dc..0000000 --- a/e2e/command_buffer.test.js +++ /dev/null @@ -1,198 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); - -const newApp = () => { - let app = express(); - app.get('/*', (req, res) => { - res.send(` - - - my_${req.path.slice(1)} - -

${req.path}

-`); - }); - return app; -}; - -describe('buffer command test', () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - - before(async() => { - http = newApp().listen(port); - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - let tabs = await browser.tabs.query({}); - for (let tab of tabs.slice(1)) { - await browser.tabs.remove(tab.id); - } - await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1` }); - for (let i = 2; i <= 5; ++i) { - await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}`}) - } - - await eventually(async() => { - let handles = await webdriver.getAllWindowHandles(); - assert.equal(handles.length, 5); - await webdriver.switchTo().window(handles[2]); - await webdriver.findElement(By.css('iframe')); - }); - - await new Promise((resolve) => setTimeout(resolve, 100)); - }); - - it('should do nothing by buffer command with no parameters', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('buffer', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }); - assert.equal(tabs[0].index, 2); - }); - }); - - it('should select a tab by buffer command with a number', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('buffer', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }); - assert.equal(tabs[0].index, 2); - }); - }); - - it('should should an out of range error by buffer commands', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('buffer 0', Key.ENTER); - - await eventually(async() => { - let p = await webdriver.findElement(By.css('.vimvixen-console-error')); - let text = await p.getText(); - assert.equal(text, 'tab 0 does not exist'); - }); - - await webdriver.switchTo().parentFrame(); - body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - input = await webdriver.findElement(By.css('input')); - await input.sendKeys('buffer 9', Key.ENTER); - - await eventually(async() => { - let p = await webdriver.findElement(By.css('.vimvixen-console-error')); - let text = await p.getText(); - assert.equal(text, 'tab 9 does not exist'); - }); - }); - - it('should select a tab by buffer command with a title', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('buffer my_site1', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }); - assert.equal(tabs[0].index, 0); - }); - }); - - it('should select a tab by buffer command with an URL', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('buffer /site1', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }); - assert.equal(tabs[0].index, 0); - }); - }); - - it('should select tabs rotately', async() => { - let handles = await webdriver.getAllWindowHandles(); - await webdriver.switchTo().window(handles[4]); - - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('buffer site', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }); - assert.equal(tabs[0].index, 0); - }); - }); - - it('should do nothing by ":buffer %"', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('buffer %', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }); - assert.equal(tabs[0].index, 2); - }); - }); - - it('should selects last selected tab by ":buffer #"', async() => { - let handles = await webdriver.getAllWindowHandles(); - await webdriver.switchTo().window(handles[1]); - - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('buffer #', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }); - assert.equal(tabs[0].index, 2); - }); - }); -}); diff --git a/e2e/command_buffer.test.ts b/e2e/command_buffer.test.ts new file mode 100644 index 0000000..e642673 --- /dev/null +++ b/e2e/command_buffer.test.ts @@ -0,0 +1,200 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; + +const newApp = () => { + let app = express(); + app.get('/*', (req, res) => { + res.send(` + + + my_${req.path.slice(1)} + +

${req.path}

+`); + }); + return app; +}; + +describe('buffer command test', () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + + before(async() => { + http = newApp().listen(port); + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1` }); + for (let i = 2; i <= 5; ++i) { + await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}`}) + } + + await eventually(async() => { + let handles = await webdriver.getAllWindowHandles(); + assert.equal(handles.length, 5); + await webdriver.switchTo().window(handles[2]); + await webdriver.findElement(By.css('iframe')); + }); + + await new Promise((resolve) => setTimeout(resolve, 100)); + }); + + it('should do nothing by buffer command with no parameters', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('buffer', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }); + assert.equal(tabs[0].index, 2); + }); + }); + + it('should select a tab by buffer command with a number', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('buffer', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }); + assert.equal(tabs[0].index, 2); + }); + }); + + it('should should an out of range error by buffer commands', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('buffer 0', Key.ENTER); + + await eventually(async() => { + let p = await webdriver.findElement(By.css('.vimvixen-console-error')); + let text = await p.getText(); + assert.equal(text, 'tab 0 does not exist'); + }); + + await (webdriver.switchTo() as any).parentFrame(); + body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + input = await webdriver.findElement(By.css('input')); + await input.sendKeys('buffer 9', Key.ENTER); + + await eventually(async() => { + let p = await webdriver.findElement(By.css('.vimvixen-console-error')); + let text = await p.getText(); + assert.equal(text, 'tab 9 does not exist'); + }); + }); + + it('should select a tab by buffer command with a title', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('buffer my_site1', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }); + assert.equal(tabs[0].index, 0); + }); + }); + + it('should select a tab by buffer command with an URL', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('buffer /site1', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }); + assert.equal(tabs[0].index, 0); + }); + }); + + it('should select tabs rotately', async() => { + let handles = await webdriver.getAllWindowHandles(); + await webdriver.switchTo().window(handles[4]); + + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('buffer site', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }); + assert.equal(tabs[0].index, 0); + }); + }); + + it('should do nothing by ":buffer %"', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('buffer %', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }); + assert.equal(tabs[0].index, 2); + }); + }); + + it('should selects last selected tab by ":buffer #"', async() => { + let handles = await webdriver.getAllWindowHandles(); + await webdriver.switchTo().window(handles[1]); + + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('buffer #', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }); + assert.equal(tabs[0].index, 2); + }); + }); +}); diff --git a/e2e/command_open.test.js b/e2e/command_open.test.js deleted file mode 100644 index ccf7393..0000000 --- a/e2e/command_open.test.js +++ /dev/null @@ -1,146 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); - -const newApp = () => { - - let app = express(); - for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) { - app.get('/' + name, (req, res) => { - res.send(` - -

${name.charAt(0).toUpperCase() + name.slice(1)}

-`); - }); - } - app.get('/', (req, res) => { - res.send(` - -

home

-`); - }); - return app; -}; - -describe("open command test", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; - - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - http = newApp().listen(port); - - await browser.storage.local.set({ - settings, - }); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - await webdriver.navigate().to(`http://127.0.0.1:${port}`); - body = await webdriver.findElement(By.css('body')); - }) - - it('should open default search for keywords by open command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('open an apple', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }); - let url = new URL(tabs[0].url); - assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`) - }); - }); - - it('should open certain search page for keywords by open command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('open yahoo an apple', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }) - let url = new URL(tabs[0].url); - assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`) - }); - }); - - it('should open default engine with empty keywords by open command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('open', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }) - let url = new URL(tabs[0].url); - assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`) - }); - }); - - it('should open certain search page for empty keywords by open command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('open yahoo', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }) - let url = new URL(tabs[0].url); - assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`) - }); - }); - - it('should open a site with domain by open command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('open i-beam.org', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }) - let url = new URL(tabs[0].url); - assert.equal(url.href, 'https://i-beam.org/') - }); - }); - - it('should open a site with URL by open command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('open https://i-beam.org', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({ active: true }) - let url = new URL(tabs[0].url); - assert.equal(url.href, 'https://i-beam.org/') - }); - }); -}); diff --git a/e2e/command_open.test.ts b/e2e/command_open.test.ts new file mode 100644 index 0000000..cfaee15 --- /dev/null +++ b/e2e/command_open.test.ts @@ -0,0 +1,148 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; + +const newApp = () => { + + let app = express(); + for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) { + app.get('/' + name, (_req, res) => { + res.send(` + +

${name.charAt(0).toUpperCase() + name.slice(1)}

+`); + }); + } + app.get('/', (_req, res) => { + res.send(` + +

home

+`); + }); + return app; +}; + +describe("open command test", () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; + + before(async() => { + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + http = newApp().listen(port); + + await browser.storage.local.set({ + settings, + }); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + await webdriver.navigate().to(`http://127.0.0.1:${port}`); + body = await webdriver.findElement(By.css('body')); + }) + + it('should open default search for keywords by open command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('open an apple', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }); + let url = new URL(tabs[0].url); + assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`) + }); + }); + + it('should open certain search page for keywords by open command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('open yahoo an apple', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }) + let url = new URL(tabs[0].url); + assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`) + }); + }); + + it('should open default engine with empty keywords by open command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('open', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }) + let url = new URL(tabs[0].url); + assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`) + }); + }); + + it('should open certain search page for empty keywords by open command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('open yahoo', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }) + let url = new URL(tabs[0].url); + assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`) + }); + }); + + it('should open a site with domain by open command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('open i-beam.org', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }) + let url = new URL(tabs[0].url); + assert.equal(url.href, 'https://i-beam.org/') + }); + }); + + it('should open a site with URL by open command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('open https://i-beam.org', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({ active: true }) + let url = new URL(tabs[0].url); + assert.equal(url.href, 'https://i-beam.org/') + }); + }); +}); diff --git a/e2e/command_quit.test.js b/e2e/command_quit.test.js deleted file mode 100644 index 07e770a..0000000 --- a/e2e/command_quit.test.js +++ /dev/null @@ -1,121 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); - -const newApp = () => { - let app = express(); - app.get('/*', (req, res) => { - res.send(` - - - my_${req.path.slice(1)} - -

${req.path}

-`); - }); - return app; -}; - -describe('quit/quitall command test', () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - - before(async() => { - http = newApp().listen(port); - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - let tabs = await browser.tabs.query({}); - for (let tab of tabs.slice(1)) { - await browser.tabs.remove(tab.id); - } - await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1` }); - for (let i = 2; i <= 5; ++i) { - await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}`}) - } - - await eventually(async() => { - let handles = await webdriver.getAllWindowHandles(); - assert.equal(handles.length, 5); - await webdriver.switchTo().window(handles[2]); - await webdriver.findElement(By.css('iframe')); - }); - - await new Promise((resolve) => setTimeout(resolve, 100)); - }); - - it('should current tab by q command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('q', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 4) - }); - }); - - it('should current tab by quit command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('quit', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 4) - }); - }); - - it('should current tab by qa command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('qa', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 1) - }); - }); - - it('should current tab by quitall command', async() => { - let body = await webdriver.findElement(By.css('body')); - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - await input.sendKeys('quitall', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 1) - }); - }); -}); diff --git a/e2e/command_quit.test.ts b/e2e/command_quit.test.ts new file mode 100644 index 0000000..29b947a --- /dev/null +++ b/e2e/command_quit.test.ts @@ -0,0 +1,124 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; + + +const newApp = () => { + let app = express(); + app.get('/*', (req, res) => { + res.send(` + + + my_${req.path.slice(1)} + +

${req.path}

+`); + }); + return app; +}; + +describe('quit/quitall command test', () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + + before(async() => { + http = newApp().listen(port); + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1` }); + for (let i = 2; i <= 5; ++i) { + await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}`}) + } + + await eventually(async() => { + let handles = await webdriver.getAllWindowHandles(); + assert.equal(handles.length, 5); + await webdriver.switchTo().window(handles[2]); + await webdriver.findElement(By.css('iframe')); + }); + + await new Promise((resolve) => setTimeout(resolve, 100)); + }); + + it('should current tab by q command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('q', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 4) + }); + }); + + it('should current tab by quit command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('quit', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 4) + }); + }); + + it('should current tab by qa command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('qa', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 1) + }); + }); + + it('should current tab by quitall command', async() => { + let body = await webdriver.findElement(By.css('body')); + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + await input.sendKeys('quitall', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 1) + }); + }); +}); diff --git a/e2e/command_tabopen.test.js b/e2e/command_tabopen.test.js deleted file mode 100644 index 78f5d7f..0000000 --- a/e2e/command_tabopen.test.js +++ /dev/null @@ -1,157 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); - -const newApp = () => { - - let app = express(); - for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) { - app.get('/' + name, (req, res) => { - res.send(` - -

${name.charAt(0).toUpperCase() + name.slice(1)}

-`); - }); - } - app.get('/', (req, res) => { - res.send(` - -

home

-`); - }); - return app; -}; - -describe("tabopen command test", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; - - before(async() => { - http = newApp().listen(port); - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - - await browser.storage.local.set({ - settings, - }); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - let tabs = await browser.tabs.query({}); - for (let tab of tabs.slice(1)) { - await browser.tabs.remove(tab.id); - } - - await webdriver.navigate().to(`http://127.0.0.1:${port}`); - body = await webdriver.findElement(By.css('body')); - }) - - it('should open default search for keywords by tabopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('tabopen an apple', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 2); - let url = new URL(tabs[1].url); - assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`) - }); - }); - - it('should open certain search page for keywords by tabopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('tabopen yahoo an apple', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 2); - let url = new URL(tabs[1].url); - assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`) - }); - }); - - it('should open default engine with empty keywords by tabopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('tabopen', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 2); - let url = new URL(tabs[1].url); - assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`) - }); - }); - - it('should open certain search page for empty keywords by tabopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('tabopen yahoo', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 2); - let url = new URL(tabs[1].url); - assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`) - }); - }); - - it('should open a site with domain by tabopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('tabopen i-beam.org', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 2); - let url = new URL(tabs[1].url); - assert.equal(url.href, 'https://i-beam.org/') - }); - }); - - it('should open a site with URL by tabopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('tabopen https://i-beam.org', Key.ENTER); - - await eventually(async() => { - let tabs = await browser.tabs.query({}); - assert.equal(tabs.length, 2); - let url = new URL(tabs[1].url); - assert.equal(url.href, 'https://i-beam.org/') - }); - }); -}); diff --git a/e2e/command_tabopen.test.ts b/e2e/command_tabopen.test.ts new file mode 100644 index 0000000..ca4ad92 --- /dev/null +++ b/e2e/command_tabopen.test.ts @@ -0,0 +1,160 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; + + +const newApp = () => { + + let app = express(); + for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) { + app.get('/' + name, (_req, res) => { + res.send(` + +

${name.charAt(0).toUpperCase() + name.slice(1)}

+`); + }); + } + app.get('/', (_req, res) => { + res.send(` + +

home

+`); + }); + return app; +}; + +describe("tabopen command test", () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; + + before(async() => { + http = newApp().listen(port); + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + + await browser.storage.local.set({ + settings, + }); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + + await webdriver.navigate().to(`http://127.0.0.1:${port}`); + body = await webdriver.findElement(By.css('body')); + }) + + it('should open default search for keywords by tabopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('tabopen an apple', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 2); + let url = new URL(tabs[1].url); + assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`) + }); + }); + + it('should open certain search page for keywords by tabopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('tabopen yahoo an apple', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 2); + let url = new URL(tabs[1].url); + assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`) + }); + }); + + it('should open default engine with empty keywords by tabopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('tabopen', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 2); + let url = new URL(tabs[1].url); + assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`) + }); + }); + + it('should open certain search page for empty keywords by tabopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('tabopen yahoo', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 2); + let url = new URL(tabs[1].url); + assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`) + }); + }); + + it('should open a site with domain by tabopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('tabopen i-beam.org', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 2); + let url = new URL(tabs[1].url); + assert.equal(url.href, 'https://i-beam.org/') + }); + }); + + it('should open a site with URL by tabopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('tabopen https://i-beam.org', Key.ENTER); + + await eventually(async() => { + let tabs = await browser.tabs.query({}); + assert.equal(tabs.length, 2); + let url = new URL(tabs[1].url); + assert.equal(url.href, 'https://i-beam.org/') + }); + }); +}); diff --git a/e2e/command_winopen.test.js b/e2e/command_winopen.test.js deleted file mode 100644 index 149d775..0000000 --- a/e2e/command_winopen.test.js +++ /dev/null @@ -1,168 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); - -const newApp = () => { - - let app = express(); - for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) { - app.get('/' + name, (req, res) => { - res.send(` - -

${name.charAt(0).toUpperCase() + name.slice(1)}

-`); - }); - } - app.get('/', (req, res) => { - res.send(` - -

home

-`); - }); - return app; -}; - -describe("winopen command test", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; - - before(async() => { - http = newApp().listen(port); - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - await browser.storage.local.set({ - settings, - }); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - let wins = await browser.windows.getAll(); - for (let win of wins.slice(1)) { - await browser.windows.remove(win.id); - } - - await webdriver.navigate().to(`http://127.0.0.1:${port}`); - body = await webdriver.findElement(By.css('body')); - }) - - it('should open default search for keywords by winopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('winopen an apple', Key.ENTER); - - await eventually(async() => { - let wins = await browser.windows.getAll(); - assert.equal(wins.length, 2); - - let tabs = await browser.tabs.query({ windowId: wins[1].id }); - let url = new URL(tabs[0].url); - assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`) - }); - }); - - it('should open certain search page for keywords by winopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('winopen yahoo an apple', Key.ENTER); - - await eventually(async() => { - let wins = await browser.windows.getAll(); - assert.equal(wins.length, 2); - - let tabs = await browser.tabs.query({ windowId: wins[1].id }); - let url = new URL(tabs[0].url); - assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`) - }); - }); - - it('should open default engine with empty keywords by winopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('winopen', Key.ENTER); - - await eventually(async() => { - let wins = await browser.windows.getAll(); - assert.equal(wins.length, 2); - - let tabs = await browser.tabs.query({ windowId: wins[1].id }); - let url = new URL(tabs[0].url); - assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`) - }); - }); - - it('should open certain search page for empty keywords by winopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('winopen yahoo', Key.ENTER); - - await eventually(async() => { - let wins = await browser.windows.getAll(); - assert.equal(wins.length, 2); - - let tabs = await browser.tabs.query({ windowId: wins[1].id }); - let url = new URL(tabs[0].url); - assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`) - }); - }); - - it('should open a site with domain by winopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('winopen i-beam.org', Key.ENTER); - - await eventually(async() => { - let wins = await browser.windows.getAll(); - assert.equal(wins.length, 2); - - let tabs = await browser.tabs.query({ windowId: wins[1].id }); - let url = new URL(tabs[0].url); - assert.equal(url.href, 'https://i-beam.org/') - }); - }); - - it('should open a site with URL by winopen command ', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let input = await webdriver.findElement(By.css('input')); - input.sendKeys('winopen https://i-beam.org', Key.ENTER); - - await eventually(async() => { - let wins = await browser.windows.getAll(); - assert.equal(wins.length, 2); - - let tabs = await browser.tabs.query({ windowId: wins[1].id }); - let url = new URL(tabs[0].url); - assert.equal(url.href, 'https://i-beam.org/') - }); - }); -}); diff --git a/e2e/command_winopen.test.ts b/e2e/command_winopen.test.ts new file mode 100644 index 0000000..cdd4c1c --- /dev/null +++ b/e2e/command_winopen.test.ts @@ -0,0 +1,170 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; + +const newApp = () => { + + let app = express(); + for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) { + app.get('/' + name, (_req, res) => { + res.send(` + +

${name.charAt(0).toUpperCase() + name.slice(1)}

+`); + }); + } + app.get('/', (_req, res) => { + res.send(` + +

home

+`); + }); + return app; +}; + +describe("winopen command test", () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; + + before(async() => { + http = newApp().listen(port); + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + await browser.storage.local.set({ + settings, + }); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + let wins = await browser.windows.getAll(); + for (let win of wins.slice(1)) { + await browser.windows.remove(win.id); + } + + await webdriver.navigate().to(`http://127.0.0.1:${port}`); + body = await webdriver.findElement(By.css('body')); + }) + + it('should open default search for keywords by winopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('winopen an apple', Key.ENTER); + + await eventually(async() => { + let wins = await browser.windows.getAll(); + assert.equal(wins.length, 2); + + let tabs = await browser.tabs.query({ windowId: wins[1].id }); + let url = new URL(tabs[0].url); + assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`) + }); + }); + + it('should open certain search page for keywords by winopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('winopen yahoo an apple', Key.ENTER); + + await eventually(async() => { + let wins = await browser.windows.getAll(); + assert.equal(wins.length, 2); + + let tabs = await browser.tabs.query({ windowId: wins[1].id }); + let url = new URL(tabs[0].url); + assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`) + }); + }); + + it('should open default engine with empty keywords by winopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('winopen', Key.ENTER); + + await eventually(async() => { + let wins = await browser.windows.getAll(); + assert.equal(wins.length, 2); + + let tabs = await browser.tabs.query({ windowId: wins[1].id }); + let url = new URL(tabs[0].url); + assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`) + }); + }); + + it('should open certain search page for empty keywords by winopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('winopen yahoo', Key.ENTER); + + await eventually(async() => { + let wins = await browser.windows.getAll(); + assert.equal(wins.length, 2); + + let tabs = await browser.tabs.query({ windowId: wins[1].id }); + let url = new URL(tabs[0].url); + assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`) + }); + }); + + it('should open a site with domain by winopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('winopen i-beam.org', Key.ENTER); + + await eventually(async() => { + let wins = await browser.windows.getAll(); + assert.equal(wins.length, 2); + + let tabs = await browser.tabs.query({ windowId: wins[1].id }); + let url = new URL(tabs[0].url); + assert.equal(url.href, 'https://i-beam.org/') + }); + }); + + it('should open a site with URL by winopen command ', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let input = await webdriver.findElement(By.css('input')); + input.sendKeys('winopen https://i-beam.org', Key.ENTER); + + await eventually(async() => { + let wins = await browser.windows.getAll(); + assert.equal(wins.length, 2); + + let tabs = await browser.tabs.query({ windowId: wins[1].id }); + let url = new URL(tabs[0].url); + assert.equal(url.href, 'https://i-beam.org/') + }); + }); +}); diff --git a/e2e/completion.test.js b/e2e/completion.test.js deleted file mode 100644 index fc87df0..0000000 --- a/e2e/completion.test.js +++ /dev/null @@ -1,133 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); -const Console = require('./lib/Console'); - -const newApp = () => { - let app = express(); - app.get('/', (req, res) => { - res.send(` - - ok -`); - }); - return app; -}; - -describe("general completion test", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; - - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - http = newApp().listen(port); - - await browser.storage.local.set({ - settings, - }); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - await webdriver.navigate().to(`http://127.0.0.1:${port}`); - body = await webdriver.findElement(By.css('body')); - }); - - it('should all commands on empty line', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 10); - assert.deepEqual(items[0], { type: 'title', text: 'Console Command' }); - assert(items[1].text.startsWith('set')) - assert(items[2].text.startsWith('open')) - assert(items[3].text.startsWith('tabopen')) - }); - }); - - it('should only commands filtered by prefix', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('b'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 4); - assert.deepEqual(items[0], { type: 'title', text: 'Console Command' }); - assert(items[1].text.startsWith('buffer')) - assert(items[2].text.startsWith('bdelete')) - assert(items[3].text.startsWith('bdeletes')) - }); - }); - - it('selects completion items by / keys', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('b'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 4); - }); - - await c.sendKeys(Key.TAB); - await eventually(async() => { - let items = await c.getCompletions(); - assert(items[1].highlight) - - let v = await c.currentValue(); - assert.equal(v, 'buffer'); - }); - - await c.sendKeys(Key.TAB, Key.TAB); - await eventually(async() => { - let items = await c.getCompletions(); - assert(items[3].highlight) - - let v = await c.currentValue(); - assert.equal(v, 'bdeletes'); - }); - - await c.sendKeys(Key.TAB); - await eventually(async() => { - let v = await c.currentValue(); - assert.equal(v, 'b'); - }); - - await c.sendKeys(Key.SHIFT, Key.TAB); - await eventually(async() => { - let items = await c.getCompletions(); - assert(items[3].highlight) - - let v = await c.currentValue(); - assert.equal(v, 'bdeletes'); - }); - }); -}); diff --git a/e2e/completion.test.ts b/e2e/completion.test.ts new file mode 100644 index 0000000..fd58f74 --- /dev/null +++ b/e2e/completion.test.ts @@ -0,0 +1,135 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; +import { Console } from './lib/Console'; + +const newApp = () => { + let app = express(); + app.get('/', (_req, res) => { + res.send(` + + ok +`); + }); + return app; +}; + +describe("general completion test", () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; + + before(async() => { + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + http = newApp().listen(port); + + await browser.storage.local.set({ + settings, + }); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + await webdriver.navigate().to(`http://127.0.0.1:${port}`); + body = await webdriver.findElement(By.css('body')); + }); + + it('should all commands on empty line', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 10); + assert.deepEqual(items[0], { type: 'title', text: 'Console Command' }); + assert.ok(items[1].text.startsWith('set')) + assert.ok(items[2].text.startsWith('open')) + assert.ok(items[3].text.startsWith('tabopen')) + }); + }); + + it('should only commands filtered by prefix', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('b'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 4); + assert.deepEqual(items[0], { type: 'title', text: 'Console Command' }); + assert.ok(items[1].text.startsWith('buffer')) + assert.ok(items[2].text.startsWith('bdelete')) + assert.ok(items[3].text.startsWith('bdeletes')) + }); + }); + + it('selects completion items by / keys', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('b'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 4); + }); + + await c.sendKeys(Key.TAB); + await eventually(async() => { + let items = await c.getCompletions(); + assert.ok(items[1].highlight) + + let v = await c.currentValue(); + assert.equal(v, 'buffer'); + }); + + await c.sendKeys(Key.TAB, Key.TAB); + await eventually(async() => { + let items = await c.getCompletions(); + assert.ok(items[3].highlight) + + let v = await c.currentValue(); + assert.equal(v, 'bdeletes'); + }); + + await c.sendKeys(Key.TAB); + await eventually(async() => { + let v = await c.currentValue(); + assert.equal(v, 'b'); + }); + + await c.sendKeys(Key.SHIFT, Key.TAB); + await eventually(async() => { + let items = await c.getCompletions(); + assert.ok(items[3].highlight) + + let v = await c.currentValue(); + assert.equal(v, 'bdeletes'); + }); + }); +}); diff --git a/e2e/completion_buffers.test.js b/e2e/completion_buffers.test.js deleted file mode 100644 index 87d2397..0000000 --- a/e2e/completion_buffers.test.js +++ /dev/null @@ -1,211 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const Console = require('./lib/Console'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); - -const newApp = () => { - - let app = express(); - app.get('/*', (req, res) => { - res.send(` - - - title_${req.path.slice(1)} - -

home

-`); - }); - return app; -}; - -describe("completion on buffer/bdelete/bdeletes", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; - - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - http = newApp().listen(port); - - await browser.storage.local.set({ - settings, - }); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - let tabs = await browser.tabs.query({}); - for (let tab of tabs.slice(1)) { - await browser.tabs.remove(tab.id); - } - - await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1`, pinned: true }); - await browser.tabs.create({ url: `http://127.0.0.1:${port}/site2`, pinned: true }) - for (let i = 3; i <= 5; ++i) { - await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}` }) - } - - await eventually(async() => { - let handles = await webdriver.getAllWindowHandles(); - assert.equal(handles.length, 5); - await webdriver.switchTo().window(handles[2]); - await webdriver.findElement(By.css('iframe')); - }); - body = await webdriver.findElement(By.css('body')); - - await new Promise((resolve) => setTimeout(resolve, 100)); - }); - - it('should all tabs by "buffer" command with empty params', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('buffer '); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 6); - assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); - assert(items[1].text.startsWith('1:')); - assert(items[2].text.startsWith('2:')); - assert(items[3].text.startsWith('3:')); - assert(items[4].text.startsWith('4:')); - assert(items[5].text.startsWith('5:')); - - assert(items[3].text.includes('%')); - assert(items[5].text.includes('#')); - }); - }) - - it('should filter items with URLs by keywords on "buffer" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('buffer title_site2'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); - assert(items[1].text.startsWith('2:')); - assert(items[1].text.includes('title_site2')); - assert(items[1].text.includes(`http://127.0.0.1:${port}/site2`)); - }); - }) - - it('should filter items with titles by keywords on "buffer" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('buffer /site2'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); - assert(items[1].text.startsWith('2:')); - }); - }) - - it('should show one item by number on "buffer" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('buffer 2'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 2); - assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); - assert(items[1].text.startsWith('2:')); - }); - }) - - it('should show unpinned tabs "bdelete" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('bdelete site'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 4); - assert(items[1].text.includes('site3')); - assert(items[2].text.includes('site4')); - assert(items[3].text.includes('site5')); - }); - }) - - it('should show unpinned tabs "bdeletes" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('bdelete site'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 4); - assert(items[1].text.includes('site3')); - assert(items[2].text.includes('site4')); - assert(items[3].text.includes('site5')); - }); - }) - - it('should show both pinned and unpinned tabs "bdelete!" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('bdelete! site'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 6); - assert(items[1].text.includes('site1')); - assert(items[2].text.includes('site2')); - assert(items[3].text.includes('site3')); - assert(items[4].text.includes('site4')); - assert(items[5].text.includes('site5')); - }); - }) - - it('should show both pinned and unpinned tabs "bdeletes!" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('bdeletes! site'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 6); - assert(items[1].text.includes('site1')); - assert(items[2].text.includes('site2')); - assert(items[3].text.includes('site3')); - assert(items[4].text.includes('site4')); - assert(items[5].text.includes('site5')); - }); - }) -}); diff --git a/e2e/completion_buffers.test.ts b/e2e/completion_buffers.test.ts new file mode 100644 index 0000000..9c212cc --- /dev/null +++ b/e2e/completion_buffers.test.ts @@ -0,0 +1,213 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By } from 'selenium-webdriver'; +import { Console } from './lib/Console'; + +const newApp = () => { + + let app = express(); + app.get('/*', (req, res) => { + res.send(` + + + title_${req.path.slice(1)} + +

home

+`); + }); + return app; +}; + +describe("completion on buffer/bdelete/bdeletes", () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; + + before(async() => { + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + http = newApp().listen(port); + + await browser.storage.local.set({ + settings, + }); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + + await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1`, pinned: true }); + await browser.tabs.create({ url: `http://127.0.0.1:${port}/site2`, pinned: true }) + for (let i = 3; i <= 5; ++i) { + await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}` }) + } + + await eventually(async() => { + let handles = await webdriver.getAllWindowHandles(); + assert.equal(handles.length, 5); + await webdriver.switchTo().window(handles[2]); + await webdriver.findElement(By.css('iframe')); + }); + body = await webdriver.findElement(By.css('body')); + + await new Promise((resolve) => setTimeout(resolve, 100)); + }); + + it('should all tabs by "buffer" command with empty params', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('buffer '); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 6); + assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); + assert.ok(items[1].text.startsWith('1:')); + assert.ok(items[2].text.startsWith('2:')); + assert.ok(items[3].text.startsWith('3:')); + assert.ok(items[4].text.startsWith('4:')); + assert.ok(items[5].text.startsWith('5:')); + + assert.ok(items[3].text.includes('%')); + assert.ok(items[5].text.includes('#')); + }); + }) + + it('should filter items with URLs by keywords on "buffer" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('buffer title_site2'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); + assert.ok(items[1].text.startsWith('2:')); + assert.ok(items[1].text.includes('title_site2')); + assert.ok(items[1].text.includes(`http://127.0.0.1:${port}/site2`)); + }); + }) + + it('should filter items with titles by keywords on "buffer" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('buffer /site2'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); + assert.ok(items[1].text.startsWith('2:')); + }); + }) + + it('should show one item by number on "buffer" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('buffer 2'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 2); + assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); + assert.ok(items[1].text.startsWith('2:')); + }); + }) + + it('should show unpinned tabs "bdelete" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('bdelete site'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 4); + assert.ok(items[1].text.includes('site3')); + assert.ok(items[2].text.includes('site4')); + assert.ok(items[3].text.includes('site5')); + }); + }) + + it('should show unpinned tabs "bdeletes" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('bdelete site'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 4); + assert.ok(items[1].text.includes('site3')); + assert.ok(items[2].text.includes('site4')); + assert.ok(items[3].text.includes('site5')); + }); + }) + + it('should show both pinned and unpinned tabs "bdelete!" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('bdelete! site'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 6); + assert.ok(items[1].text.includes('site1')); + assert.ok(items[2].text.includes('site2')); + assert.ok(items[3].text.includes('site3')); + assert.ok(items[4].text.includes('site4')); + assert.ok(items[5].text.includes('site5')); + }); + }) + + it('should show both pinned and unpinned tabs "bdeletes!" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('bdeletes! site'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 6); + assert.ok(items[1].text.includes('site1')); + assert.ok(items[2].text.includes('site2')); + assert.ok(items[3].text.includes('site3')); + assert.ok(items[4].text.includes('site4')); + assert.ok(items[5].text.includes('site5')); + }); + }) +}); diff --git a/e2e/completion_open.test.js b/e2e/completion_open.test.js deleted file mode 100644 index b2b7484..0000000 --- a/e2e/completion_open.test.js +++ /dev/null @@ -1,256 +0,0 @@ -const express = require('express'); -const lanthan = require('lanthan'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); -const Console = require('./lib/Console'); - -const newApp = () => { - - let app = express(); - app.get('/', (req, res) => { - res.send(` - - ok -`); - }); - return app; -}; - -describe("completion on open/tabopen/winopen commands", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; - - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - http = newApp().listen(port); - - await browser.storage.local.set({ - settings, - }); - - // Add item into hitories - await webdriver.navigate().to(`https://i-beam.org/404`); - }); - - after(async() => { - http.close(); - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - await webdriver.navigate().to(`http://127.0.0.1:${port}`); - body = await webdriver.findElement(By.css('body')); - }); - - it('should show completions from search engines, bookmarks, and histories by "open" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('open '); - - await eventually(async() => { - let completions = await c.getCompletions(); - assert(completions.find(x => x.type === 'title' && x.text === 'Search Engines')); - assert(completions.find(x => x.type === 'title' && x.text === 'Bookmarks')); - assert(completions.find(x => x.type === 'title' && x.text === 'History')); - }); - }); - - it('should filter items with URLs by keywords on "open" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('open https://'); - - await eventually(async() => { - let completions = await c.getCompletions(); - let items = completions.filter(x => x.type === 'item').map(x => x.text); - assert(items.every(x => x.includes('https://'))); - }); - }) - - it('should filter items with titles by keywords on "open" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('open getting'); - - await eventually(async() => { - let completions = await c.getCompletions(); - let items = completions.filter(x => x.type === 'item').map(x => x.text); - assert(items.every(x => x.toLowerCase().includes('getting'))); - }); - }) - - it('should filter items with titles by keywords on "tabopen" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('tabopen https://'); - - await eventually(async() => { - let completions = await c.getCompletions(); - let items = completions.filter(x => x.type === 'item').map(x => x.text); - assert(items.every(x => x.includes('https://'))); - }); - }) - - it('should filter items with titles by keywords on "winopen" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('winopen https://'); - - await eventually(async() => { - let completions = await c.getCompletions(); - let items = completions.filter(x => x.type === 'item').map(x => x.text); - assert(items.every(x => x.includes('https://'))); - }); - }) - - it('should display only specified items in "complete" property by set command', async() => { - let c = new Console(webdriver); - - const execCommand = async(line) => { - await body.sendKeys(':'); - await webdriver.switchTo().frame(0); - await c.sendKeys(line, Key.ENTER); - await new Promise(resolve => setTimeout(resolve, 100)); - await webdriver.switchTo().parentFrame(); - } - - const typeCommand = async(...keys) => { - await body.sendKeys(':'); - await webdriver.switchTo().frame(0); - await c.sendKeys(...keys); - } - - const cancel = async() => { - await c.sendKeys(Key.ESCAPE); - await new Promise(resolve => setTimeout(resolve, 100)); - await webdriver.switchTo().parentFrame(); - } - - await execCommand('set complete=sbh'); - await typeCommand('open '); - - await eventually(async() => { - let completions = await c.getCompletions(); - let titles = completions.filter(x => x.type === 'title').map(x => x.text); - assert.deepEqual(titles, ['Search Engines', 'Bookmarks', 'History']) - }); - - await cancel(); - await execCommand('set complete=bss'); - await typeCommand('open '); - - await eventually(async() => { - let completions = await c.getCompletions(); - let titles = completions.filter(x => x.type === 'title').map(x => x.text); - assert.deepEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines']) - }); - }) - - it('should display only specified items in "complete" property by setting', async() => { - const settings = { - source: 'json', - json: `{ - "keymaps": { - ":": { "type": "command.show" } - }, - "search": { - "default": "google", - "engines": { "google": "https://google.com/search?q={}" } - }, - "properties": { - "complete": "sbh" - } - }`, - }; - await browser.storage.local.set({ settings, }); - - let c = new Console(webdriver); - - const typeCommand = async(...keys) => { - await body.sendKeys(':'); - await webdriver.switchTo().frame(0); - await c.sendKeys(...keys); - } - - const cancel = async() => { - await c.sendKeys(Key.ESCAPE); - await new Promise(resolve => setTimeout(resolve, 100)); - await webdriver.switchTo().parentFrame(); - } - - await browser.storage.local.set({ settings: { - source: 'json', - json: `{ - "keymaps": { - ":": { "type": "command.show" } - }, - "search": { - "default": "google", - "engines": { "google": "https://google.com/search?q={}" } - }, - "properties": { - "complete": "sbh" - } - }`, - }}); - await typeCommand('open '); - - await eventually(async() => { - let completions = await c.getCompletions(); - let titles = completions.filter(x => x.type === 'title').map(x => x.text); - assert.deepEqual(titles, ['Search Engines', 'Bookmarks', 'History']) - }); - - await cancel(); - - await browser.storage.local.set({ settings: { - source: 'json', - json: `{ - "keymaps": { - ":": { "type": "command.show" } - }, - "search": { - "default": "google", - "engines": { "google": "https://google.com/search?q={}" } - }, - "properties": { - "complete": "bss" - } - }`, - }}); - await typeCommand('open '); - - await eventually(async() => { - let completions = await c.getCompletions(); - let titles = completions.filter(x => x.type === 'title').map(x => x.text); - assert.deepEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines']) - }); - - - }) -}); diff --git a/e2e/completion_open.test.ts b/e2e/completion_open.test.ts new file mode 100644 index 0000000..dcd1829 --- /dev/null +++ b/e2e/completion_open.test.ts @@ -0,0 +1,257 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; +import { Console } from './lib/Console'; + +const newApp = () => { + + let app = express(); + app.get('/', (_req, res) => { + res.send(` + + ok +`); + }); + return app; +}; + +describe("completion on open/tabopen/winopen commands", () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; + + before(async() => { + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + http = newApp().listen(port); + + await browser.storage.local.set({ + settings, + }); + + // Add item into hitories + await webdriver.navigate().to(`https://i-beam.org/404`); + }); + + after(async() => { + http.close(); + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + await webdriver.navigate().to(`http://127.0.0.1:${port}`); + body = await webdriver.findElement(By.css('body')); + }); + + it('should show completions from search engines, bookmarks, and histories by "open" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('open '); + + await eventually(async() => { + let completions = await c.getCompletions(); + assert.ok(completions.find(x => x.type === 'title' && x.text === 'Search Engines')); + assert.ok(completions.find(x => x.type === 'title' && x.text === 'Bookmarks')); + assert.ok(completions.find(x => x.type === 'title' && x.text === 'History')); + }); + }); + + it('should filter items with URLs by keywords on "open" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('open https://'); + + await eventually(async() => { + let completions = await c.getCompletions(); + let items = completions.filter(x => x.type === 'item').map(x => x.text); + assert.ok(items.every(x => x.includes('https://'))); + }); + }) + + it('should filter items with titles by keywords on "open" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('open getting'); + + await eventually(async() => { + let completions = await c.getCompletions(); + let items = completions.filter(x => x.type === 'item').map(x => x.text); + assert.ok(items.every(x => x.toLowerCase().includes('getting'))); + }); + }) + + it('should filter items with titles by keywords on "tabopen" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('tabopen https://'); + + await eventually(async() => { + let completions = await c.getCompletions(); + let items = completions.filter(x => x.type === 'item').map(x => x.text); + assert.ok(items.every(x => x.includes('https://'))); + }); + }) + + it('should filter items with titles by keywords on "winopen" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('winopen https://'); + + await eventually(async() => { + let completions = await c.getCompletions(); + let items = completions.filter(x => x.type === 'item').map(x => x.text); + assert.ok(items.every(x => x.includes('https://'))); + }); + }) + + it('should display only specified items in "complete" property by set command', async() => { + let c = new Console(webdriver); + + const execCommand = async(line: string) => { + await body.sendKeys(':'); + await webdriver.switchTo().frame(0); + await c.sendKeys(line, Key.ENTER); + await new Promise(resolve => setTimeout(resolve, 100)); + await (webdriver.switchTo() as any).parentFrame(); + } + + const typeCommand = async(...keys: string[]) => { + await body.sendKeys(':'); + await webdriver.switchTo().frame(0); + await c.sendKeys(...keys); + } + + const cancel = async() => { + await c.sendKeys(Key.ESCAPE); + await new Promise(resolve => setTimeout(resolve, 100)); + await (webdriver.switchTo() as any).parentFrame(); + } + + await execCommand('set complete=sbh'); + await typeCommand('open '); + + await eventually(async() => { + let completions = await c.getCompletions(); + let titles = completions.filter(x => x.type === 'title').map(x => x.text); + assert.deepEqual(titles, ['Search Engines', 'Bookmarks', 'History']) + }); + + await cancel(); + await execCommand('set complete=bss'); + await typeCommand('open '); + + await eventually(async() => { + let completions = await c.getCompletions(); + let titles = completions.filter(x => x.type === 'title').map(x => x.text); + assert.deepEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines']) + }); + }) + + it('should display only specified items in "complete" property by setting', async() => { + const settings = { + source: 'json', + json: `{ + "keymaps": { + ":": { "type": "command.show" } + }, + "search": { + "default": "google", + "engines": { "google": "https://google.com/search?q={}" } + }, + "properties": { + "complete": "sbh" + } + }`, + }; + await browser.storage.local.set({ settings, }); + + let c = new Console(webdriver); + + const typeCommand = async(...keys: string[]) => { + await body.sendKeys(':'); + await webdriver.switchTo().frame(0); + await c.sendKeys(...keys); + } + + const cancel = async() => { + await c.sendKeys(Key.ESCAPE); + await new Promise(resolve => setTimeout(resolve, 100)); + await (webdriver.switchTo() as any).parentFrame(); + } + + await browser.storage.local.set({ settings: { + source: 'json', + json: `{ + "keymaps": { + ":": { "type": "command.show" } + }, + "search": { + "default": "google", + "engines": { "google": "https://google.com/search?q={}" } + }, + "properties": { + "complete": "sbh" + } + }`, + }}); + await typeCommand('open '); + + await eventually(async() => { + let completions = await c.getCompletions(); + let titles = completions.filter(x => x.type === 'title').map(x => x.text); + assert.deepEqual(titles, ['Search Engines', 'Bookmarks', 'History']) + }); + + await cancel(); + + await browser.storage.local.set({ settings: { + source: 'json', + json: `{ + "keymaps": { + ":": { "type": "command.show" } + }, + "search": { + "default": "google", + "engines": { "google": "https://google.com/search?q={}" } + }, + "properties": { + "complete": "bss" + } + }`, + }}); + await typeCommand('open '); + + await eventually(async() => { + let completions = await c.getCompletions(); + let titles = completions.filter(x => x.type === 'title').map(x => x.text); + assert.deepEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines']) + }); + + + }) +}); diff --git a/e2e/completion_set.test.js b/e2e/completion_set.test.js deleted file mode 100644 index a6ec248..0000000 --- a/e2e/completion_set.test.js +++ /dev/null @@ -1,73 +0,0 @@ -const express = require('express'); -const lanthan = require('lanthan'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const Console = require('./lib/Console'); -const { Builder } = require('lanthan'); -const { By } = require('selenium-webdriver'); - -describe("completion on set commands", () => { - const port = 12321; - let lanthan; - let session; - let browser; - let body; - - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - - await browser.storage.local.set({ - settings, - }); - }); - - after(async() => { - if (lanthan) { - await lanthan.quit(); - } - }); - - beforeEach(async() => { - await webdriver.navigate().to(`about:blank`); - body = await webdriver.findElement(By.css('body')); - }); - - it('should show all property names by "set" command with empty params', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('set '); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 5); - assert.deepEqual(items[0], { type: 'title', text: 'Properties' }); - assert(items[1].text.startsWith('hintchars')) - assert(items[2].text.startsWith('smoothscroll')) - assert(items[3].text.startsWith('nosmoothscroll')) - assert(items[4].text.startsWith('complete')) - }); - }); - - it('should show filtered property names by "set" command', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - let c = new Console(webdriver); - await c.sendKeys('set no'); - - await eventually(async() => { - let items = await c.getCompletions(); - assert.equal(items.length, 2); - assert(items[1].text.includes('nosmoothscroll')) - }); - }); -}); diff --git a/e2e/completion_set.test.ts b/e2e/completion_set.test.ts new file mode 100644 index 0000000..018479f --- /dev/null +++ b/e2e/completion_set.test.ts @@ -0,0 +1,71 @@ +import * as path from 'path'; +import * as assert from 'assert'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By } from 'selenium-webdriver'; +import { Console } from './lib/Console'; + +describe("completion on set commands", () => { + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; + + before(async() => { + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + + await browser.storage.local.set({ + settings, + }); + }); + + after(async() => { + if (lanthan) { + await lanthan.quit(); + } + }); + + beforeEach(async() => { + await webdriver.navigate().to(`about:blank`); + body = await webdriver.findElement(By.css('body')); + }); + + it('should show all property names by "set" command with empty params', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('set '); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 5); + assert.deepEqual(items[0], { type: 'title', text: 'Properties' }); + assert.ok(items[1].text.startsWith('hintchars')) + assert.ok(items[2].text.startsWith('smoothscroll')) + assert.ok(items[3].text.startsWith('nosmoothscroll')) + assert.ok(items[4].text.startsWith('complete')) + }); + }); + + it('should show filtered property names by "set" command', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + let c = new Console(webdriver); + await c.sendKeys('set no'); + + await eventually(async() => { + let items = await c.getCompletions(); + assert.equal(items.length, 2); + assert.ok(items[1].text.includes('nosmoothscroll')) + }); + }); +}); diff --git a/e2e/console.test.js b/e2e/console.test.js deleted file mode 100644 index 131a4ef..0000000 --- a/e2e/console.test.js +++ /dev/null @@ -1,128 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { Key, By } = require('selenium-webdriver'); - -const newApp = () => { - let app = express(); - app.get('/', (req, res) => { - res.send(` - - - Hello, world! - -`); - }); - return app; -}; - - -describe("console test", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let tab; - let body; - - before(async() => { - http = newApp().listen(port); - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) - .build(); - webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); - }); - - after(async() => { - if (lanthan) { - await lanthan.quit(); - } - if (http) { - http.close(); - } - }); - - beforeEach(async() => { - await webdriver.navigate().to(`http://127.0.0.1:${port}`); - body = await webdriver.findElement(By.css('body')); - }); - - it('open console with :', async() => { - await body.sendKeys(':'); - - await webdriver.switchTo().frame(0); - - let input = await webdriver.findElement(By.css('input')); - assert.equal(await input.isDisplayed(), true); - }); - - it('open console with open command by o', async() => { - await body.sendKeys('o'); - - await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); - assert.equal(value, 'open '); - }); - - it('open console with open command and current URL by O', async() => { - await body.sendKeys(Key.SHIFT, 'o'); - - await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); - assert.equal(value, `open http://127.0.0.1:${port}/`); - }); - - it('open console with tabopen command by t', async() => { - await body.sendKeys('t'); - - await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); - assert.equal(value, 'tabopen '); - }); - - it('open console with tabopen command and current URL by T', async() => { - await body.sendKeys(Key.SHIFT, 't'); - - await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); - assert.equal(value, `tabopen http://127.0.0.1:${port}/`); - }); - - it('open console with winopen command by w', async() => { - await body.sendKeys('w'); - - await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); - assert.equal(value, 'winopen '); - }); - - it('open console with winopen command and current URL by W', async() => { - await body.sendKeys(Key.SHIFT, 'W'); - - await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); - assert.equal(value, `winopen http://127.0.0.1:${port}/`); - }); - - it('open console with buffer command by b', async() => { - await body.sendKeys('b'); - - await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); - assert.equal(value, `buffer `); - }); - - it('open console with addbookmark command with title by a', async() => { - await body.sendKeys('a'); - - await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); - assert.equal(value, `addbookmark Hello, world!`); - }); -}); - diff --git a/e2e/console.test.ts b/e2e/console.test.ts new file mode 100644 index 0000000..65c5d2d --- /dev/null +++ b/e2e/console.test.ts @@ -0,0 +1,126 @@ +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; + +const newApp = () => { + let app = express(); + app.get('/', (_req, res) => { + res.send(` + + + Hello, world! + +`); + }); + return app; +}; + + +describe("console test", () => { + const port = 12321; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let body: WebElement; + + before(async() => { + http = newApp().listen(port); + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + }); + + after(async() => { + if (lanthan) { + await lanthan.quit(); + } + if (http) { + http.close(); + } + }); + + beforeEach(async() => { + await webdriver.navigate().to(`http://127.0.0.1:${port}`); + body = await webdriver.findElement(By.css('body')); + }); + + it('open console with :', async() => { + await body.sendKeys(':'); + + await webdriver.switchTo().frame(0); + + let input = await webdriver.findElement(By.css('input')); + assert.equal(await input.isDisplayed(), true); + }); + + it('open console with open command by o', async() => { + await body.sendKeys('o'); + + await webdriver.switchTo().frame(0); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); + assert.equal(value, 'open '); + }); + + it('open console with open command and current URL by O', async() => { + await body.sendKeys(Key.SHIFT, 'o'); + + await webdriver.switchTo().frame(0); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); + assert.equal(value, `open http://127.0.0.1:${port}/`); + }); + + it('open console with tabopen command by t', async() => { + await body.sendKeys('t'); + + await webdriver.switchTo().frame(0); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); + assert.equal(value, 'tabopen '); + }); + + it('open console with tabopen command and current URL by T', async() => { + await body.sendKeys(Key.SHIFT, 't'); + + await webdriver.switchTo().frame(0); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); + assert.equal(value, `tabopen http://127.0.0.1:${port}/`); + }); + + it('open console with winopen command by w', async() => { + await body.sendKeys('w'); + + await webdriver.switchTo().frame(0); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); + assert.equal(value, 'winopen '); + }); + + it('open console with winopen command and current URL by W', async() => { + await body.sendKeys(Key.SHIFT, 'W'); + + await webdriver.switchTo().frame(0); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); + assert.equal(value, `winopen http://127.0.0.1:${port}/`); + }); + + it('open console with buffer command by b', async() => { + await body.sendKeys('b'); + + await webdriver.switchTo().frame(0); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); + assert.equal(value, `buffer `); + }); + + it('open console with addbookmark command with title by a', async() => { + await body.sendKeys('a'); + + await webdriver.switchTo().frame(0); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); + assert.equal(value, `addbookmark Hello, world!`); + }); +}); + diff --git a/e2e/eventually.js b/e2e/eventually.js deleted file mode 100644 index ab0ae25..0000000 --- a/e2e/eventually.js +++ /dev/null @@ -1,23 +0,0 @@ -let defaultInterval = 100; -let defaultTimeout = 2000; - -function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -const eventually = async (fn, timeout = defaultTimeout, interval = defaultInterval) => { - let start = Date.now(); - let loop = async() => { - try { - await fn(); - } catch (err) { - if (Date.now() - start > timeout) { - throw err; - } - await new Promise((resolve) => setTimeout(resolve, interval)) - await loop(); - } - }; - await loop(); -}; -module.exports = eventually; diff --git a/e2e/eventually.ts b/e2e/eventually.ts new file mode 100644 index 0000000..12c4552 --- /dev/null +++ b/e2e/eventually.ts @@ -0,0 +1,30 @@ +const defaultInterval = 100; +const defaultTimeout = 2000; + +type Handler = () => void + +const sleep = (ms: number): Promise => { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +const eventually = async ( + fn: Handler, + timeout = defaultTimeout, + interval = defaultInterval, +): Promise => { + let start = Date.now(); + let loop = async() => { + try { + await fn(); + } catch (err) { + if (Date.now() - start > timeout) { + throw err; + } + await sleep(interval); + await loop(); + } + }; + await loop(); +}; + +export default eventually; diff --git a/e2e/follow.test.js b/e2e/follow.test.js deleted file mode 100644 index 336d673..0000000 --- a/e2e/follow.test.js +++ /dev/null @@ -1,263 +0,0 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { Key, By } = require('selenium-webdriver'); - -const newApp = () => { - let app = express(); - - app.get('/', (req, res) => { - res.send(` - - hello -`); - }); - - app.get('/follow-input', (req, res) => { - res.send(` - - -`); - }); - - app.get('/area', (req, res) => { - res.send(` - - - - - - - - - -`); - }); - - /* - * test case: link2 is out of the viewport - * +-----------------+ - * | [link1] |<--- window - * | | - * |=================|<--- viewport - * | [link2] | - * | | - * +-----------------+ - */ - app.get('/test1', (req, res) => { - res.send(` - - - -
- - -`); - }); - -/* - * test case 2: link2 and link3 are out of window of the frame - * +-----------------+ - * | +-----------+ | - * | | [link1] | | - * |=================| - * | | [link2] | | - * | +-----------+ | - * | | - * +-----------------+ - */ - app.get('/test2', (req, res) => { - res.send(` - -