puppet-herald 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +15 -7
  2. data/.rubocop.yml +31 -0
  3. data/.rubocop_todo.yml +6 -0
  4. data/.travis.yml +7 -7
  5. data/Gemfile +5 -9
  6. data/README.md +152 -16
  7. data/Rakefile +67 -6
  8. data/bin/puppet-herald +1 -1
  9. data/config.ru +2 -2
  10. data/db/migrate/20141211165540_create_nodes.rb +5 -3
  11. data/db/migrate/20141211171305_create_reports.rb +12 -10
  12. data/db/migrate/20141211171326_create_log_entries.rb +9 -7
  13. data/db/schema.rb +24 -26
  14. data/lib/puppet-herald.rb +59 -21
  15. data/lib/puppet-herald/app/api.rb +111 -0
  16. data/lib/puppet-herald/app/configuration.rb +70 -0
  17. data/lib/puppet-herald/app/frontend.rb +61 -0
  18. data/lib/puppet-herald/{views → app/views}/app.erb +5 -8
  19. data/lib/puppet-herald/{views → app/views}/err500.erb +1 -4
  20. data/lib/puppet-herald/application.rb +27 -0
  21. data/lib/puppet-herald/cli.rb +66 -45
  22. data/lib/puppet-herald/client.rb +33 -0
  23. data/lib/puppet-herald/database.rb +84 -40
  24. data/lib/puppet-herald/javascript.rb +23 -17
  25. data/lib/puppet-herald/models/log-entry.rb +10 -3
  26. data/lib/puppet-herald/models/node.rb +15 -5
  27. data/lib/puppet-herald/models/report.rb +70 -63
  28. data/lib/puppet-herald/public/app.js +9 -8
  29. data/lib/puppet-herald/public/components/directives/status-button.html +1 -1
  30. data/lib/puppet-herald/public/components/directives/status-button.js +5 -3
  31. data/lib/puppet-herald/public/components/filters/filters.js +9 -4
  32. data/lib/puppet-herald/public/components/page.js +34 -0
  33. data/lib/puppet-herald/public/node/node.html +3 -1
  34. data/lib/puppet-herald/public/node/node.js +7 -4
  35. data/lib/puppet-herald/public/nodes/nodes.js +3 -2
  36. data/lib/puppet-herald/public/report/report.html +4 -1
  37. data/lib/puppet-herald/public/report/report.js +5 -3
  38. data/lib/puppet-herald/stubs/puppet.rb +20 -9
  39. data/lib/puppet-herald/version.rb +17 -7
  40. data/package.json +8 -3
  41. data/puppet-herald.gemspec +3 -6
  42. data/spec/integration/application_spec.rb +175 -0
  43. data/spec/integration/models/node_spec.rb +4 -4
  44. data/spec/integration/models/report_spec.rb +7 -7
  45. data/spec/spec_helper.rb +12 -7
  46. data/spec/support/active_record.rb +6 -10
  47. data/spec/support/reconnectdb.rb +13 -0
  48. data/spec/unit/puppet-herald/cli_spec.rb +45 -13
  49. data/spec/unit/puppet-herald/client_spec.rb +23 -0
  50. data/spec/unit/puppet-herald/database_spec.rb +8 -9
  51. data/spec/unit/puppet-herald/javascript_spec.rb +8 -13
  52. data/spec/unit/puppet-herald_spec.rb +4 -4
  53. data/test/javascript/karma.conf.js +43 -5
  54. data/test/javascript/src/app_test.js +90 -0
  55. data/test/javascript/src/components/artifact/artifact-directive_test.js +36 -0
  56. data/test/javascript/src/components/artifact/artifact_test.js +64 -0
  57. data/test/javascript/src/components/directives/status-button_test.js +159 -0
  58. data/test/javascript/src/components/filters/filters_test.js +35 -0
  59. data/test/javascript/src/node/node_test.js +87 -0
  60. data/test/javascript/src/nodes/nodes_test.js +56 -0
  61. data/test/javascript/src/report/report_test.js +94 -0
  62. metadata +98 -68
  63. data/lib/puppet-herald/app.rb +0 -103
  64. data/lib/puppet-herald/public/components/artifact/artifact-directive_test.js +0 -17
  65. data/spec/integration/app_spec.rb +0 -21
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'webmock/rspec'
3
+ require 'puppet-herald/client'
4
+
5
+ describe PuppetHerald::Client, '.process' do
6
+ let(:payload) { { :zz => 65, :yh => 12 } }
7
+ let(:expected) { payload.to_yaml }
8
+ before :each do
9
+ stub_request(:post, "#{address}/api/v1/reports").with(:body => expected).
10
+ to_return(:body => "{id: 1}", :status => 201)
11
+ end
12
+ subject { client.process payload }
13
+ context 'on defaults' do
14
+ let(:address) { 'localhost:11303' }
15
+ let(:client) { PuppetHerald::Client.new }
16
+ it { expect(subject).to be_truthy }
17
+ end
18
+ context 'on other host:port' do
19
+ let(:address) { 'master.secure.vm:8082' }
20
+ let(:client) { PuppetHerald::Client.new('master.secure.vm', 8082) }
21
+ it { expect(subject).to be_truthy }
22
+ end
23
+ end
@@ -1,34 +1,33 @@
1
1
  require 'spec_helper'
