From 511f4f0975f253a05cc04a52d8d197905ab94b19 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 30 Oct 2017 13:26:50 +0100 Subject: [PATCH] Refactor --- test/e2e/specs/03_embedStream.js | 28 +-------------------------- test/e2e/utils/SortedWindowHandler.js | 28 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 test/e2e/utils/SortedWindowHandler.js diff --git a/test/e2e/specs/03_embedStream.js b/test/e2e/specs/03_embedStream.js index 5381a5558..4c7e620e8 100644 --- a/test/e2e/specs/03_embedStream.js +++ b/test/e2e/specs/03_embedStream.js @@ -1,30 +1,4 @@ -class SortedWindowHandler { - - constructor(client) { - this.client = client; - this.client.windowHandles((result) => { - this.handles = result.value; - if (this.handles.length > 2) { - throw new Error('SortedWindowHandler must be created before new windows were created.'); - } - }); - } - - windowHandles(callback) { - this.client.windowHandles((result) => { - console.log(result); - this.handles = this.handles.filter((handle) => result.value.includes(handle)); - const remaining = result.value.filter((handle) => !this.handles.includes(handle)); - if (remaining.length === 1) { - this.handles.push(remaining[0]); - } - if (remaining.length > 1) { - throw new Error('Cannot detect new window handle, because more than one windows was created.'); - } - callback(this.handles); - }); - } -} +const SortedWindowHandler = require('../utils/SortedWindowHandler'); module.exports = { '@tags': ['embedStream', 'login'], diff --git a/test/e2e/utils/SortedWindowHandler.js b/test/e2e/utils/SortedWindowHandler.js new file mode 100644 index 000000000..c736547ed --- /dev/null +++ b/test/e2e/utils/SortedWindowHandler.js @@ -0,0 +1,28 @@ +class SortedWindowHandler { + + constructor(client) { + this.client = client; + this.client.windowHandles((result) => { + this.handles = result.value; + if (this.handles.length > 2) { + throw new Error('SortedWindowHandler must be created before new windows were created.'); + } + }); + } + + windowHandles(callback) { + this.client.windowHandles((result) => { + this.handles = this.handles.filter((handle) => result.value.includes(handle)); + const remaining = result.value.filter((handle) => !this.handles.includes(handle)); + if (remaining.length === 1) { + this.handles.push(remaining[0]); + } + if (remaining.length > 1) { + throw new Error('Cannot detect new window handle, because more than one windows was created.'); + } + callback(this.handles); + }); + } +} + +module.exports = SortedWindowHandler;