Rewrite e2e tests with async/await

jh-changes
Shin'ya Ueoka 7 years ago
parent d6dc869d1f
commit 70ed31f35e
  1. 182
      e2e/contents/navigate.test.js
  2. 2
      e2e/contents/tab.test.js

@ -7,150 +7,96 @@ import { CLIENT_URL } from '../web-server/url';
describe("navigate test", () => { describe("navigate test", () => {
let targetWindow; let targetWindow;
before(() => { before(async () => {
return windows.create().then((win) => { targetWindow = await windows.create();
targetWindow = win; await tabs.create(targetWindow.id, CLIENT_URL);
return tabs.create(targetWindow.id, CLIENT_URL);
});
}); });
after(() => { after(async () => {
return windows.remove(targetWindow.id); await windows.remove(targetWindow.id);
}); });
it('goes to parent', () => { it('goes to parent', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c');
return tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c').then((tab) => { await keys.press(tab.id, 'g');
targetTab = tab; await keys.press(tab.id, 'u');
return keys.press(targetTab.id, 'g'); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, 'u'); tab = await tabs.get(tab.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/b/'); expect(tab.url).to.be.equal(CLIENT_URL + '/a/b/');
}); });
});
it('removes hash', () => { it('removes hash', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c#navigate');
return tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c#navigate').then((tab) => { await keys.press(tab.id, 'g');
targetTab = tab; await keys.press(tab.id, 'u');
return keys.press(targetTab.id, 'g'); tab = await tabs.get(tab.id);
}).then(() => {
return keys.press(targetTab.id, 'u');
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url).to.be.equal(CLIENT_URL + '/a/b/c#'); expect(tab.url).to.be.equal(CLIENT_URL + '/a/b/c#');
}); });
});
it('goes to root', () => { it('goes to root', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c');
return tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c').then((tab) => { await keys.press(tab.id, 'g');
targetTab = tab; await keys.press(tab.id, 'U', { shiftKey: true });
return keys.press(targetTab.id, 'g'); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, 'U', { shiftKey: true }); tab = await tabs.get(tab.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 + '/'); expect(tab.url).to.be.equal(CLIENT_URL + '/');
}); });
});
it('goes back and forward in history', () => { it('goes back and forward in history', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/#navigate');
return tabs.create(targetWindow.id, CLIENT_URL + '/#navigate').then((tab) => { await keys.press(tab.id, 'g');
targetTab = tab; await keys.press(tab.id, 'u');
return keys.press(targetTab.id, 'g'); await keys.press(tab.id, 'H', { shiftKey: true });
}).then(() => { await new Promise(resolve => { setTimeout(() => resolve(), 10) });
return keys.press(targetTab.id, 'u');
}).then(() => { tab = await tabs.get(tab.id);
return keys.press(targetTab.id, 'H', { shiftKey: true });
}).then(() => {
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'); expect(tab.url, 'go back in history').to.be.equal(CLIENT_URL + '/#navigate');
}).then(() => { await new Promise(resolve => { setTimeout(() => resolve(), 10) });
return new Promise(resolve => { setTimeout(() => resolve(), 10) }); await keys.press(tab.id, 'L', { shiftKey: true });
}).then(() => {
return keys.press(targetTab.id, 'L', { shiftKey: true }); tab = await tabs.get(tab.id);
}).then(() => {
return tabs.get(targetTab.id);
}).then((tab) => {
expect(tab.url, 'go next in history').to.be.equal(CLIENT_URL + '/#'); expect(tab.url, 'go next in history').to.be.equal(CLIENT_URL + '/#');
}); });
});
it('goes previous page by <a>', () => { it('goes previous page by <a>', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10');
return tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10').then((tab) => { await keys.press(tab.id, '[');
targetTab = tab; await keys.press(tab.id, '[');
return keys.press(targetTab.id, '['); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, '['); tab = await tabs.get(tab.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'); expect(tab.url).to.be.equal(CLIENT_URL + '/a-pagenation?page=9');
});
}) })
it('goes next page by <a>', () => { it('goes next page by <a>', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10');
return tabs.create(targetWindow.id, CLIENT_URL + '/a-pagenation?page=10').then((tab) => { await keys.press(tab.id, ']');
targetTab = tab; await keys.press(tab.id, ']');
return keys.press(targetTab.id, ']'); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, ']'); tab = await tabs.get(tab.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'); expect(tab.url).to.be.equal(CLIENT_URL + '/a-pagenation?page=11');
});
}) })
it('goes previous page by <link>', () => { it('goes previous page by <link>', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10');
return tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10').then((tab) => { await keys.press(tab.id, '[');
targetTab = tab; await keys.press(tab.id, '[');
return keys.press(targetTab.id, '['); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, '['); tab = await tabs.get(tab.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'); expect(tab.url).to.be.equal(CLIENT_URL + '/link-pagenation?page=9');
});
}) })
it('goes next page by <link>', () => { it('goes next page by <link>', async () => {
let targetTab; let tab = await tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10');
return tabs.create(targetWindow.id, CLIENT_URL + '/link-pagenation?page=10').then((tab) => { await keys.press(tab.id, ']');
targetTab = tab; await keys.press(tab.id, ']');
return keys.press(targetTab.id, ']'); await new Promise(resolve => { setTimeout(() => resolve(), 10) });
}).then(() => {
return keys.press(targetTab.id, ']'); tab = await tabs.get(tab.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'); expect(tab.url).to.be.equal(CLIENT_URL + '/link-pagenation?page=11');
});
}) })
}); });

@ -92,7 +92,7 @@ describe("tab test", () => {
await tabs.create(targetWindow.id, CLIENT_URL + '#2'); await tabs.create(targetWindow.id, CLIENT_URL + '#2');
await tabs.create(targetWindow.id, CLIENT_URL + '#3'); await tabs.create(targetWindow.id, CLIENT_URL + '#3');
let tab = await tabs.selectAt(targetWindow.id, 2); let tab = await tabs.selectAt(targetWindow.id, 2);
await keys.press(tab.id, 'g').then(() => tab); await keys.press(tab.id, 'g');
await keys.press(tab.id, '0'); await keys.press(tab.id, '0');
let win = await windows.get(targetWindow.id); let win = await windows.get(targetWindow.id);