aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-07-02 19:01:45 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-07-04 09:51:08 +0200
commit46c588d9db7395d6185b95038a04dccf44e079b0 (patch)
tree7a374d1641d7e0f887793c19f3020e1a5267b44d
parent24613f816d004b9af44ec3678acc2b6af91e4d3f (diff)
downloadsonarqube-46c588d9db7395d6185b95038a04dccf44e079b0.tar.gz
sonarqube-46c588d9db7395d6185b95038a04dccf44e079b0.zip
WIP frontend medium tests for Quality Gates
-rw-r--r--sonar-server/Gruntfile.coffee19
-rw-r--r--sonar-server/package.json7
-rw-r--r--sonar-server/src/main/js/tests/e2e/pages/quality-gates.html40
-rw-r--r--sonar-server/src/main/js/tests/e2e/server.js17
-rw-r--r--sonar-server/src/main/js/tests/e2e/tests/quality-gates.js251
5 files changed, 332 insertions, 2 deletions
diff --git a/sonar-server/Gruntfile.coffee b/sonar-server/Gruntfile.coffee
index 613a32c46b6..0f06e25c577 100644
--- a/sonar-server/Gruntfile.coffee
+++ b/sonar-server/Gruntfile.coffee
@@ -1,5 +1,8 @@
module.exports = (grunt) ->
grunt.loadNpmTasks('grunt-karma')
+ grunt.loadNpmTasks('grunt-express-server')
+ grunt.loadNpmTasks('grunt-casper')
+
pkg = grunt.file.readJSON('package.json')
grunt.initConfig
@@ -255,6 +258,20 @@ module.exports = (grunt) ->
logLevel: 'DEBUG'
+ express:
+ dev:
+ options:
+ script: '<%= pkg.assets %>js/tests/e2e/server.js'
+
+
+ casper:
+ test:
+ options:
+ test: true
+ 'no-colors': true
+ src: ['<%= pkg.sources %>js/tests/e2e/tests/**/*.js']
+
+
watch:
options:
spawn: false
@@ -303,4 +320,4 @@ module.exports = (grunt) ->
'concat:build',
'requirejs', 'clean:js', 'copy:build', 'copy:requirejs', 'clean:build']
- grunt.registerTask 'test', ['coffee:build', 'handlebars:build', 'copy:js', 'concat:dev', 'karma:unit']
+ grunt.registerTask 'test', ['coffee:build', 'handlebars:build', 'copy:js', 'concat:dev', 'karma:unit', 'express', 'casper']
diff --git a/sonar-server/package.json b/sonar-server/package.json
index 42e34c6e1b2..dded422d38f 100644
--- a/sonar-server/package.json
+++ b/sonar-server/package.json
@@ -7,6 +7,9 @@
"karma-phantomjs-launcher": "0.1.4",
"karma-coverage": "0.2.1",
"karma-junit-reporter": "0.2.1",
+ "express": "3.4.4",
+ "phantomjs": "1.9.7-12",
+ "casperjs": "1.1.0-beta3",
"grunt": "0.4.4",
"grunt-cli": "0.1.13",
"grunt-contrib-less": "0.10.0",
@@ -19,7 +22,9 @@
"grunt-contrib-clean": "0.5.0",
"grunt-contrib-copy": "0.5.0",
"grunt-contrib-concat": "0.4.0",
- "grunt-css-url-rewrite": "0.3.5"
+ "grunt-css-url-rewrite": "0.3.5",
+ "grunt-casper": "0.3.9",
+ "grunt-express-server": "0.4.17"
},
"engines": {
"node": "~0.8 || ~0.10"
diff --git a/sonar-server/src/main/js/tests/e2e/pages/quality-gates.html b/sonar-server/src/main/js/tests/e2e/pages/quality-gates.html
new file mode 100644
index 00000000000..c4152e98755
--- /dev/null
+++ b/sonar-server/src/main/js/tests/e2e/pages/quality-gates.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Quality Gates</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <link href="../css/sonar.css" rel="stylesheet" media="all"/>
+
+ <script src="../js/sonar.js"></script>
+ <script type="text/javascript">
+ var baseUrl = '..';
+ var $j = jQuery.noConflict();
+ $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>
+ </head>
+ <body>
+ <div id="container">
+ <div id="body">
+ <div id="content">
+ <div class="error" id="error" style="display:none">
+ <span id="errormsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#error').hide();return false;"><%= message('hide').downcase -%></a>]
+ </div>
+ <div class="notice" id="info" style="display:none">
+ <span id="infomsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#info').hide();return false;"><%= message('hide').downcase -%></a>]
+ </div>
+ <div class="warning" id="warning" style="display:none">
+ <span id="warningmsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#warning').hide();return false;"><%= message('hide').downcase -%></a>]
+ </div>
+
+ <div id="quality-gate-page-loader" class="navigator-page-loader">
+ <i class="spinner"></i>
+ </div>
+ </div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/sonar-server/src/main/js/tests/e2e/server.js b/sonar-server/src/main/js/tests/e2e/server.js
new file mode 100644
index 00000000000..8173ed21f40
--- /dev/null
+++ b/sonar-server/src/main/js/tests/e2e/server.js
@@ -0,0 +1,17 @@
+var express = require('express');
+var path = require('path');
+
+var app = express();
+
+app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+
+// Serve static files
+app.use("/", express.static(path.join(__dirname, '../../..')));
+app.use("/pages", express.static(path.join(__dirname, 'pages')));
+
+// Get the port from environment variables
+var port = process.env.PORT || 8000;
+
+app.listen(port);
+
+console.log('Server running on port %d', port);
diff --git a/sonar-server/src/main/js/tests/e2e/tests/quality-gates.js b/sonar-server/src/main/js/tests/e2e/tests/quality-gates.js
new file mode 100644
index 00000000000..94f134693c3
--- /dev/null
+++ b/sonar-server/src/main/js/tests/e2e/tests/quality-gates.js
@@ -0,0 +1,251 @@
+// 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();
+ });
+});