src: '<%= pkg.sources %>js/require.js', dest: '<%= pkg.assets %>js/require.js'
- karma:
- unit:
- configFile: 'karma.conf.js'
- singleRun: true
- logLevel: 'DEBUG'
-
-
express:
dev:
options:
options:
test: true
'no-colors': true
- src: ['<%= pkg.sources %>js/tests/e2e/tests/**/*.js']
+ src: ['<%= pkg.sources %>js/tests/**/*-spec.js']
watch:
'concat:build',
'requirejs', 'clean:js', 'copy:build', 'copy:requirejs', 'clean:build']
- grunt.registerTask 'test', ['coffee:build', 'handlebars:build', 'copy:js', 'concat:dev', 'karma:unit', 'express', 'casper']
+ grunt.registerTask 'test', ['coffee:build', 'handlebars:build', 'copy:js', 'concat:dev', 'express', 'casper']
+++ /dev/null
-/* global module:false, karma:false */
-
-// Karma configuration for JS application
-
-// GLOBAL INSTALLATION
-// sonar-server$ npm install -g
-// sonar-server$ karma start
-
-// LOCAL INSTALLATION
-// sonar-server$ npm install
-// sonar-server$ ./node_modules/.bin/karma start
-
-module.exports = function(config) {
- config.set({
-
- // base path, that will be used to resolve files and exclude
- basePath: 'src/main/webapp/js',
-
-
- // frameworks to use
- frameworks: ['jasmine'],
-
-
- // list of files / patterns to load in the browser
- files: [
- // dependencies
- 'third-party/jquery.js',
- 'third-party/underscore.js',
- 'require.js',
- 'translate.js',
- 'common/inputs.js',
- 'widgets/base.js',
-
- // libs
- { pattern: 'third-party/**/*.js', included: false },
-
- // common
- { pattern: 'common/**/*.js', included: false },
-
- // app
- { pattern: 'navigator/**/*.js', included: false },
- { pattern: 'quality-gate/**/*.js', included: false },
-
- // tests
- { pattern: 'tests/**/*Spec.js', included: false },
-
- 'tests/main.js'
- ],
-
-
- // list of files to exclude
- exclude: [
-
- ],
-
-
- preprocessors: {
- 'navigator/**/*.js': 'coverage',
- 'common/inputs.js': 'coverage',
- 'translate.js': 'coverage'
- },
-
-
- plugins: [
- 'karma-jasmine',
- 'karma-phantomjs-launcher',
- 'karma-coverage',
- 'karma-junit-reporter'
- ],
-
-
- // test results reporter to use
- reporters: ['progress', 'coverage', 'junit'],
-
-
- coverageReporter: {
- type : 'lcovonly',
- dir : '../../../../target/karma/coverage/'
- },
-
- junitReporter: {
- outputFile : '../../../../target/karma/test-results.xml'
- },
-
- // WARNING - the 2 following ports should not be hardcoded in CI environments
- // web server port
- port: 9876,
-
-
- // cli runner port
- runnerPort: 9100,
-
-
- // enable / disable colors in the output (reporters and logs)
- colors: true,
-
-
- // level of logging
- // possible values: karma.LOG_DISABLE || karma.LOG_ERROR || karma.LOG_WARN || karma.LOG_INFO || karma.LOG_DEBUG
- logLevel: config.LOG_INFO,
-
-
- // enable / disable watching file and executing tests whenever any file changes
- autoWatch: false,
-
-
- // Start these browsers, currently available:
- // - Chrome
- // - ChromeCanary
- // - Firefox
- // - Opera
- // - Safari (only Mac)
- // - PhantomJS
- // - IE (only Windows)
- browsers: ['PhantomJS'],
-
-
- // If browser does not capture in given timeout [ms], kill it
- captureTimeout: 60000,
-
-
- // Continuous Integration mode
- // if true, it capture browsers, run tests and exit
- singleRun: false
- });
-};
+++ /dev/null
-$ = jQuery
-
-describe 'WORK_DUR suite', ->
-
- beforeEach ->
- window.SS = {}
- window.SS.phrases =
- 'work_duration':
- 'x_days': '{0}d', 'x_hours': '{0}h', 'x_minutes': '{0}min'
-
- @input = $('<input type="text">')
- @input.appendTo $('body')
- @input.data 'type', 'WORK_DUR'
-
-
- it 'converts', ->
- @input.originalVal '2d 7h 13min'
- expect(@input.val()).toBe 1393
-
- it 'converts only days', ->
- @input.originalVal '1d'
- expect(@input.val()).toBe 480
-
- it 'converts hours with minutes', ->
- @input.originalVal '2h 30min'
- expect(@input.val()).toBe 150
-
- it 'converts zero', ->
- @input.originalVal '0'
- expect(@input.val()).toBe 0
-
-
- it 'restores', ->
- @input.val 1393
- expect(@input.originalVal()).toBe '2d 7h 13min'
-
- it 'restores zero', ->
- @input.val '0'
- expect(@input.originalVal()).toBe '0'
-
-
- it 'returns initially incorrect value', ->
- @input.val 'something'
- expect(@input.val()).toBe 'something'
-
-
-describe 'RATING suite', ->
-
- beforeEach ->
- @input = $('<input type="text">')
- @input.appendTo $('body')
- @input.data 'type', 'RATING'
-
-
- it 'converts A', ->
- @input.originalVal 'A'
- expect(@input.val()).toBe 1
-
-
- it 'converts B', ->
- @input.originalVal 'B'
- expect(@input.val()).toBe 2
-
-
- it 'converts E', ->
- @input.originalVal 'E'
- expect(@input.val()).toBe 5
-
-
- it 'does not convert F', ->
- @input.originalVal 'F'
- expect(@input.val()).toBe 'F'
-
-
- it 'restores A', ->
- @input.val 1
- expect(@input.originalVal()).toBe 'A'
-
-
- it 'restores E', ->
- @input.val 5
- expect(@input.originalVal()).toBe 'E'
-
-
- it 'returns initially incorrect value', ->
- @input.val 'something'
- expect(@input.val()).toBe 'something'
+++ /dev/null
-$ = jQuery
-
-describe 'translation "t" suite', ->
-
- beforeEach ->
- window.messages =
- 'something': 'SOMETHING'
- 'something_with_underscore': 'SOMETHING_WITH_UNDERSCORE'
- 'something_with{braces}': 'SOMETHING_WITH{braces}'
-
- window.SS =
- phrases:
- 'something': 'SOMETHING ANOTHER'
-
-
- afterEach ->
- window.messages = window.SS = undefined
-
-
- it 'translates', ->
- expect(t('something')).toBe 'SOMETHING'
-
-
- it 'translates with underscore', ->
- expect(t('something_with_underscore')).toBe 'SOMETHING_WITH_UNDERSCORE'
-
-
- it 'translates with braces', ->
- expect(t('something_with{braces}')).toBe 'SOMETHING_WITH{braces}'
-
-
- it 'fallbacks to "translate"', ->
- window.messages = undefined
- expect(t('something')).toBe 'SOMETHING ANOTHER'
-
-
- it 'returns the key when no translation', ->
- expect(t('something_another')).toBe 'something_another'
-
-
-
-describe 'translation "translate" suite', ->
-
- beforeEach ->
- window.SS =
- phrases:
- 'something': 'SOMETHING'
- 'something_with_underscore': 'SOMETHING_WITH_UNDERSCORE'
- 'something_with{braces}': 'SOMETHING_WITH{braces}'
-
-
- afterEach ->
- window.messages = window.SS = undefined
-
-
- it 'translates', ->
- expect(translate('something')).toBe 'SOMETHING'
-
-
- it 'translates with underscore', ->
- expect(translate('something_with_underscore')).toBe 'SOMETHING_WITH_UNDERSCORE'
-
-
- it 'translates with braces', ->
- expect(translate('something_with{braces}')).toBe 'SOMETHING_WITH{braces}'
-
-
- it 'returns the key when no translation', ->
- expect(translate('something_another')).toBe 'something_another'
-
-
- it 'does not fail when there is no dictionary', ->
- window.SS = undefined
- expect(translate('something_another')).toBe 'something_another'
-
+++ /dev/null
-$ = jQuery
-
-describe 'base widget suite', ->
-
- it 'exists', ->
- expect(window.SonarWidgets).toBeDefined()
- expect(window.SonarWidgets.BaseWidget).toBeDefined()
-
-
- it 'adds fields', ->
- widget = new window.SonarWidgets.BaseWidget()
- widget.addField 'fieldName', 1
-
- expect(typeof widget.fieldName).toBe 'function'
- expect(widget.fieldName()).toBe 1
-
- expect(widget.fieldName(2)).toBe widget
- expect(widget.fieldName()).toBe 2
-
-
- it 'adds metrics', ->
- widget = new window.SonarWidgets.BaseWidget()
- widget.addField 'metrics', 'metricA': { name: 'Metric A', someField: 2 }
- widget.addField 'metricsPriority', ['metricA']
- widget.addMetric 'myMetric', 0
-
- expect(widget.myMetric).toBeDefined()
- expect(widget.myMetric.key).toBe 'metricA'
- expect(widget.myMetric.name).toBe 'Metric A'
- expect(widget.myMetric.someField).toBe 2
- expect(typeof widget.myMetric.value).toBe 'function'
- expect(typeof widget.myMetric.formattedValue).toBe 'function'
-
-
- it 'has default properties', ->
- widget = new window.SonarWidgets.BaseWidget()
-
- expect(widget.components).toBeDefined()
- expect(widget.metrics).toBeDefined()
- expect(widget.metricsPriority).toBeDefined()
- expect(widget.options).toBeDefined()
-
-
- it 'created "translate" string', ->
- widget = new window.SonarWidgets.BaseWidget()
-
- expect(widget.trans(1, 2)).toBe 'translate(1,2)'
\ No newline at end of file
<script type="text/javascript">
var baseUrl = '..';
var $j = jQuery.noConflict();
+ window.suppressTranslationWarnings = true;
$j(document).ready(function () {
$j('.open-modal').modal();
-
$j('<scr' + 'ipt data-main="../js/quality-gate/app" src="../js/require.js"></scr' + 'ipt>').appendTo('body');
});
</script>
--- /dev/null
+// Dump log messages
+casper.on('remote.message', function(message) {
+ this.echo('Log: '+ message, 'LOG');
+});
+
+// Dump uncaught errors
+casper.on('page.error', function(msg, trace) {
+ this.echo('Error: ' + msg, 'ERROR');
+});
+
+
+casper.test.begin('App is setup correctly', function suite(test) {
+
+ // Register mockjax requests on loading of requirejs
+ casper.options.onResourceRequested = function(instance, requestData, networkRequest) {
+ if (requestData.url.indexOf('require') >= 0) {
+ // Here, instance is the running instance of casperjs
+ instance.page.includeJs('../js/third-party/jquery.mockjax.js', function() {
+ instance.page.evaluate(function() {
+ jQuery.mockjaxSettings.contentType = 'text/json';
+ jQuery.mockjaxSettings.responseTime = 250;
+
+ jQuery.mockjax({
+ url: '../api/l10n/index',
+ responseText: JSON.stringify({
+ 'quality_gates.page': 'Quality Gates'
+ })
+ });
+
+ jQuery.mockjax({
+ url: '../api/qualitygates/app',
+ responseText: JSON.stringify({
+ "edit": false,
+ "periods": [
+ {
+ "key": 1,
+ "text": "since previous analysis"
+ },
+ {
+ "key": 2,
+ "text": "over 365 days"
+ },
+ {
+ "key": 3,
+ "text": "since previous version"
+ },
+ {
+ "key": 4,
+ "text": "over period 4 - defined at project level"
+ },
+ {
+ "key": 5,
+ "text": "over period 5 - defined at project level"
+ }
+ ],
+ "metrics": [
+ {
+ "id": 62,
+ "key": "blocker_violations",
+ "name": "Blocker issues",
+ "type": "INT",
+ "domain": "Issues",
+ "hidden": false
+ },
+ {
+ "id": 37,
+ "key": "new_coverage",
+ "name": "Coverage on new code",
+ "type": "PERCENT",
+ "domain": "Tests",
+ "hidden": false
+ },
+ {
+ "id": 63,
+ "key": "critical_violations",
+ "name": "Critical issues",
+ "type": "INT",
+ "domain": "Issues",
+ "hidden": false
+ },
+ {
+ "id": 154,
+ "key": "sqale_effort_to_grade_a",
+ "name": "Effort to rating A",
+ "type": "WORK_DUR",
+ "domain": "SQALE",
+ "hidden": false
+ },
+ {
+ "id": 218,
+ "key": "open_issues",
+ "name": "Open issues",
+ "type": "INT",
+ "domain": "Issues",
+ "hidden": false
+ },
+ {
+ "id": 219,
+ "key": "reopened_issues",
+ "name": "Reopened issues",
+ "type": "INT",
+ "domain": "Issues",
+ "hidden": false
+ },
+ {
+ "id": 32,
+ "key": "skipped_tests",
+ "name": "Skipped unit tests",
+ "type": "INT",
+ "domain": "Tests",
+ "hidden": false
+ },
+ {
+ "id": 31,
+ "key": "test_errors",
+ "name": "Unit test errors",
+ "type": "INT",
+ "domain": "Tests",
+ "hidden": false
+ },
+ {
+ "id": 33,
+ "key": "test_failures",
+ "name": "Unit test failures",
+ "type": "INT",
+ "domain": "Tests",
+ "hidden": false
+ }
+ ]
+ })
+ });
+
+
+ jQuery.mockjax({
+ url: "../api/qualitygates/list",
+ responseText: JSON.stringify({
+ "qualitygates": [
+ {
+ "id": 1,
+ "name": "Default Gate"
+ }
+ ],
+ "default": 1
+ })
+ });
+
+ jQuery.mockjax({
+ url: "../api/qualitygates/show?id=1",
+ responseText: {
+ "id": 1,
+ "name": "Default Gate",
+ "conditions": [
+ {
+ "id": 1,
+ "metric": "blocker_violations",
+ "op": "GT",
+ "warning": "",
+ "error": "0"
+ },
+ {
+ "id": 2,
+ "metric": "new_coverage",
+ "op": "LT",
+ "warning": "",
+ "error": "80",
+ "period": 3
+ },
+ {
+ "id": 3,
+ "metric": "critical_violations",
+ "op": "GT",
+ "warning": "",
+ "error": "0"
+ },
+ {
+ "id": 4,
+ "metric": "sqale_effort_to_grade_a",
+ "op": "GT",
+ "warning": "",
+ "error": "0"
+ },
+ {
+ "id": 5,
+ "metric": "open_issues",
+ "op": "GT",
+ "warning": "0",
+ "error": ""
+ },
+ {
+ "id": 6,
+ "metric": "reopened_issues",
+ "op": "GT",
+ "warning": "0",
+ "error": ""
+ },
+ {
+ "id": 7,
+ "metric": "skipped_tests",
+ "op": "GT",
+ "warning": "0",
+ "error": ""
+ },
+ {
+ "id": 8,
+ "metric": "test_errors",
+ "op": "GT",
+ "warning": "",
+ "error": "0"
+ },
+ {
+ "id": 9,
+ "metric": "test_failures",
+ "op": "GT",
+ "warning": "",
+ "error": "0"
+ }
+ ]
+ }
+ });
+
+ });
+ });
+ }
+ };
+
+ // See API at http://docs.casperjs.org/en/latest/modules/index.html
+
+ casper.start('http://localhost:3000/pages/quality-gates.html', function() {
+ test.assertTitle('Quality Gates');
+ });
+
+ casper.waitWhileSelector("div#quality-gates-loader", function() {
+
+ casper.waitForSelector('li.active', function() {
+ test.assertElementCount('li.active', 1);
+ test.assertSelectorHasText('ol.navigator-results-list li', 'Default Gate');
+ });
+
+ casper.waitForSelector('div.navigator-header', function() {
+ test.assertSelectorHasText('div.navigator-header h1', 'Default Gate');
+ });
+
+ casper.waitForSelector('table.quality-gate-conditions tbody tr:nth-child(9)', function() {
+ test.assertElementCount('table.quality-gate-conditions tbody tr', 9);
+ });
+ });
+
+ casper.run(function() {
+ test.done();
+ });
+});
+++ /dev/null
-// Dump log messages
-casper.on('remote.message', function(message) {
- this.echo('Log: '+ message, 'LOG');
-});
-
-// Dump uncaught errors
-casper.on('page.error', function(msg, trace) {
- this.echo('Error: ' + msg, 'ERROR');
-});
-
-
-casper.test.begin('App is setup correctly', function suite(test) {
-
- // Register mockjax requests on loading of requirejs
- casper.options.onResourceRequested = function(instance, requestData, networkRequest) {
- if (requestData.url.indexOf('require') >= 0) {
- // Here, instance is the running instance of casperjs
- instance.page.includeJs('../js/third-party/jquery.mockjax.js', function() {
- instance.page.evaluate(function() {
- jQuery.mockjaxSettings.contentType = 'text/json';
- jQuery.mockjaxSettings.responseTime = 250;
-
- jQuery.mockjax({
- url: '../api/l10n/index',
- responseText: JSON.stringify({
- 'quality_gates.page': 'Quality Gates'
- })
- });
-
- jQuery.mockjax({
- url: '../api/qualitygates/app',
- responseText: JSON.stringify({
- "edit": false,
- "periods": [
- {
- "key": 1,
- "text": "since previous analysis"
- },
- {
- "key": 2,
- "text": "over 365 days"
- },
- {
- "key": 3,
- "text": "since previous version"
- },
- {
- "key": 4,
- "text": "over period 4 - defined at project level"
- },
- {
- "key": 5,
- "text": "over period 5 - defined at project level"
- }
- ],
- "metrics": [
- {
- "id": 62,
- "key": "blocker_violations",
- "name": "Blocker issues",
- "type": "INT",
- "domain": "Issues",
- "hidden": false
- },
- {
- "id": 37,
- "key": "new_coverage",
- "name": "Coverage on new code",
- "type": "PERCENT",
- "domain": "Tests",
- "hidden": false
- },
- {
- "id": 63,
- "key": "critical_violations",
- "name": "Critical issues",
- "type": "INT",
- "domain": "Issues",
- "hidden": false
- },
- {
- "id": 154,
- "key": "sqale_effort_to_grade_a",
- "name": "Effort to rating A",
- "type": "WORK_DUR",
- "domain": "SQALE",
- "hidden": false
- },
- {
- "id": 218,
- "key": "open_issues",
- "name": "Open issues",
- "type": "INT",
- "domain": "Issues",
- "hidden": false
- },
- {
- "id": 219,
- "key": "reopened_issues",
- "name": "Reopened issues",
- "type": "INT",
- "domain": "Issues",
- "hidden": false
- },
- {
- "id": 32,
- "key": "skipped_tests",
- "name": "Skipped unit tests",
- "type": "INT",
- "domain": "Tests",
- "hidden": false
- },
- {
- "id": 31,
- "key": "test_errors",
- "name": "Unit test errors",
- "type": "INT",
- "domain": "Tests",
- "hidden": false
- },
- {
- "id": 33,
- "key": "test_failures",
- "name": "Unit test failures",
- "type": "INT",
- "domain": "Tests",
- "hidden": false
- }
- ]
- })
- });
-
-
- jQuery.mockjax({
- url: "../api/qualitygates/list",
- responseText: JSON.stringify({
- "qualitygates": [
- {
- "id": 1,
- "name": "Default Gate"
- }
- ],
- "default": 1
- })
- });
-
- jQuery.mockjax({
- url: "../api/qualitygates/show?id=1",
- responseText: {
- "id": 1,
- "name": "Default Gate",
- "conditions": [
- {
- "id": 1,
- "metric": "blocker_violations",
- "op": "GT",
- "warning": "",
- "error": "0"
- },
- {
- "id": 2,
- "metric": "new_coverage",
- "op": "LT",
- "warning": "",
- "error": "80",
- "period": 3
- },
- {
- "id": 3,
- "metric": "critical_violations",
- "op": "GT",
- "warning": "",
- "error": "0"
- },
- {
- "id": 4,
- "metric": "sqale_effort_to_grade_a",
- "op": "GT",
- "warning": "",
- "error": "0"
- },
- {
- "id": 5,
- "metric": "open_issues",
- "op": "GT",
- "warning": "0",
- "error": ""
- },
- {
- "id": 6,
- "metric": "reopened_issues",
- "op": "GT",
- "warning": "0",
- "error": ""
- },
- {
- "id": 7,
- "metric": "skipped_tests",
- "op": "GT",
- "warning": "0",
- "error": ""
- },
- {
- "id": 8,
- "metric": "test_errors",
- "op": "GT",
- "warning": "",
- "error": "0"
- },
- {
- "id": 9,
- "metric": "test_failures",
- "op": "GT",
- "warning": "",
- "error": "0"
- }
- ]
- }
- });
-
- });
- });
- }
- };
-
- // See API at http://docs.casperjs.org/en/latest/modules/index.html
-
- casper.start('http://localhost:3000/pages/quality-gates.html', function() {
- test.assertTitle('Quality Gates');
- });
-
- casper.waitWhileSelector("div#quality-gates-loader", function() {
-
- casper.waitForSelector('li.active', function() {
- test.assertElementCount('li.active', 1);
- test.assertSelectorHasText('ol.navigator-results-list li', 'Default Gate');
- });
-
- casper.waitForSelector('div.navigator-header', function() {
- test.assertSelectorHasText('div.navigator-header h1', 'Default Gate');
- });
-
- casper.waitForSelector('table.quality-gate-conditions tbody tr:nth-child(9)', function() {
- test.assertElementCount('table.quality-gate-conditions tbody tr', 9);
- });
- });
-
- casper.run(function() {
- test.done();
- });
-});
+++ /dev/null
-window.__karma__.loaded = function() {};
-
-var tests = [];
-for (var file in window.__karma__.files) {
- if (window.__karma__.files.hasOwnProperty(file)) {
- if (/Spec\.js$/.test(file)) {
- tests.push(file);
- }
- }
-}
-
-requirejs.config({
- baseUrl: '/base',
-
- paths: {
- 'backbone': 'third-party/backbone',
- 'backbone.marionette': 'third-party/backbone.marionette',
- 'handlebars': 'third-party/handlebars',
- 'moment': 'third-party/moment'
- },
-
- shim: {
- 'backbone.marionette': {
- deps: ['backbone'],
- exports: 'Marionette'
- },
- 'backbone': {
- exports: 'Backbone'
- },
- 'handlebars': {
- exports: 'Handlebars'
- },
- 'moment': {
- exports: 'moment'
- }
- },
-
- // ask Require.js to load these files (all our tests)
- deps: tests,
-
- // start test run, once Require.js is done
- callback: window.__karma__.start
-
-});
+++ /dev/null
-define(['navigator/filters/base-filters'], function(BaseFilters) {
-
- describe('BaseFilterView', function() {
-
- it('initializes', function() {
- var baseFilterView = new BaseFilters.BaseFilterView({
- model: new BaseFilters.Filter()
- });
- expect(baseFilterView.detailsView).toBeDefined();
- expect(baseFilterView.detailsView.options.filterView).toBe(baseFilterView);
- });
-
- });
-
-});
+++ /dev/null
-define(['navigator/filters/base-filters', 'navigator/filters/choice-filters'], function(BaseFilters, ChoiceFilters) {
-
- describe('BaseFilterView', function() {
- var choices, choiceFilter, choiceFilterView;
-
- beforeEach(function() {
- choices = {
- 'ONE': 'one',
- 'TWO': 'two',
- 'THREE': 'three',
- '!OPPOSITE': 'opposite'
- };
-
- choiceFilter = new BaseFilters.Filter({
- name: 'Choice Filter Name',
- property: 'choiceFilterProperty',
- type: ChoiceFilters.ChoiceFilterView,
- enabled: true,
- optional: false,
- choices: choices
- });
-
- choiceFilterView = new ChoiceFilters.ChoiceFilterView({
- model: choiceFilter
- });
- });
-
- it('creates choices', function() {
- expect(choiceFilterView.choices).toBeDefined();
- expect(choiceFilterView.choices.length).toBe(Object.keys(choices).length);
- });
-
- it('does not have selected by default', function() {
- expect(choiceFilterView.getSelected().length).toBe(0);
- });
-
- });
-
-});
(function() {
+ window.suppressTranslationWarnings = false;
+
var warn = function(message) {
- if (console != null && typeof console.warn === 'function') {
- console.warn(message);
+ if (!window.suppressTranslationWarnings) {
+ if (console != null && typeof console.warn === 'function') {
+ console.warn(message);
+ }
}
};
window.messages = bundle;
localStorage.setItem('l10n.bundle', JSON.stringify(bundle));
- } else if (jqXHR.status === 304) {
+ } else if (jqXHR.status == 304) {
window.messages = JSON.parse(localStorage.getItem('l10n.bundle'));
}
});