Adds unit tests for datasetservice, homeCtrl
Alters main.js to allow Karma to see app. Basic unit tests (checking for definition) are added as placeholders. New unit test files will need to have the window.bootstrap && window.bootstrap() call to allow Karma visibility. Change-Id: If3ad2130e6ad6e3883a57ddd291fc17753229ed8
This commit is contained in:
parent
a55187cd47
commit
81a6cb9e97
@ -35,8 +35,8 @@ var bootstrap = function() {
|
||||
angular.bootstrap(document, ['app']);
|
||||
|
||||
window.bootstrap = null;
|
||||
|
||||
};
|
||||
|
||||
// create and bootstrap application
|
||||
angular.element(document).ready(bootstrap);
|
||||
window.bootstrap = bootstrap;
|
||||
|
@ -1,30 +0,0 @@
|
||||
/*global angular */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('Unit: ExampleCtrl', function() {
|
||||
|
||||
var ctrl;
|
||||
|
||||
beforeEach(function() {
|
||||
// instantiate the app module
|
||||
angular.mock.module('app');
|
||||
|
||||
angular.mock.inject(function($controller) {
|
||||
ctrl = $controller('ExampleCtrl');
|
||||
});
|
||||
});
|
||||
|
||||
it('should exist', function() {
|
||||
expect(ctrl).toBeDefined();
|
||||
});
|
||||
|
||||
it('should have a number variable equal to 1234', function() {
|
||||
expect(ctrl.number).toEqual(1234);
|
||||
});
|
||||
|
||||
it('should have a title variable equal to \'AngularJS, Gulp, and Browserify!\'', function() {
|
||||
expect(ctrl.title).toEqual('AngularJS, Gulp, and Browserify!');
|
||||
});
|
||||
|
||||
});
|
24
test/unit/controllers/test-home.js
Normal file
24
test/unit/controllers/test-home.js
Normal file
@ -0,0 +1,24 @@
|
||||
/*global angular */
|
||||
|
||||
'use strict';
|
||||
|
||||
window.bootstrap && window.bootstrap();
|
||||
|
||||
describe('Unit: HomeCtrl', function() {
|
||||
|
||||
var ctrl;
|
||||
|
||||
beforeEach(function() {
|
||||
// instantiate the app module
|
||||
angular.mock.module('app');
|
||||
|
||||
angular.mock.inject(function($controller) {
|
||||
ctrl = $controller('HomeCtrl');
|
||||
});
|
||||
});
|
||||
|
||||
it('should exist', function() {
|
||||
expect(ctrl).toBeDefined();
|
||||
});
|
||||
|
||||
});
|
@ -1,23 +0,0 @@
|
||||
/*global angular */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('Unit: ExampleService', function() {
|
||||
|
||||
var service;
|
||||
|
||||
beforeEach(function() {
|
||||
// instantiate the app module
|
||||
angular.mock.module('app');
|
||||
|
||||
// mock the service
|
||||
angular.mock.inject(function(ExampleService) {
|
||||
service = ExampleService;
|
||||
});
|
||||
});
|
||||
|
||||
it('should exist', function() {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
});
|
69
test/unit/services/test-dataset.js
Normal file
69
test/unit/services/test-dataset.js
Normal file
@ -0,0 +1,69 @@
|
||||
/*global angular */
|
||||
|
||||
'use strict';
|
||||
|
||||
window.bootstrap && window.bootstrap();
|
||||
|
||||
describe('Unit: DatasetService', function() {
|
||||
|
||||
var service, httpBackend;
|
||||
var exampleConfig = {"tempest": [
|
||||
{"raw": "tempest_file_freshlog_0_raw.json",
|
||||
"details": "tempest_file_freshlog_0_details.json",
|
||||
"tree": "tempest_file_freshlog_0_tree.json",
|
||||
"id": 0,
|
||||
"name": "Subunit File: freshlog"}
|
||||
]};
|
||||
|
||||
beforeEach(function() {
|
||||
// instantiate the app module
|
||||
angular.mock.module('app');
|
||||
|
||||
// mock the service
|
||||
angular.mock.inject(function(datasetService, $httpBackend) {
|
||||
service = datasetService;
|
||||
httpBackend = $httpBackend;
|
||||
});
|
||||
});
|
||||
|
||||
it('should exist', function() {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
it('should return config.json', function() {
|
||||
httpBackend.whenGET("data/config.json").respond(exampleConfig);
|
||||
service.list().then(function(config){
|
||||
expect(config.data).toEqual(exampleConfig);
|
||||
});
|
||||
httpBackend.flush();
|
||||
});
|
||||
|
||||
it('should GET the raw file from a dataset', function() {
|
||||
httpBackend.whenGET(exampleConfig.raw).respond(exampleConfig.raw);
|
||||
service.raw(exampleConfig).then(function(raw){
|
||||
expect(raw).toEqual(exampleConfig.raw);
|
||||
});
|
||||
});
|
||||
|
||||
it('should GET the details file from a dataset', function() {
|
||||
httpBackend.whenGET(exampleConfig.details).respond(exampleConfig.details);
|
||||
service.details(exampleConfig).then(function(details){
|
||||
expect(details).toEqual(exampleConfig.details);
|
||||
});
|
||||
});
|
||||
|
||||
it('should GET the tree file from a dataset', function() {
|
||||
httpBackend.whenGET(exampleConfig.tree).respond(exampleConfig.tree);
|
||||
service.tree(exampleConfig).then(function(tree){
|
||||
expect(tree).toEqual(exampleConfig.tree);
|
||||
});
|
||||
});
|
||||
|
||||
it('should GET the dstat file from a dataset', function() {
|
||||
httpBackend.whenGET(exampleConfig.dstat).respond(exampleConfig.dstat);
|
||||
service.dstat(exampleConfig).then(function(dstat){
|
||||
expect(dstat).toEqual(exampleConfig.dstat);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user