]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality gates tests
authorStas Vilchik <vilchiks@gmail.com>
Wed, 23 Jul 2014 14:32:14 +0000 (16:32 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 23 Jul 2014 14:32:23 +0000 (16:32 +0200)
server/sonar-web/src/main/js/tests/e2e/lib.js
server/sonar-web/src/main/js/tests/e2e/tests/quality-gates-spec.js
server/sonar-web/src/main/js/tests/e2e/views/quality-gates.jade

index 28f75d43c7c2ce0728cfe5547d5bbb5eef4be8fb..ece72a640324e9d85c991fdd559ce281b489918a 100644 (file)
@@ -8,11 +8,13 @@ var BASE_URL = 'http://localhost:3000/pages/',
 
 exports.initMessages = function () {
   // Dump log messages
+  casper.removeAllListeners('remote.message');
   casper.on('remote.message', function(message) {
     this.echo('Log: '+ message, 'LOG');
   });
 
   // Dump uncaught errors
+  casper.removeAllListeners('page.error');
   casper.on('page.error', function(msg) {
     this.echo('Error: ' + msg, 'ERROR');
   });
index 146ecd577fe292f794da1dca020d1ec1831ddf6e..f068858dd676d8cbe2f9ebe3788c2f209ff05c73 100644 (file)
@@ -1,75 +1,17 @@
-// 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');
-});
-
-var fs = require('fs');
-var utils = require('utils');
-
-// Since Casper has control, the invoked script is deep in the argument stack
-var currentFile = require('system').args[4];
-var curFilePath = fs.absolute(currentFile).split(fs.separator);
-if (curFilePath.length > 1) {
-    curFilePath.pop(); // PhantomJS does not have an equivalent path.baseName()-like method
-    curFilePath.push('quality-gates-spec');
-    fs.changeWorkingDirectory(curFilePath.join(fs.separator));
-}
-
-casper.test.begin('App is setup correctly', function suite(test) {
-
-  // Load MockJax responses from FS
-  var appResponse = fs.read('app.json');
-  var listResponse = fs.read('list.json');
-  var showResponse = fs.read('show.json');
-
-  // Register mockjax requests on loading of requirejs
-  casper.options.onResourceRequested = function(instance, requestData, networkRequest) {
-
-    // Here, instance is the running instance of casperjs
-    if (requestData.url.indexOf('require') >= 0) {
-      instance.page.includeJs('../js/third-party/jquery.mockjax.js', function injectReponses() {
-        // Inject response values to page scope
-        instance.page.evaluate(function setupMockJax(appResponse, listResponse, showResponse) {
-          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: appResponse
-          });
-
-
-          jQuery.mockjax({
-            url: "../api/qualitygates/list",
-            responseText: listResponse
-          });
+var lib = require('../lib');
 
-          jQuery.mockjax({
-            url: "../api/qualitygates/show?id=1",
-            responseText: showResponse
-          });
+lib.initMessages();
+lib.changeWorkingDirectory('quality-gates-spec');
 
-        }, appResponse, listResponse, showResponse);
-      });
-    }
-  };
 
-  // See API at http://docs.casperjs.org/en/latest/modules/index.html
+casper.test.begin('Quality Gates', function suite(test) {
+  casper.start(lib.buildUrl('quality-gates'), function() {
+    lib.setDefaultViewport();
 
-  casper.start('http://localhost:3000/pages/quality-gates.html', function() {
-    test.assertTitle('Quality Gates');
+    lib.mockRequest('/api/l10n/index', '{}');
+    lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
+    lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
+    lib.mockRequestFromFile('/api/qualitygates/show?id=1', 'show.json');
   });
 
   casper.waitWhileSelector("div#quality-gates-loader", function() {
index 58b27d60f0e6480e2744046f16e71d64cc63e760..57ff78c66ec50c8c2bf8afee1bbb970bbf0fe094 100644 (file)
@@ -1,8 +1,9 @@
-extends .layouts/main
+extends ./layouts/main
 
 block header
   script(data-main='/js/quality-gate/app', src='../js/require.js')
 
 block body
-  #quality-gate-page-loader.navigator-page-loader
-    i.spinner
+  #content
+    #quality-gate-page-loader.navigator-page-loader
+      i.spinner