Rewrite e2e tests with await/async

jh-changes
Shin'ya Ueoka 7 years ago
parent 7cae7302bd
commit c884c2b0a7
  1. 183
      e2e/contents/scroll.test.js

@ -8,142 +8,99 @@ describe("scroll test", () => {
let targetWindow; let targetWindow;
let targetTab; let targetTab;
before(() => { before(async () => {
return windows.create().then((win) => { targetWindow = await windows.create();
targetWindow = win; targetTab = await tabs.create(targetWindow.id, CLIENT_URL + '/scroll');
return tabs.create(targetWindow.id, CLIENT_URL + '/scroll');
}).then((tab) => {
targetTab = tab;
});
}); });
after(() => { after(async () => {
return windows.remove(targetWindow.id); await windows.remove(targetWindow.id);
}); });
it('scrolls up by k', () => { it('scrolls up by k', async () => {
let before let before = await scrolls.set(targetTab.id, 100, 100);
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await keys.press(targetTab.id, 'k');
before = scroll;
return keys.press(targetTab.id, 'k'); let actual = await scrolls.get(targetTab.id);
}).then(() => { expect(actual.y).to.be.lessThan(before.y);
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.be.lessThan(before.y);
});
}); });
it('scrolls down by j', () => { it('scrolls down by j', async () => {
let before let before = await scrolls.set(targetTab.id, 100, 100);
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await keys.press(targetTab.id, 'j');
before = scroll;
return keys.press(targetTab.id, 'j'); let actual = await scrolls.get(targetTab.id);
}).then(() => { expect(actual.y).to.be.greaterThan(before.y);
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.be.greaterThan(before.y);
});
}); });
it('scrolls left by h', () => { it('scrolls left by h', async () => {
let before let before = await scrolls.set(targetTab.id, 100, 100)
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await keys.press(targetTab.id, 'h');
before = scroll;
return keys.press(targetTab.id, 'h'); let actual = await scrolls.get(targetTab.id);
}).then(() => { expect(actual.x).to.be.lessThan(before.x);
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.x).to.be.lessThan(before.x);
});
}); });
it('scrolls top by gg', () => { it('scrolls top by gg', async () => {
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await scrolls.set(targetTab.id, 100, 100);
return keys.press(targetTab.id, 'g'); await keys.press(targetTab.id, 'g');
}).then(() => { await keys.press(targetTab.id, 'g');
return keys.press(targetTab.id, 'g'); let actual = await scrolls.get(targetTab.id);
}).then(() => { expect(actual.y).to.be.equals(0);
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.be.equals(0);
});
}); });
it('scrolls bottom by G', () => { it('scrolls bottom by G', async () => {
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await scrolls.set(targetTab.id, 100, 100);
return keys.press(targetTab.id, 'G', { shiftKey: true }); await keys.press(targetTab.id, 'G', { shiftKey: true });
}).then(() => {
return scrolls.get(targetTab.id); let actual = await scrolls.get(targetTab.id);
}).then((actual) => { expect(actual.y).to.be.equals(actual.yMax);
expect(actual.y).to.be.equals(actual.yMax);
});
}); });
it('scrolls bottom by 0', () => { it('scrolls bottom by 0', async () => {
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await scrolls.set(targetTab.id, 100, 100);
return keys.press(targetTab.id, '0'); await keys.press(targetTab.id, '0');
}).then(() => {
return scrolls.get(targetTab.id); let actual = await scrolls.get(targetTab.id);
}).then((actual) => { expect(actual.x).to.be.equals(0);
expect(actual.x).to.be.equals(0);
});
}); });
it('scrolls bottom by $', () => { it('scrolls bottom by $', async () => {
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { await scrolls.set(targetTab.id, 100, 100);
return keys.press(targetTab.id, '$'); await keys.press(targetTab.id, '$');
}).then(() => {
return scrolls.get(targetTab.id); let actual = await scrolls.get(targetTab.id);
}).then((actual) => { expect(actual.x).to.be.equals(actual.xMax);
expect(actual.x).to.be.equals(actual.xMax);
});
}); });
it('scrolls bottom by <C-U>', () => { it('scrolls bottom by <C-U>', async () => {
let before let before = await scrolls.set(targetTab.id, 5000, 5000);
return scrolls.set(targetTab.id, 5000, 5000).then((scroll) => { await keys.press(targetTab.id, 'u', { ctrlKey: true });
before = scroll;
return keys.press(targetTab.id, 'u', { ctrlKey: true }); let actual = await scrolls.get(targetTab.id);
}).then(() => { expect(actual.y).to.closeTo(before.y - before.frameHeight / 2, 1);
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.closeTo(before.y - before.frameHeight / 2, 1);
});
}); });
it('scrolls bottom by <C-D>', () => { it('scrolls bottom by <C-D>', async () => {
let before let before = await scrolls.set(targetTab.id, 5000, 5000);
return scrolls.set(targetTab.id, 5000, 5000).then((scroll) => { await keys.press(targetTab.id, 'd', { ctrlKey: true });
before = scroll;
return keys.press(targetTab.id, 'd', { ctrlKey: true }); let actual = await scrolls.get(targetTab.id);
}).then(() => { expect(actual.y).to.closeTo(before.y + before.frameHeight / 2, 1);
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.closeTo(before.y + before.frameHeight / 2, 1);
});
}); });
it('scrolls bottom by <C-B>', () => { it('scrolls bottom by <C-B>', async () => {
let before let before = await scrolls.set(targetTab.id, 5000, 5000);
return scrolls.set(targetTab.id, 5000, 5000).then((scroll) => { await keys.press(targetTab.id, 'b', { ctrlKey: true });
before = scroll;
return keys.press(targetTab.id, 'b', { ctrlKey: true }); let actual = await await scrolls.get(targetTab.id);
}).then(() => { expect(actual.y).to.equals(before.y - before.frameHeight);
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.equals(before.y - before.frameHeight);
});
}); });
it('scrolls bottom by <C-F>', () => { it('scrolls bottom by <C-F>', async () => {
let before let before = await scrolls.set(targetTab.id, 5000, 5000);
return scrolls.set(targetTab.id, 5000, 5000).then((scroll) => { await keys.press(targetTab.id, 'f', { ctrlKey: true });
before = scroll; let actual = await scrolls.get(targetTab.id);
return keys.press(targetTab.id, 'f', { ctrlKey: true }); expect(actual.y).to.equals(before.y + before.frameHeight);
}).then(() => {
return scrolls.get(targetTab.id);
}).then((actual) => {
expect(actual.y).to.equals(before.y + before.frameHeight);
});
}); });
}); });