2
2
  require 'puppet-herald'
3
- require 'puppet-herald/database'
4
3
 
5
4
  describe PuppetHerald::Database, '.spec' do
6
5
  let(:tempdir) { Dir.tmpdir }
7
6
  let(:echo) { false }
8
- subject { PuppetHerald::Database::spec echo }
7
+ subject { PuppetHerald::database::spec echo }
9
8
  context 'with invalid dbconn' do
10
9
  before :each do
11
- PuppetHerald::Database::dbconn = "#{tempdir}/non-existing.db"
10
+ PuppetHerald::database::dbconn = "#{tempdir}/non-existing.db"
12
11
  end
13
12
  it { expect { subject }.to raise_error(RuntimeError, /Invalid database connection string given/) }
14
13
  end
15
14
  context 'using sqlite' do
16
15
  context 'with non existing database' do
17
16
  before :each do
18
- PuppetHerald::Database::dbconn = 'sqlite:///non-existing/non-existing.db'
17
+ PuppetHerald::database::dbconn = 'sqlite:///non-existing/non-existing.db'
19
18
  end
20
19
  it { expect { subject }.to raise_error(Errno::ENOENT, /No such file or directory/) }
21
20
  end
22
21
  context 'with creatable database file' do
23
22
  before :each do
24
- PuppetHerald::Database::dbconn = "sqlite://#{tempdir}/non-existing.db"
23
+ PuppetHerald::database::dbconn = "sqlite://#{tempdir}/non-existing.db"
25
24
  end
26
25
  its(:class) { should be Hash }
27
26
  its(:size) { should eq 2 }
28
27
  context 'while echoing!!' do
29
28
  let(:echo) { true }
30
29
  before :each do
31
- PuppetHerald::Database::logger.level = Logger::FATAL
30
+ PuppetHerald::database::logger.level = Logger::FATAL
32
31
  end
33
32
  its(:class) { should be Hash }
34
33
  its(:size) { should eq 2 }
@@ -37,17 +36,17 @@ describe PuppetHerald::Database, '.spec' do
37
36
  end
38
37
  context 'using postgres' do
39
38
  before :each do
40
- PuppetHerald::Database::dbconn = "postgres://abc@localhost:6543/adb"
39
+ PuppetHerald::database::dbconn = "postgres://abc@localhost:6543/adb"
41
40
  end
42
41
  context 'with non existing passfile' do
43
42
  before :each do
44
- PuppetHerald::Database::passfile = "/non-existing/passfile"
43
+ PuppetHerald::database::passfile = "/non-existing/passfile"
45
44
  end
46
45
  it { expect { subject }.to raise_error(Errno::ENOENT, /No such file or directory/) }
