Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scf2k committed Jan 21, 2015
1 parent e727ff4 commit 9f4f496
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
69 changes: 66 additions & 3 deletions test/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ describe('browser', function() {
beforeEach(function() {
this.wd = {
configureHttp: sinon.stub().returns(q()),
init: sinon.stub().returns(q({}))
init: sinon.stub().returns(q({})),
get: sinon.stub().returns(q({}))
};

this.config = {
Expand All @@ -51,7 +52,9 @@ describe('browser', function() {
this.sinon.stub(wd, 'promiseRemote').returns(this.wd);
this.browser = new Browser(this.config, 'browser', {
browserName: 'browser',
version: '1.0'
version: '1.0',
// disable calibration for tests to avoid a lot of mocking
'--noCalibrate': true
});
});

Expand All @@ -61,7 +64,8 @@ describe('browser', function() {
sinon.assert.calledWith(_this.wd.init, {
browserName: 'browser',
version: '1.0',
takesScreenshot: true
takesScreenshot: true,
'--noCalibrate': true
});
});
});
Expand Down Expand Up @@ -89,11 +93,34 @@ describe('browser', function() {
browserName: 'browser',
version: '1.0',
takesScreenshot: true,
'--noCalibrate': true,
option1: 'value1',
option2: 'value2'
});
});
});

it('should call calibrate() by default', function() {
var _this = this;
this.browser = new Browser(this.config, 'browser', {
browserName: 'browser',
version: '1.0'
});

this.sinon.stub(this.browser, 'calibrate').returns(q({}));

return this.browser.launch().then(function() {
sinon.assert.calledWith(_this.browser.calibrate);
});
});

it('should not call calibrate() when --noCalibrate is true', function() {
var _this = this;
this.sinon.stub(this.browser, 'calibrate').returns(q({}));
return this.browser.launch().then(function() {
sinon.assert.notCalled(_this.browser.calibrate);
});
});
});

describe('open', function() {
Expand Down Expand Up @@ -180,4 +207,40 @@ describe('browser', function() {
});
});
});

describe('calibrate', function() {
var img = path.join(__dirname, 'functional', 'data', 'image', 'calibrate.png'),
imgData = fs.readFileSync(img);

beforeEach(function() {
this.wd = {
execute: sinon.stub().returns(q({})),
get: sinon.stub().returns(q({})),
elementByCssSelector: sinon.stub().returns(q()),
moveTo: sinon.stub().returns(q()),
takeScreenshot: sinon.stub().returns(q(imgData))
};

this.sinon.stub(wd, 'promiseRemote').returns(this.wd);

this.browser = new Browser({}, 'browser', {browserName: 'browser', version: '1.0'});
});

it('should calculate correct crop area', function() {
return this.browser.calibrate()
.then(function(rs) {
rs.must.eql({top: 24, left: 6, right: 2, bottom: 0});
});
});

it('captureFullscreenImage() should crop according to calibration result', function() {
var _this = this;
return this.browser.calibrate()
.then(function() {
return _this.browser.captureFullscreenImage().then(function(img) {
img.getSize().must.eql({width: 572, height: 311});
});
});
});
});
});
Binary file added test/functional/data/image/calibrate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9f4f496

Please sign in to comment.