From 28da164e5c630a7d9d0dafe61277814b7b777804 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 13 May 2018 14:41:03 +0900 Subject: [PATCH] Add e2e test cases for [[/]] --- QA.md | 5 --- e2e/contents/navigate.test.js | 68 +++++++++++++++++++++++++++++++++-- e2e/web-server/index.js | 55 +++++++++++++++++++++++++++- 3 files changed, 120 insertions(+), 8 deletions(-) diff --git a/QA.md b/QA.md index 38c3196..ef1ecb4 100644 --- a/QA.md +++ b/QA.md @@ -25,11 +25,6 @@ The behaviors of the console are tested in [Console section](#consoles). - [ ] r: reload current tab - [ ] R: reload current tab without cache -#### Navigation - -- [ ] [[, ]]: Open next/prev link in `` tags. -- [ ] [[, ]]: find prev and next links and open it - #### Misc - [ ] y: yank current URL and show a message diff --git a/e2e/contents/navigate.test.js b/e2e/contents/navigate.test.js index 590a4b3..b9d283d 100644 --- a/e2e/contents/navigate.test.js +++ b/e2e/contents/navigate.test.js @@ -70,13 +70,13 @@ describe("navigate test", () => { }).then(() => { return keys.press(targetTab.id, 'H', { shiftKey: true }); }).then(() => { - return new Promise(resolve => { setTimeout(() => resolve(), 2000) }); + return new Promise(resolve => { setTimeout(() => resolve(), 10) }); }).then(() => { return tabs.get(targetTab.id); }).then((tab) => { expect(tab.url, 'go back in history').to.be.equal(CLIENT_URL + '/#navigate'); }).then(() => { - return new Promise(resolve => { setTimeout(() => resolve(), 2000) }); + return new Promise(resolve => { setTimeout(() => resolve(), 10) }); }).then(() => { return keys.press(targetTab.id, 'L', { shiftKey: true }); }).then(() => { @@ -85,4 +85,68 @@ describe("navigate test", () => { expect(tab.url, 'go next in history').to.be.equal(CLIENT_URL + '/#'); }); }); + + it('goes previous page by ', () => { + let targetTab; + return tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10').then((tab) => { + targetTab = tab; + return keys.press(targetTab.id, '['); + }).then(() => { + return keys.press(targetTab.id, '['); + }).then(() => { + return new Promise(resolve => { setTimeout(() => resolve(), 10) }); + }).then(() => { + return tabs.get(targetTab.id); + }).then((tab) => { + expect(tab.url).to.be.equal(CLIENT_URL + '/a-pagenation?page=9'); + }); + }) + + it('goes next page by ', () => { + let targetTab; + return tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10').then((tab) => { + targetTab = tab; + return keys.press(targetTab.id, ']'); + }).then(() => { + return keys.press(targetTab.id, ']'); + }).then(() => { + return new Promise(resolve => { setTimeout(() => resolve(), 10) }); + }).then(() => { + return tabs.get(targetTab.id); + }).then((tab) => { + expect(tab.url).to.be.equal(CLIENT_URL + '/a-pagenation?page=11'); + }); + }) + + it('goes previous page by ', () => { + let targetTab; + return tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10').then((tab) => { + targetTab = tab; + return keys.press(targetTab.id, '['); + }).then(() => { + return keys.press(targetTab.id, '['); + }).then(() => { + return new Promise(resolve => { setTimeout(() => resolve(), 10) }); + }).then(() => { + return tabs.get(targetTab.id); + }).then((tab) => { + expect(tab.url).to.be.equal(CLIENT_URL + '/link-pagenation?page=9'); + }); + }) + + it('goes next page by ', () => { + let targetTab; + return tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10').then((tab) => { + targetTab = tab; + return keys.press(targetTab.id, ']'); + }).then(() => { + return keys.press(targetTab.id, ']'); + }).then(() => { + return new Promise(resolve => { setTimeout(() => resolve(), 10) }); + }).then(() => { + return tabs.get(targetTab.id); + }).then((tab) => { + expect(tab.url).to.be.equal(CLIENT_URL + '/link-pagenation?page=11'); + }); + }) }); diff --git a/e2e/web-server/index.js b/e2e/web-server/index.js index 8710bf9..cbeee15 100644 --- a/e2e/web-server/index.js +++ b/e2e/web-server/index.js @@ -1,3 +1,5 @@ +'use strict'; + var serverUrl = require('./url'); var http = require('http'); var url = require('url'); @@ -7,15 +9,66 @@ const handleScroll = (req, res) => { res.end(''); }; +const handleAPagenation = (req, res) => { + let u = url.parse(req.url); + let params = new url.URLSearchParams(u.search); + let page = params.get('page') === null ? null : Number(params.get('page')); + if (page === null || isNaN(page)) { + return handle404(req, res); + } + + let body = ''; + let nextLink = u.pathname + '?page=' + (page + 1); + let prevLink = u.pathname + '?page=' + (page - 1); + + if (page > 1) { + body += 'prev | '; + } + body += 'next'; + + res.writeHead(200, {'Content-Type': 'text/html'}); + res.end('' + body + ''); +}; + +const handleLinkPagenation = (req, res) => { + let u = url.parse(req.url); + let params = new url.URLSearchParams(u.search); + let page = params.get('page') === null ? null : Number(params.get('page')); + if (page === null || isNaN(page)) { + return handle404(req, res); + } + + let head = ''; + let nextLink = u.pathname + '?page=' + (page + 1); + let prevLink = u.pathname + '?page=' + (page - 1); + + if (page > 1) { + head += ''; + } + head += ''; + + res.writeHead(200, {'Content-Type': 'text/html'}); + res.end('' + head + ''); +}; + + const handle404 = (req, res) => { res.writeHead(404, {'Content-Type': 'text/plain'}); res.end('not found') }; http.createServer(function (req, res) { + if (req.method !== 'GET') { + handle404(req, res); + } + let u = url.parse(req.url); - if (req.method === 'GET' && u.pathname === '/scroll') { + if (u.pathname === '/scroll') { handleScroll(req, res); + } else if (u.pathname === '/a-pagenation') { + handleAPagenation(req, res); + } else if (u.pathname === '/link-pagenation') { + handleLinkPagenation(req, res); } else { handle404(req, res); }