Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Get the tests running with phantomjs using npm test

  • Loading branch information...
commit 58d99d9e228d90c1031dbe022150f0470b6c71d8 1 parent df404f5
Tomas Doran bobtfish authored
3  .gitignore
... ... @@ -0,0 +1,3 @@
  1 +*.swp
  2 +node_modules/
  3 +
4 .travis.yml
... ... @@ -0,0 +1,4 @@
  1 +language: node_js
  2 +node_js:
  3 + - 0.8
  4 +
5 app/js/controllers.js
@@ -41,13 +41,14 @@ function ReportDetailCtrl($scope, $routeParams, $http) {
41 41 function addContextTo(data) {
42 42 data.iconFailures = "icon-ok";
43 43 data.iconChanges = "icon-minus";
44   - if (data.fields.metrics.resources.Failed > 0) {
  44 + if (data.fields.metrics.resources.Failed > 0) {
45 45 data.hadFailures = "hadFailures";
46 46 data.iconFailures = "icon-remove";
47 47 }
48   - if (!data.fields.metrics.events.Noop || data.fields.metrics.events.Noop < 1) {
  48 + if (!data.fields.metrics.events.Noop || data.fields.metrics.events.Noop < 1) {
49 49 data.hadChanges = "hadChanges";
50 50 data.iconChanges = "icon-exclamation-sign";
51 51 }
52 52 return data;
53 53 }
  54 +
23 package.json
... ... @@ -0,0 +1,23 @@
  1 +{
  2 + "name": "norman",
  3 + "version": "0.0.0",
  4 + "description": "A Puppet run reports viewer for reports stored in Elasticsearch",
  5 + "main": "index.js",
  6 + "directories": {
  7 + "test": "test"
  8 + },
  9 + "scripts": {
  10 + "test": "./node_modules/.bin/testacular start --single-run --browsers PhantomJS config/testacular.conf.js"
  11 + },
  12 + "repository": {
  13 + "type": "git",
  14 + "url": "git://github.com/youdevise/norman.git"
  15 + },
  16 + "author": "Tomas Doran",
  17 + "license": "BSD",
  18 + "readmeFilename": "README.md",
  19 + "gitHead": "df404f5735ddb330bfea6b41fae17a12bf3cd1c7",
  20 + "devDependencies": {
  21 + "testacular": "~0.6"
  22 + }
  23 +}
13 scripts/update-repo.sh
... ... @@ -1,13 +0,0 @@
1   -#!/bin/bash
2   -
3   -###
4   -# This scripts updates the local repo with the latest changes from github.
5   -#
6   -# The master branch will be REPLACED with what's in github and all local changes
7   -# will be LOST.
8   -###
9   -
10   -git checkout master
11   -git fetch -f origin
12   -git fetch --tags origin
13   -git reset --hard origin/master
67 test/unit/controllersSpec.js
... ... @@ -1,32 +1,79 @@
1 1 'use strict';
2 2
3 3 /* jasmine specs for controllers go here */
4   -describe('PhoneCat controllers', function() {
  4 +describe('Norman controllers', function() {
  5 +
  6 + var all_reports = [
  7 + {
  8 + '@uuid': 'FOO1',
  9 + '@fields': {
  10 + 'metrics': {
  11 + 'resources': {
  12 + 'Failed': 0
  13 + },
  14 + 'events': {
  15 + 'Noop': 0
  16 + }
  17 + }
  18 + }
  19 + },
  20 + {
  21 + '@uuid': 'FOO2',
  22 + '@fields': {
  23 + 'metrics': {
  24 + 'resources': {
  25 + 'Failed': 0
  26 + },
  27 + 'events': {
  28 + 'Noop': 0
  29 + }
  30 + }
  31 + }
  32 + }
  33 + ];
  34 +
  35 + var all_reports_cleaned = [];
  36 + all_reports.forEach(function (report) {
  37 + var n = angular.fromJson(angular.toJson(report));
  38 + n['uuid'] = n['@uuid'];
  39 + n['fields'] = n['@fields'];
  40 + delete(n['@uuid']);
  41 + delete(n['@fields']);
  42 + n['iconFailures'] = 'icon-ok';
  43 + n['iconChanges'] = 'icon-exclamation-sign';
  44 + n['hadChanges'] = 'hadChanges';
  45 + all_reports_cleaned.push(n);
  46 + });
5 47
6 48 describe('ReportListCtrl', function(){
7 49 var scope, ctrl, $httpBackend;
8 50
9 51 beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
10 52 $httpBackend = _$httpBackend_;
  53 +// $httpBackend.expectPOST('/add-msg.py', 'message content').respond(201, '');
11 54 $httpBackend.expectGET('data/reports_latest.json').
12   - respond([{uuid: 'FOO1'}, {uuid: 'FOO2'}]);
  55 + respond(all_reports);
13 56
14 57 scope = $rootScope.$new();
15 58 ctrl = $controller(ReportListCtrl, {$scope: scope});
16 59 }));
17 60
  61 + afterEach(function() {
  62 + $httpBackend.verifyNoOutstandingExpectation();
  63 + $httpBackend.verifyNoOutstandingRequest();
  64 + });
18 65
19 66 it('should create "reports" model with 2 reports fetched from xhr', function() {
20 67 expect(scope.reports).toBeUndefined();
21 68 $httpBackend.flush();
22 69
23   - expect(scope.reports).toEqual([{uuid: 'FOO1'},
24   - {uuid: 'FOO2'}]);
  70 + expect(scope.reports).toEqual(all_reports_cleaned);
25 71 });
26 72
27 73
28 74 it('should set the default value of orderProp model', function() {
29   - expect(scope.orderProp).toBe('age');
  75 + $httpBackend.flush();
  76 + expect(scope.orderProp).toBe('-timestamp');
30 77 });
31 78 });
32 79
@@ -34,7 +81,7 @@ describe('PhoneCat controllers', function() {
34 81 describe('ReportDetailCtrl', function(){
35 82 var scope, ctrl, $httpBackend;
36 83
37   - var report = {uuid: 'FOO1', 'fields': { 'logs': [ 'line1', 'line2' ]} };
  84 + var report = all_reports[0]
38 85
39 86 beforeEach(inject(function(_$httpBackend_, $rootScope, $routeParams, $controller) {
40 87 $httpBackend = _$httpBackend_;
@@ -47,10 +94,16 @@ describe('PhoneCat controllers', function() {
47 94 ctrl = $controller(ReportDetailCtrl, {$scope: scope});
48 95 }));
49 96
  97 + afterEach(function() {
  98 + $httpBackend.verifyNoOutstandingExpectation();
  99 + $httpBackend.verifyNoOutstandingRequest();
  100 + });
  101 +
50 102 it('should create "report" model with log lines in fields', function() {
51 103 expect(scope.report).toBeUndefined();
52 104 $httpBackend.flush();
53   - expect(scope.report).toEqual(report);
  105 + expect(scope.report).toEqual(all_reports_cleaned[0]);
54 106 })
55 107 });
56 108 });
  109 +

0 comments on commit 58d99d9

Please sign in to comment.
Something went wrong with that request. Please try again.