2018-01-01 14:10:10 +00:00
|
|
|
import sinon from 'sinon';
|
|
|
|
|
2018-04-18 13:11:04 +00:00
|
|
|
import Dimensions from 'dom/dimensions';
|
|
|
|
import GraphicsBuilder from 'dom/graphics_builder';
|
2018-02-17 05:52:03 +00:00
|
|
|
import MockRange from 'mocks/range'
|
2017-12-30 13:37:28 +00:00
|
|
|
|
2018-01-01 14:10:10 +00:00
|
|
|
var sandbox = sinon.sandbox.create();
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-04-18 13:11:04 +00:00
|
|
|
sandbox.stub(Dimensions.prototype, '_getOrCreateMeasuringBox').returns(element);
|
2018-04-22 14:59:00 +00:00
|
|
|
sandbox.stub(Dimensions.prototype, 'sendMessage').returns(true);
|
2018-04-18 13:11:04 +00:00
|
|
|
sandbox.stub(GraphicsBuilder.prototype, '_hideText').returns(true);
|
|
|
|
sandbox.stub(GraphicsBuilder.prototype, '_showText').returns(true);
|
|
|
|
sandbox.stub(GraphicsBuilder.prototype, '_scaleCanvas').returns(true);
|
|
|
|
sandbox.stub(GraphicsBuilder.prototype, '_unScaleCanvas').returns(true);
|
2018-01-01 14:10:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
2018-04-18 13:11:04 +00:00
|
|
|
global.dimensions = {
|
|
|
|
char: {
|
|
|
|
width: 1,
|
|
|
|
height: 2 - 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-30 13:37:28 +00:00
|
|
|
global.document = {
|
|
|
|
addEventListener: () => {},
|
|
|
|
getElementById: () => {},
|
2018-01-23 04:28:56 +00:00
|
|
|
getElementsByTagName: () => {
|
|
|
|
return [{
|
|
|
|
innerHTML: 'Google'
|
|
|
|
}]
|
|
|
|
},
|
2017-12-30 13:37:28 +00:00
|
|
|
createRange: () => {
|
|
|
|
return new MockRange()
|
|
|
|
},
|
|
|
|
createElement: () => {
|
|
|
|
return {
|
|
|
|
getContext: () => {}
|
|
|
|
}
|
2018-01-23 04:28:56 +00:00
|
|
|
},
|
2018-04-18 13:11:04 +00:00
|
|
|
documentElement: {
|
|
|
|
scrollWidth: 3,
|
2018-04-22 14:59:00 +00:00
|
|
|
scrollHeight: 4
|
2018-04-18 13:11:04 +00:00
|
|
|
},
|
2018-01-23 04:28:56 +00:00
|
|
|
location: {
|
|
|
|
href: 'https://www.google.com'
|
2018-04-18 13:11:04 +00:00
|
|
|
},
|
|
|
|
scrollX: 0,
|
2018-04-22 14:59:00 +00:00
|
|
|
scrollY: 0,
|
|
|
|
|
|
|
|
// To save us hand-writing large pixel arrays, let's just have an unrealistically
|
|
|
|
// small window, it's not a problem, because we'll never actually have to view real
|
|
|
|
// webpages on it.
|
|
|
|
innerWidth: 3,
|
|
|
|
innerHeight: 4
|
2017-12-30 13:37:28 +00:00
|
|
|
};
|
|
|
|
|
2018-01-01 14:10:10 +00:00
|
|
|
global.DEVELOPMENT = false;
|
|
|
|
global.PRODUCTION = false;
|
|
|
|
global.TEST = true;
|
2018-01-23 04:28:56 +00:00
|
|
|
global.window = global.document;
|
2017-12-30 13:37:28 +00:00
|
|
|
global.performance = {
|
|
|
|
now: () => {}
|
|
|
|
}
|
2018-01-01 14:10:10 +00:00
|
|
|
|
2018-04-18 13:11:04 +00:00
|
|
|
let element = {
|
|
|
|
getBoundingClientRect: () => {
|
|
|
|
return {
|
|
|
|
width: global.dimensions.char.width,
|
|
|
|
height: global.dimensions.char.height
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-01 14:10:10 +00:00
|
|
|
export default sandbox;
|