diff --git a/client/client/src/web-access/web-access.spec.js b/client/client/src/web-access/web-access.spec.js new file mode 100644 index 000000000..eea0edfd7 --- /dev/null +++ b/client/client/src/web-access/web-access.spec.js @@ -0,0 +1,30 @@ +import VNClientWebAccess from './web-access.js'; +describe('some component', () => { + let instance; + var $scope; + var $http; + var vnApp = {showError: jasmine.createSpy('showError')}; + beforeEach(() => { + instance = new VNClientWebAccess($scope, $http, vnApp); + }); + + it('should throw an error when password is empty', () => { + instance.newPassword = ''; + instance.onPassChange('ACCEPT'); + expect(vnApp.showError).toHaveBeenCalledWith(`Passwords can't be empty`); + }); + + it('should throw an error when password repeat doesnt match', () => { + instance.newPassword = 'test'; + instance.repeatPassword = 'notTheSame'; + instance.onPassChange('ACCEPT'); + expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`); + }); + + it('', () => { + instance.newPassword = 'test'; + instance.repeatPassword = 'notTheSame'; + instance.onPassChange('ACCEPT'); + expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`); + }); +}); diff --git a/client/test_index.js b/client/test_index.js new file mode 100644 index 000000000..8cd58d588 --- /dev/null +++ b/client/test_index.js @@ -0,0 +1,5 @@ +// require all modules ending in ".spec" from the +// current directory and all subdirectories + +var testsContext = require.context('./', true, /\.spec\.js$/); +testsContext.keys().forEach(testsContext); diff --git a/jasmine.js b/jasmine.js new file mode 100644 index 000000000..e1fdf9fdd --- /dev/null +++ b/jasmine.js @@ -0,0 +1,9 @@ +const Jasmine = require('jasmine'); +const jasmine = new Jasmine(); + +jasmine.loadConfig({ + spec_dir: '', + spec_files: ['*[Ss]pec.js'] +}); + +jasmine.execute(); diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..6934f0e34 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,83 @@ +var webpackConfig = require('./webpack.config.js'); +delete webpackConfig.entry; +delete webpackConfig.output; +webpackConfig.devtool = 'inline-source-map'; +webpackConfig.plugins = []; + +// Karma configuration +// Generated on Tue Aug 22 2017 13:37:43 GMT+0200 (CEST) + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + // list of files / patterns to load in the browser + files: [ + {pattern: 'client/test_index.js', watched: false} + ], + + // list of files to exclude + exclude: [], + + webpack: webpackConfig, + + webpackMiddleware: { + stats: 'errors-only' + }, + + webpackServer: { + noInfo: true + }, + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + './client/test_index.js': ['webpack', 'sourcemap'] + }, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['Chrome'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity, + + plugins: [ + 'karma-jasmine', + 'karma-webpack', + 'karma-requirejs', + 'karma-chrome-launcher', + 'karma-browserify', + 'karma-sourcemap-loader' + ] + }); +}; diff --git a/package.json b/package.json index 2050ddab2..dbbc94efb 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "validator": "^6.2.1" }, "devDependencies": { + "angular-mocks": "^1.6.6", "babel": "^6.5.2", "babel-core": "^6.22.1", "babel-loader": "^6.4.1", @@ -42,10 +43,19 @@ "gulp-wrap": "^0.13.0", "gulp-yaml": "^1.0.1", "html-loader": "^0.4.4", + "jasmine": "^2.7.0", + "karma": "^1.7.0", + "karma-chrome-launcher": "^2.2.0", + "karma-firefox-launcher": "^1.0.1", + "karma-jasmine": "^1.1.0", + "karma-requirejs": "^1.1.0", + "karma-sourcemap-loader": "^0.3.7", + "karma-webpack": "^2.0.4", "merge-stream": "^1.0.1", "node-sass": "^3.11.0", "pre-commit": "^1.1.3", "raw-loader": "*", + "requirejs": "^2.3.5", "sass-loader": "^4.0.2", "style-loader": "^0.13.1", "webpack": "^2.2.0", diff --git a/webpack.config.js b/webpack.config.js index c4e78fced..090eadc36 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -54,7 +54,7 @@ var config = { }, plugins: [ new webpack.optimize.CommonsChunkPlugin({ - names: ['bundle.vendor', 'bundle.manifest'] + names: ['bundle.vendor', 'bundle.manifest'], }) ], devtool: 'source-map'