47
46
  end
48
47
  context 'with existing passfile' do
49
48
  before :each do
50
- PuppetHerald::Database::passfile = __FILE__
49
+ PuppetHerald::database::passfile = __FILE__
51
50
  end
52
51
  its(:class) { should be Hash }
53
52
  its(:size) { should eq 7 }
@@ -3,16 +3,14 @@ require 'puppet-herald'
3
3
  require 'puppet-herald/javascript'
4
4
 
5
5
  describe PuppetHerald::Javascript, '.files' do
6
+ subject { PuppetHerald::Javascript.new }
6
7
  context 'running in dev environment' do
7
8
  before :each do
8
- expect(PuppetHerald).to receive(:is_in_dev?).twice.and_return true
9
+ expect(PuppetHerald).to receive(:in_dev?).twice.and_return true
9
10
  expect(Dir).to receive(:glob).twice.and_return(['aaa.js', 'a/bbb.js', 'ccc_test.js'])
10
- PuppetHerald::Javascript::files
11
+ subject.files
11
12
  end
12
- after :each do
13
- PuppetHerald::Javascript::class_variable_set '@@files', nil
14
- end
15
- let(:files) { PuppetHerald::Javascript::files }
13
+ let(:files) { subject.files }
16
14
  it { files.size.should eq 2 }
17
15
  it { files.should include 'aaa.js' }
18
16
  it { files.should_not include 'ccc_test.js' }
@@ -20,14 +18,11 @@ describe PuppetHerald::Javascript, '.files' do
20
18
 
21
19
  context 'running in prod environment' do
22
20
  before :each do
23
- expect(PuppetHerald).to receive(:is_in_dev?).twice.and_return false
21
+ expect(PuppetHerald).to receive(:in_dev?).twice.and_return false
24
22
  expect(Dir).to receive(:glob).once.and_return(['aaa.js', 'a/bbb.js', 'ccc_test.js'])
25
- PuppetHerald::Javascript::files
26
- end
27
- after :each do
28
- PuppetHerald::Javascript::class_variable_set '@@files', nil
23
+ subject.files
29
24
  end
30
- let(:files) { PuppetHerald::Javascript::files }
25
+ let(:files) { subject.files }
31
26
  it { files.size.should eq 2 }
32
27
  it { files.should include 'aaa.js' }
33
28
  it { files.should_not include 'ccc_test.js' }
@@ -35,7 +30,7 @@ describe PuppetHerald::Javascript, '.files' do
35
30
  end
36
31
 
37
32
  describe PuppetHerald::Javascript, '.uglify' do
38
- subject { PuppetHerald::Javascript::uglify 'myapp.js.map' }
33
+ subject { PuppetHerald::Javascript.new.uglify 'myapp.js.map' }
39
34
 
40
35
  it { subject.size.should eq 2 }
41
36
  it { subject['js'].should_not be_empty }
@@ -37,8 +37,8 @@ describe PuppetHerald do
37
37
  describe '.environment' do
38
38
  it { subject::environment.should eq(:production) }
39
39
  end
40
- describe '.is_in_prod?' do
41
- it { subject.should be_is_in_prod }
40
+ describe '.in_prod?' do
41
+ it { subject.should be_in_prod }
42
42
  end
43
43
  end
44
44
 
@@ -49,8 +49,8 @@ describe PuppetHerald do
49
49
  describe '.environment' do
50
50
  it { subject::environment.should eq(:dev) }
51
51
  end
52
- describe '.is_in_prod?' do
53
- it { subject.should be_is_in_dev }
52
+ describe '.in_prod?' do
53
+ it { subject.should be_in_dev }
54
54
  end
55
55
  end
56
56
  end
