Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated protractor-http-mock. #39

Merged
merged 4 commits into from
Nov 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"node-sass": "^3.3.3",
"portfinder": "^0.4.0",
"protractor": "git+https://github.com/jGleitz/protractor.git#browserstack",
"protractor-http-mock": "^0.1.18",
"q": "^1.4.1",
"sass-lint": "^1.3.2",
"serve-static": "^1.10.0",
Expand Down
55 changes: 0 additions & 55 deletions test/behaviour/apimocker.js

This file was deleted.

22 changes: 5 additions & 17 deletions test/behaviour/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

require('./asserters')();

var server = require('./apimocker');
var mock = require('./http-mock');

describe('Home', function() {
this.timeout(1 * 60 * 1000);
Expand All @@ -23,25 +23,13 @@ describe('List', function() {
var locationlist = by.repeater('location in ctrl.locations');

it('should have two entries: "Sandsäcke füllen" and "Transport"', function() {
mock(['locations']);

browser.getPart('list');

expect(element.all(locationlist).count()).to.eventually.equal(2);
expect(element.all(locationlist).count()).to.eventually.equal(3);
expect(element(locationlist.column('location.name').row(0)).getInnerHtml()).to.eventually.contain('Sandsäcke füllen');
expect(element(locationlist.column('location.name').row(1)).getInnerHtml()).to.eventually.contain('Transport');
});

// Example for mocking
it('should load another entry', function() {
server.mockAPI('locations', [{
id: 1,
name: 'Mocked Location',
latitude: 49.1232,
longitude: 8,
location: 'Schlossplatz'
}]);

browser.navigate().refresh();

expect(element(locationlist.column('location.name').row(0)).getInnerHtml()).to.eventually.contain('Mocked Location');
expect(element(locationlist.column('location.name').row(2)).getInnerHtml()).to.eventually.contain('Test 3');
});
});
6 changes: 6 additions & 0 deletions test/behaviour/http-mock.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports.config = {
mocks: {
dir: 'mocks',
default: ['default']
}
};
8 changes: 8 additions & 0 deletions test/behaviour/http-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

var mock = require('protractor-http-mock');
mock.config = {
rootDirectory: __dirname, // default value: process.cwd()
protractorConfig: 'http-mock.conf.js'
};

module.exports = mock;
11 changes: 11 additions & 0 deletions test/behaviour/mocks/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
request: {
path: '/default',
method: 'GET'
},
response: {
data: {
name: "i'm always loaded"
}
}
};
33 changes: 33 additions & 0 deletions test/behaviour/mocks/locations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
request: {
path: '/locations',
method: 'GET'
},
response: {
data: [{
id: 1,
name: 'Sandsäcke füllen',
latitude: 49.1232,
longitude: 8,
location: 'Schlossplatz'
}, {
id: 2,
name: 'Transport',
latitude: 48.1232,
longitude: 8,
location: 'Rheinbad',
options: {
title: 'Transport im Rheinbad'
}
}, {
id: 2,
name: 'Test 3',
latitude: 48.1232,
longitude: 8,
location: 'Rheinbad',
options: {
title: 'Transport im Rheinbad'
}
}]
}
};
4 changes: 1 addition & 3 deletions test/behaviour/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Sets up the test environment
*/

var mocker = require('./apimocker');
var portfinder = require('portfinder');
var Server = require('../../tasks/server');

Expand Down Expand Up @@ -30,8 +29,7 @@ before('Expose globals', function() {
};
});

before('Set up the JSON server and mocker', function() {
before('Set up the HTTP server', function() {
var server = new Server();
server.use(mocker.middleware);
server.listen(port);
});