diff --git a/app/js/components/rule/ruleToggle/ruleToggle.directive.js b/app/js/components/rule/ruleToggle/ruleToggle.directive.js index 3a42e763..94cfc5a7 100644 --- a/app/js/components/rule/ruleToggle/ruleToggle.directive.js +++ b/app/js/components/rule/ruleToggle/ruleToggle.directive.js @@ -3,6 +3,12 @@ const componentsModule = require('../../'); const pub = {}; +const priv = { + text: { + UNIGNORE_RULE: 'Unignore Rule', + IGNORE_RULE: 'Ignore Rule' + } +}; pub.ackAction = ($scope, Ack) => { return () => { @@ -18,11 +24,10 @@ pub.ackAction = ($scope, Ack) => { }; pub.init = ($scope, gettextCatalog) => { - $scope.text = gettextCatalog.getString('Ignore Rule'); + $scope.text = gettextCatalog.getString(priv.text.IGNORE_RULE); if ($scope.rule && $scope.rule.ack_id) { - $scope.text = gettextCatalog.getString('Unignore Rule'); + $scope.text = gettextCatalog.getString(priv.text.UNIGNORE_RULE); } - }; /** @@ -48,7 +53,7 @@ function ruleToggle() { } componentsModule.directive('ruleToggle', ruleToggle); - if (componentsModule.testMode) { module.exports.pub = pub; + module.exports.priv = priv; } diff --git a/app/js/components/rule/ruleToggle/ruleToggle.spec.js b/app/js/components/rule/ruleToggle/ruleToggle.unit.js similarity index 68% rename from app/js/components/rule/ruleToggle/ruleToggle.spec.js rename to app/js/components/rule/ruleToggle/ruleToggle.unit.js index cc4a097e..a0dab61f 100644 --- a/app/js/components/rule/ruleToggle/ruleToggle.spec.js +++ b/app/js/components/rule/ruleToggle/ruleToggle.unit.js @@ -7,6 +7,29 @@ const ruleToggle = require('./ruleToggle.directive'); const unit = require('../../../../../unit'); describe('ruleToggle', () => { + describe('init()', () => { + const gettextCatalog = { + getString: (str) => { return str; } + }; + + it('should Ignore Rule', () => { + const scope = {}; + ruleToggle.pub.init(scope, gettextCatalog); + scope.text.should.equal(ruleToggle.priv.text.IGNORE_RULE); + }); + + it('should Unignore Rule', () => { + const scope = { + rule: { + ack_id: 1235 + } + }; + + ruleToggle.pub.init(scope, gettextCatalog); + scope.text.should.equal(ruleToggle.priv.text.UNIGNORE_RULE); + }); + }); + describe('ackAction()', () => { it('should delete an ack', () => { const scope = { diff --git a/gulp/tasks/unit.js b/gulp/tasks/unit.js index e5682b8d..3c872fde 100644 --- a/gulp/tasks/unit.js +++ b/gulp/tasks/unit.js @@ -1,12 +1,18 @@ +/*global require, __dirname*/ 'use strict'; -var gulp = require('gulp'); -var config = require('../config'); -var Server = require('karma').Server; -var path = require('path'); +const gulp = require('gulp'); +const mocha = require('gulp-mocha'); +const config = require('../config'); +const Server = require('karma').Server; +const path = require('path'); -gulp.task('unit', ['views'], function (done) { +gulp.task('unit', function () { + gulp.src('app/js/**/*.unit.js', { read: false }) + .pipe(mocha()); +}); +gulp.task('unit-browser', ['views'], function (done) { new Server({ configFile: path.normalize(path.join(__dirname, '..', '..', config.test.karma)), singleRun: true diff --git a/gulp/tasks/watch.js b/gulp/tasks/watch.js index 68bf7511..3f29f5d4 100644 --- a/gulp/tasks/watch.js +++ b/gulp/tasks/watch.js @@ -19,6 +19,10 @@ gulp.task('watch', [ 'browserSync', 'server'], function () { }); }); +gulp.task('unit:watch', [], function () { + gulp.watch('app/js/**/*js', ['unit']); +}); + gulp.task('smoke:watch', [], function () { gulp.watch(config.views.watch.concat(exclude), ['smoke:run']); gulp.watch('./smoketest/*js', ['smoke:run']); diff --git a/package.json b/package.json index fd4716e4..3838aa50 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "gulp-jscs": "~4.1.x", "gulp-jscs-stylish": "~1.4.x", "gulp-jshint": "^2.0.4", + "gulp-mocha": "^5.0.0", "gulp-notify": "~3.2.x", "gulp-plumber": "~1.2.x", "gulp-protractor": "~4.1.x",