@@ -1,13 +1,51 @@
1
1
  module.exports = function(config) {
2
2
  config.set({
3
+
4
+ basePath: '../..',
5
+
6
+ singleRun: true,
7
+
3
8
  frameworks: ['jasmine'],
4
9
 
10
+ reporters: ['story', 'coverage'],
11
+
12
+ preprocessors: {
13
+ // source files, that you wanna generate coverage for
14
+ // do not include tests or libraries
15
+ // (these files will be instrumented by Istanbul)
16
+ 'lib/puppet-herald/public/**/*.js': ['coverage'],
17
+ 'lib/puppet-herald/public/**/*.html': ['ng-html2js']
18
+ },
19
+
20
+ // optionally, configure the reporter
21
+ coverageReporter: {
22
+ dir : 'coverage/javascript',
23
+ reporters: [
24
+ // reporters not supporting the `file` property
25
+ { type: 'html', subdir: 'report-html' },
26
+ // reporters supporting the `file` property, use `subdir` to directly
27
+ // output them in the `dir` directory
28
+ { type: 'cobertura', subdir: '.', file: 'cobertura.txt' },
29
+ { type: 'text', subdir: '.', file: 'text.txt' },
30
+ { type: 'text-summary', subdir: '.', file: 'text-summary.txt' },
31
+ ]
32
+ },
33
+
34
+ ngHtml2JsPreprocessor: {
35
+ // strip this from the file path
36
+ stripPrefix: 'lib/puppet-herald/public/',
37
+ },
38
+
5
39
  files: [
6
- '../../node_modules/angular/angular.js',
7
- '../../node_modules/angular-loader/angular-loader.js',
8
- '../../node_modules/angular-mocks/angular-mocks.js',
9
- '../../node_modules/angular-route/angular-route.js',
10
- '../../lib/puppet-herald/public/**/*_test.js'
40
+ 'node_modules/angular/angular.js',
41
+ 'node_modules/angular-loader/angular-loader.js',
42
+ 'node_modules/angular-mocks/angular-mocks.js',
43
+ 'node_modules/angular-route/angular-route.js',
44
+ 'node_modules/moment/moment.js',
45
+ 'node_modules/angular-moment/angular-moment.js',
46
+ 'lib/puppet-herald/public/**/*.js',
47
+ 'lib/puppet-herald/public/**/*.html',
48
+ 'test/javascript/src/**/*.js'
11
49
  ]
12
50
  });
13
51
  };
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+
3
+ describe('herald module', function() {
4
+ beforeEach(module('herald'));
5
+
6
+ describe('AppController', function() {
7
+ var controller, scope, Page;
8
+ beforeEach(inject(function(_$controller_, _Page_) {
9
+ var $controller = _$controller_;
10
+ scope = {};
11
+ controller = $controller('AppController', { $scope: scope });
12
+ Page = _Page_;
13
+ }));
14
+
15
+ it('should have a `null` as page set by default', function() {
16
+ expect(controller.page).toEqual(null);
17
+ });
18
+
19
+ it('should have a ("Nodes", null) as page set, if Page.title("Nodes") was called before', function() {
20
+ Page.title('Nodes');
21
+ expect(controller.page).toEqual("Nodes");
22
+ expect(controller.target).toEqual(undefined);
23
+ });
24
+
25
+ it('should have a ("Report", 1234567) as page set, if Page.title("Report", 1234567) was called before', function() {
26
+ Page.title('Report', 1234567);
27
+ expect(controller.page).toEqual("Report");
28
+ expect(controller.target).toEqual(1234567);
29
+ });
30
+
31
+ it('should have a ("Node", "master") as page set, if Page.title("Node", "master", " - ") was called before', function() {
32
+ Page.title('Node', "master", ' - ');
33
+ expect(controller.page).toEqual("Node");
34
+ expect(controller.target).toEqual('master');
35
+ });
36
+
37
+ });
38
+
39
+ describe('routes mapping', function() {
40
+
41
+ var $route, $location, $rootScope, navigateTo;
42
+ beforeEach(module('nodes/nodes.html'));
43
+ beforeEach(module('node/node.html'));
44
+ beforeEach(module('report/report.html'));
45
+ beforeEach(inject(function(_$route_, _$location_, _$rootScope_) {
46
+ $route = _$route_;
47
+ $location = _$location_;
48
+ $rootScope = _$rootScope_;
49
+ navigateTo = function(address) {
50
+ expect($route.current).toBeUndefined();
51
+ $location.path(address);
52
+ $rootScope.$digest();
53
+ };
54
+ }));
55
+
56
+ it('should map NodesController for unknown address', function() {
57
+ expect($route.routes[null].redirectTo).toEqual('/nodes');
58
+ });
59
+ it('should map NodesController if given "/nodes"', function() {
60
+ expect($route.routes['/nodes'].controller).toBe('NodesController');
61
+ });
62
+
63
+ it('should navigate to "/nodes" if given "/" a address', function() {
64
+ navigateTo('/');
65
+ expect($route.current.controller).toBe('NodesController');
66
+ expect($route.current.originalPath).toBe('/nodes');
67
+ });
68
+
69
+ it('should navigate to "/nodes" if given "/non-existing-link-0" a address', function() {
70
+ navigateTo('/non-existing-link-0');
71
+ expect($route.current.controller).toBe('NodesController');
72
+ expect($route.current.originalPath).toBe('/nodes');
73
+ });
74
+
75
+ it('should navigate to "/node/1" if given "/node/1" a address', function() {
76
+ navigateTo('/node/1');
77
+ expect($route.current.controller).toBe('NodeController');
78
+ expect($route.current.originalPath).toBe('/node/:nodeId');
79
+ expect($route.current.pathParams.nodeId).toBe('1');
80
+ });
81
+
82
+ it('should navigate to "/report/1" if given "/report/1" a address', function() {
83
+ navigateTo('/report/1');
84
+ expect($route.current.controller).toBe('ReportController');
85
+ expect($route.current.originalPath).toBe('/report/:reportId');
86
+ expect($route.current.pathParams.reportId).toBe('1');
87
+ });
88
+
89
+ });
90
+ });
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ describe('herald.artifact module', function() {
4
+ beforeEach(module('herald.artifact'));
5
+
6
+ describe('app-version directive', function() {
7
+
8
+ var $controller, $compile, $rootScope;
9
+ // Store references to $rootScope and $compile
10
+ // so they are available to all tests in this describe block
11
+ beforeEach(inject(function(_$compile_, _$controller_, _$rootScope_){
12
+ // The injector unwraps the underscores (_) from around the parameter names when matching
13
+ $compile = _$compile_;
14
+ $controller = _$controller_;
15
+ $rootScope = _$rootScope_;
16
+ }));
17
+
18
+ it('should print current version', function() {
19
+
20
+ inject(function($compile, $rootScope, $injector) {
21
+ // Set up the mock http service responses
22
+ var $httpBackend = $injector.get('$httpBackend');
23
+ // backend definition common for all tests
24
+ var authRequestHandler = $httpBackend.when('GET', '/version.json')
25
+ .respond({version: 'TEST_VER'});
26
+ $httpBackend.expectGET('/version.json');
27
+
28
+ var element = $compile('<div><span app-version></span></div>')($rootScope);
29
+ expect(element.text()).toEqual('{{ artifact.version }}');
30
+ // fire all the watches, so the scope expression {{ artifact.version }} will be evaluated
31
+ $rootScope.$digest();
32
+ expect(element.text()).toEqual('0.0.0');
33
+ });
34
+ });
35
+ });
36
+ });
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ describe('herald.artifact module', function() {
4
+ beforeEach(module('herald.artifact'));
5
+
6
+ describe('ArtifactController', function() {
7
+
8
+ var $httpBackend, $rootScope, createController, authRequestHandler;
9
+
10
+ var mockValues = {
11
+ version: 'TEST_VER',
12
+ homepage: 'http://example.org/herald',
13
+ summary: 'herald',
14
+ package: 'herald',
15
+ license: 'Apache 2.0',
16
+ name: 'Puppet Herald'
17
+ };
18
+
19
+ beforeEach(inject(function($injector) {
20
+
21
+ // Set up the mock http service responses
22
+ $httpBackend = $injector.get('$httpBackend');
23
+ // backend definition common for all tests
24
+ authRequestHandler = $httpBackend.when('GET', '/version.json')
25
+ .respond(mockValues);
26
+
27
+ // Get hold of a scope (i.e. the root scope)
28
+ $rootScope = $injector.get('$rootScope');
29
+ // The $controller service is used to create instances of controllers
30
+ var $controller = $injector.get('$controller');
31
+
32
+ createController = function() {
33
+ $httpBackend.expectGET('/version.json');
34
+ var controller = $controller('ArtifactController', {'$scope' : $rootScope });
35
+ $httpBackend.flush();
36
+ return controller;
37
+ };
38
+ }));
39
+
40
+ afterEach(function() {
41
+ $httpBackend.verifyNoOutstandingExpectation();
42
+ $httpBackend.verifyNoOutstandingRequest();
43
+ });
44
+
45
+ it('should fetch version of artifact', function() {
46
+ expect(createController().version).toBe(mockValues.version);
47
+ });
48
+ it('should fetch homepage of artifact', function() {
49
+ expect(createController().homepage).toBe(mockValues.homepage);
50
+ });
51
+ it('should fetch package of artifact', function() {
52
+ expect(createController().package).toBe(mockValues.package);
53
+ });
54
+ it('should fetch summary of artifact', function() {
55
+ expect(createController().summary).toBe(mockValues.summary);
56
+ });
57
+ it('should fetch license of artifact', function() {
58
+ expect(createController().license).toBe(mockValues.license);
59
+ });
60
+ it('should fetch name of artifact', function() {
61
+ expect(createController().name).toBe(mockValues.name);
62
+ });
63
+ });
64
+ });
@@ -0,0 +1,159 @@
1
+ 'use strict';
2
+
3
+ describe('herald.directives module', function() {
4
+ beforeEach(module('herald.directives'));
5
+
6
+ describe('herald.directives.status-button module', function() {
7
+
8
+ beforeEach(module('herald.directives.status-button'));
9
+
10
+ describe('StatusButtonController', function() {
11
+ var controller, scope, location;
12
+
13
+ beforeEach(inject(function($injector) {
14
+ var $controller = $injector.get('$controller');
15
+ var $rootScope = $injector.get('$rootScope');
16
+ location = $injector.get('$location');
17
+ $rootScope.$on('$locationChangeStart', function(event, args) {
18
+ event.preventDefault();
19
+ })
20
+ var $scope = {};
21
+ scope = $scope;
22
+ controller = $controller('StatusButtonController', { $scope: $scope });
23
+ }));
24
+
25
+ it('should navigate to "/node/112" after issuing navigate() function', function() {
26
+ spyOn(location, 'path').and.returnValue(null);
27
+ expect(scope.navigate('/node/:id', 112)).toBe(undefined);
28
+ expect(location.path).toHaveBeenCalledWith('/node/112');
29
+ });
30
+
31
+ });
32
+
33
+ describe('colorizeStatus filter', function() {
34
+
35
+ var colorizeStatus;
36
+
37
+ beforeEach(inject(function($injector) {
38
+ var $filter = $injector.get('$filter');
39
+ colorizeStatus = $filter('colorizeStatus');
40
+ }));
41
+
42
+ it('should returns "default" when given null', function() {
43
+ expect(colorizeStatus(null)).toEqual('default');
44
+ });
45
+ it('should returns "default" when given undefined', function() {
46
+ expect(colorizeStatus(undefined)).toEqual('default');
47
+ });
48
+ it('should returns "default" when given undefined', function() {
49
+ expect(colorizeStatus('unknown')).toEqual('default');
50
+ });
51
+ it('should returns "success" when given "unchanged"', function() {
52
+ expect(colorizeStatus('unchanged')).toEqual('success');
53
+ });
54
+ it('should returns "info" when given "changed"', function() {
55
+ expect(colorizeStatus('changed')).toEqual('info');
56
+ });
57
+ it('should returns "danger" when given "failed"', function() {
58
+ expect(colorizeStatus('failed')).toEqual('danger');
59
+ });
60
+ it('should returns "warning" when given "pending"', function() {
61
+ expect(colorizeStatus('pending')).toEqual('warning');
62
+ });
63
+ });
64
+
65
+ describe('iconizeStatus filter', function() {
66
+
67
+ var iconizeStatus;
68
+
69
+ beforeEach(inject(function($injector) {
70
+ var $filter = $injector.get('$filter');
71
+ iconizeStatus = $filter('iconizeStatus');
72
+ }));
73
+
74
+ it('should returns "sign" when given null', function() {
75
+ expect(iconizeStatus(null)).toEqual('sign');
76
+ });
77
+ it('should returns "sign" when given undefined', function() {
78
+ expect(iconizeStatus(undefined)).toEqual('sign');
79
+ });
80
+ it('should returns "sign" when given undefined', function() {
81
+ expect(iconizeStatus('unknown')).toEqual('sign');
82
+ });
83
+ it('should returns "ok" when given "unchanged"', function() {
84
+ expect(iconizeStatus('unchanged')).toEqual('ok');
85
+ });
86
+ it('should returns "pencil" when given "changed"', function() {
87
+ expect(iconizeStatus('changed')).toEqual('pencil');
88
+ });
89
+ it('should returns "remove" when given "failed"', function() {
90
+ expect(iconizeStatus('failed')).toEqual('remove');
91
+ });
92
+ it('should returns "asterisk" when given "pending"', function() {
93
+ expect(iconizeStatus('pending')).toEqual('asterisk');
94
+ });
95
+ });
96
+
97
+ describe('ngStatusButton directive', function() {
98
+
99
+ var elm, scope, button;
100
+ beforeEach(module('components/directives/status-button.html'));
101
+ beforeEach(inject(function($rootScope, $compile){
102
+ var tpl = '<ng-status-button status="node.status" id="node.id" route="\'/node/:id\'"></ng-status-button>';
103
+ elm = angular.element(tpl);
104
+ scope = $rootScope;
105
+ $compile(elm)(scope);
106
+ scope.$digest();
107
+ button = elm.find('button');
108
+ }));
109
+
110
+ describe('with scope without any values', function() {
111
+
112
+ it('should embed a one element of type "button"', function() {
113
+ expect(button.length).toBe(1);
114
+ });
115
+ it('should embed an element with class "btn-default"', function() {
116
+ expect(button.hasClass('btn-default')).toBe(true);
117
+ });
118
+ it('should embed an element with class "glyphicon-sign"', function() {
119
+ expect(button.hasClass('glyphicon-sign')).toBe(true);
120
+ });
121
+ it('should embed a button with text " "', function() {
122
+ expect(button.text()).toEqual(' ');
123
+ });
124
+
125
+ });
126
+
127
+ describe('with values { status: "unchanged", id: 16 } given', function() {
128
+
129
+ beforeEach(function() {
130
+ scope.$apply(function() {
131
+ scope.node = {
132
+ status: "unchanged",
133
+ id: 16
134
+ };
135
+ });
136
+ });
137
+
138
+ it('should embed a one element of type "button"', function() {
139
+ expect(button.length).toBe(1);
140
+ });
141
+ it('should embed an element with class "btn-success"', function() {
142
+ expect(button.hasClass('btn-success')).toBe(true);
143
+ });
144
+ it('should embed an element with class "glyphicon-ok"', function() {
145
+ expect(button.hasClass('glyphicon-ok')).toBe(true);
146
+ });
147
+ it('should embed a button with text " UNCHANGED"', function() {
148
+ expect(button.text()).toEqual(' UNCHANGED');
149
+ });
150
+ it('should embed a button with onclick == "navigate(route, id)"', function() {
151
+ expect(button.attr('ng-click')).toEqual("navigate(route, id)");
152
+ });
153
+
154
+ });
155
+
156
+ });
157
+ });
158
+
159
+ });