parent
f63920e25e
commit
b694afb7ce
6 changed files with 133 additions and 18 deletions
@ -0,0 +1,20 @@ |
||||
import { SCROLL_GET, SCROLL_SET } from '../shared/messages'; |
||||
import * as ipc from './ipc'; |
||||
|
||||
const get = (tabId) => { |
||||
return ipc.send({ |
||||
type: SCROLL_GET, |
||||
tabId, |
||||
}); |
||||
}; |
||||
|
||||
const set = (tabId, x, y) => { |
||||
return ipc.send({ |
||||
type: SCROLL_SET, |
||||
tabId, |
||||
x, |
||||
y, |
||||
}); |
||||
}; |
||||
|
||||
export { get, set }; |
@ -0,0 +1,18 @@ |
||||
const get = () => { |
||||
let element = document.documentElement; |
||||
return { |
||||
xMax: element.scrollWidth - element.clientWidth, |
||||
yMax: element.scrollHeight - element.clientHeight, |
||||
x: element.scrollLeft, |
||||
y: element.scrollTop, |
||||
}; |
||||
}; |
||||
|
||||
const set = (x, y) => { |
||||
let element = document.documentElement; |
||||
element.scrollLeft = x; |
||||
element.scrollTop = y; |
||||
return get(); |
||||
}; |
||||
|
||||
export { get, set }; |
@ -0,0 +1,81 @@ |
||||
import { expect } from "chai"; |
||||
import * as windows from "../ambassador/src/client/windows"; |
||||
import * as tabs from "../ambassador/src/client/tabs"; |
||||
import * as keys from "../ambassador/src/client/keys"; |
||||
import * as scrolls from "../ambassador/src/client/scrolls"; |
||||
|
||||
const SERVER_URL = "localhost:11111"; |
||||
|
||||
describe("scroll test", () => { |
||||
let targetWindow; |
||||
let targetTab; |
||||
|
||||
before(() => { |
||||
return windows.create().then((win) => { |
||||
targetWindow = win; |
||||
return tabs.create(targetWindow.id, SERVER_URL); |
||||
}).then((tab) => { |
||||
targetTab = tab; |
||||
}); |
||||
}); |
||||
|
||||
after(() => { |
||||
return windows.remove(targetWindow.id); |
||||
}); |
||||
|
||||
describe('press k', () => { |
||||
it('scrolls up', () => { |
||||
let before |
||||
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { |
||||
before = scroll; |
||||
return keys.press(targetTab.id, 'k'); |
||||
}).then(() => { |
||||
return scrolls.get(targetTab.id); |
||||
}).then((actual) => { |
||||
expect(actual.y).to.be.lessThan(before.y); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('press j', () => { |
||||
it('scrolls down', () => { |
||||
let before |
||||
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { |
||||
before = scroll; |
||||
return keys.press(targetTab.id, 'j'); |
||||
}).then(() => { |
||||
return scrolls.get(targetTab.id); |
||||
}).then((actual) => { |
||||
expect(actual.y).to.be.greaterThan(before.y); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('press h', () => { |
||||
it('scrolls left', () => { |
||||
let before |
||||
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { |
||||
before = scroll; |
||||
return keys.press(targetTab.id, 'h'); |
||||
}).then(() => { |
||||
return scrolls.get(targetTab.id); |
||||
}).then((actual) => { |
||||
expect(actual.x).to.be.lessThan(before.x); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
describe('press l', () => { |
||||
it('scrolls right', () => { |
||||
let before |
||||
return scrolls.set(targetTab.id, 100, 100).then((scroll) => { |
||||
before = scroll; |
||||
return keys.press(targetTab.id, 'l'); |
||||
}).then(() => { |
||||
return scrolls.get(targetTab.id); |
||||
}).then((actual) => { |
||||
expect(actual.x).to.be.greaterThan(before.x); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
Reference in new issue