Skip to content

Commit

Permalink
Get the tests running with phantomjs using npm test
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Mar 30, 2013
1 parent df404f5 commit 58d99d9
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
*.swp
node_modules/

4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: node_js
node_js:
- 0.8

5 changes: 3 additions & 2 deletions app/js/controllers.js
Expand Up @@ -41,13 +41,14 @@ function ReportDetailCtrl($scope, $routeParams, $http) {
function addContextTo(data) { function addContextTo(data) {
data.iconFailures = "icon-ok"; data.iconFailures = "icon-ok";
data.iconChanges = "icon-minus"; data.iconChanges = "icon-minus";
if (data.fields.metrics.resources.Failed > 0) { if (data.fields.metrics.resources.Failed > 0) {
data.hadFailures = "hadFailures"; data.hadFailures = "hadFailures";
data.iconFailures = "icon-remove"; data.iconFailures = "icon-remove";
} }
if (!data.fields.metrics.events.Noop || data.fields.metrics.events.Noop < 1) { if (!data.fields.metrics.events.Noop || data.fields.metrics.events.Noop < 1) {
data.hadChanges = "hadChanges"; data.hadChanges = "hadChanges";
data.iconChanges = "icon-exclamation-sign"; data.iconChanges = "icon-exclamation-sign";
} }
return data; return data;
} }

23 changes: 23 additions & 0 deletions package.json
@@ -0,0 +1,23 @@
{
"name": "norman",
"version": "0.0.0",
"description": "A Puppet run reports viewer for reports stored in Elasticsearch",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "./node_modules/.bin/testacular start --single-run --browsers PhantomJS config/testacular.conf.js"
},
"repository": {
"type": "git",
"url": "git://github.com/youdevise/norman.git"
},
"author": "Tomas Doran",
"license": "BSD",
"readmeFilename": "README.md",
"gitHead": "df404f5735ddb330bfea6b41fae17a12bf3cd1c7",
"devDependencies": {
"testacular": "~0.6"
}
}
13 changes: 0 additions & 13 deletions scripts/update-repo.sh

This file was deleted.

67 changes: 60 additions & 7 deletions test/unit/controllersSpec.js
@@ -1,40 +1,87 @@
'use strict'; 'use strict';


/* jasmine specs for controllers go here */ /* jasmine specs for controllers go here */
describe('PhoneCat controllers', function() { describe('Norman controllers', function() {

var all_reports = [
{
'@uuid': 'FOO1',
'@fields': {
'metrics': {
'resources': {
'Failed': 0
},
'events': {
'Noop': 0
}
}
}
},
{
'@uuid': 'FOO2',
'@fields': {
'metrics': {
'resources': {
'Failed': 0
},
'events': {
'Noop': 0
}
}
}
}
];

var all_reports_cleaned = [];
all_reports.forEach(function (report) {
var n = angular.fromJson(angular.toJson(report));
n['uuid'] = n['@uuid'];
n['fields'] = n['@fields'];
delete(n['@uuid']);
delete(n['@fields']);
n['iconFailures'] = 'icon-ok';
n['iconChanges'] = 'icon-exclamation-sign';
n['hadChanges'] = 'hadChanges';
all_reports_cleaned.push(n);
});


describe('ReportListCtrl', function(){ describe('ReportListCtrl', function(){
var scope, ctrl, $httpBackend; var scope, ctrl, $httpBackend;


beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) { beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
// $httpBackend.expectPOST('/add-msg.py', 'message content').respond(201, '');
$httpBackend.expectGET('data/reports_latest.json'). $httpBackend.expectGET('data/reports_latest.json').
respond([{uuid: 'FOO1'}, {uuid: 'FOO2'}]); respond(all_reports);


scope = $rootScope.$new(); scope = $rootScope.$new();
ctrl = $controller(ReportListCtrl, {$scope: scope}); ctrl = $controller(ReportListCtrl, {$scope: scope});
})); }));


afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});


it('should create "reports" model with 2 reports fetched from xhr', function() { it('should create "reports" model with 2 reports fetched from xhr', function() {
expect(scope.reports).toBeUndefined(); expect(scope.reports).toBeUndefined();
$httpBackend.flush(); $httpBackend.flush();


expect(scope.reports).toEqual([{uuid: 'FOO1'}, expect(scope.reports).toEqual(all_reports_cleaned);
{uuid: 'FOO2'}]);
}); });




it('should set the default value of orderProp model', function() { it('should set the default value of orderProp model', function() {
expect(scope.orderProp).toBe('age'); $httpBackend.flush();
expect(scope.orderProp).toBe('-timestamp');
}); });
}); });




describe('ReportDetailCtrl', function(){ describe('ReportDetailCtrl', function(){
var scope, ctrl, $httpBackend; var scope, ctrl, $httpBackend;


var report = {uuid: 'FOO1', 'fields': { 'logs': [ 'line1', 'line2' ]} }; var report = all_reports[0]


beforeEach(inject(function(_$httpBackend_, $rootScope, $routeParams, $controller) { beforeEach(inject(function(_$httpBackend_, $rootScope, $routeParams, $controller) {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
Expand All @@ -47,10 +94,16 @@ describe('PhoneCat controllers', function() {
ctrl = $controller(ReportDetailCtrl, {$scope: scope}); ctrl = $controller(ReportDetailCtrl, {$scope: scope});
})); }));


afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});

it('should create "report" model with log lines in fields', function() { it('should create "report" model with log lines in fields', function() {
expect(scope.report).toBeUndefined(); expect(scope.report).toBeUndefined();
$httpBackend.flush(); $httpBackend.flush();
expect(scope.report).toEqual(report); expect(scope.report).toEqual(all_reports_cleaned[0]);
}) })
}); });
}); });

0 comments on commit 58d99d9

Please sign in to comment.