aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-03-24 09:50:04 +0100
committerStas Vilchik <vilchiks@gmail.com>2015-03-24 09:50:04 +0100
commit631cea2c6bf952460e5239c2862c43d22edf529b (patch)
treef74df39de2c9e3c2bbe728d8d75f29ddf2890400
parent209fe2e257ed43735fbbf14c49a2f9d2848eed19 (diff)
downloadsonarqube-631cea2c6bf952460e5239c2862c43d22edf529b.tar.gz
sonarqube-631cea2c6bf952460e5239c2862c43d22edf529b.zip
update process spinners
-rw-r--r--server/sonar-web/src/main/js/common/processes.js54
-rw-r--r--server/sonar-web/src/test/js/process.js167
-rw-r--r--server/sonar-web/src/test/lib.js10
-rw-r--r--server/sonar-web/src/test/server-coverage.js11
-rw-r--r--server/sonar-web/src/test/server.js11
5 files changed, 223 insertions, 30 deletions
diff --git a/server/sonar-web/src/main/js/common/processes.js b/server/sonar-web/src/main/js/common/processes.js
index 6582863d910..1116a60e134 100644
--- a/server/sonar-web/src/main/js/common/processes.js
+++ b/server/sonar-web/src/main/js/common/processes.js
@@ -68,43 +68,37 @@
model: Process
}),
- ProcessView = Marionette.ItemView.extend({
- tagName: 'li',
- className: 'process-spinner',
+ ProcessesView = Marionette.ItemView.extend({
+ tagName: 'ul',
+ className: 'processes-container',
- modelEvents: {
- 'change': 'render'
+ collectionEvents: {
+ 'all': 'render'
},
render: function () {
- var that = this;
- switch (this.model.get('state')) {
- case 'timeout':
- this.$el.html(this.model.get('message')).addClass('shown');
- break;
- case 'failed':
- this.$el.html(this.model.get('message')).addClass('process-spinner-failed shown');
- var close = $('<button></button>').html('<i class="icon-close"></i>').addClass('process-spinner-close');
- close.appendTo(this.$el);
- close.on('click', function () {
- var a = { force: true };
- that.model.finish(a);
- });
- break;
- case 'finished':
- this.$el.addClass('hidden');
- break;
- default:
- break;
+ var failed = this.collection.findWhere({ state: 'failed' }),
+ timeout = this.collection.findWhere({ state: 'timeout' }),
+ el;
+ this.$el.empty();
+ if (failed != null) {
+ el = $('<li></li>')
+ .html(failed.get('message'))
+ .addClass('process-spinner process-spinner-failed shown');
+ var close = $('<button></button>').html('<i class="icon-close"></i>').addClass('process-spinner-close');
+ close.appendTo(el);
+ close.on('click', function () {
+ failed.finish({ force: true });
+ });
+ el.appendTo(this.$el);
+ } else if (timeout != null) {
+ el = $('<li></li>')
+ .html(timeout.get('message'))
+ .addClass('process-spinner shown');
+ el.appendTo(this.$el);
}
return this;
}
- }),
-
- ProcessesView = Marionette.CollectionView.extend({
- tagName: 'ul',
- className: 'processes-container',
- itemView: ProcessView
});
diff --git a/server/sonar-web/src/test/js/process.js b/server/sonar-web/src/test/js/process.js
new file mode 100644
index 00000000000..61c6edf2404
--- /dev/null
+++ b/server/sonar-web/src/test/js/process.js
@@ -0,0 +1,167 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+/* globals casper: false */
+
+var lib = require('../lib'),
+ testName = lib.testName('Process');
+
+
+lib.initMessages();
+lib.configureCasper();
+
+
+casper.test.begin(testName('One Timeout'), function (test) {
+ casper
+ .start(lib.buildUrl('nav'), function () {
+ lib.setDefaultViewport();
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery.get(baseUrl + '/api/generic/long');
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.process-spinner.shown');
+ })
+
+ .then(function () {
+ casper.waitWhileSelector('.process-spinner.shown');
+ })
+
+ .then(function () {
+ test.assert(true, 'All process spinners disappeared');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Several Timeouts'), 1, function (test) {
+ casper
+ .start(lib.buildUrl('nav'), function () {
+ lib.setDefaultViewport();
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ setTimeout(function() { jQuery.get(baseUrl + '/api/generic/long'); }, 0);
+ setTimeout(function() { jQuery.get(baseUrl + '/api/generic/long'); }, 500);
+ setTimeout(function() { jQuery.get(baseUrl + '/api/generic/long'); }, 1000);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.process-spinner.shown');
+ })
+
+ .then(function () {
+ lib.waitWhileElementCount('.process-spinner.shown', 1);
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.process-spinner.shown', 'All process spinners disappeared');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Failed'), 1, function (test) {
+ casper
+ .start(lib.buildUrl('nav'), function () {
+ lib.setDefaultViewport();
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ setTimeout(function() { jQuery.get(baseUrl + '/api/generic/long'); }, 0);
+ setTimeout(function() { jQuery.get(baseUrl + '/api/generic/failed'); }, 0);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.process-spinner.process-spinner-failed');
+ })
+
+ .then(function () {
+ lib.waitWhileElementCount('.process-spinner.shown', 1);
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.process-spinner.shown', 'All process spinners disappeared');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Close Failed'), 2, function (test) {
+ casper
+ .start(lib.buildUrl('nav'), function () {
+ lib.setDefaultViewport();
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery.get(baseUrl + '/api/generic/failed');
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.process-spinner.process-spinner-failed');
+ })
+
+ .then(function () {
+ test.assertExists('.process-spinner-close');
+ casper.click('.process-spinner-close');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.process-spinner.shown', 'All process spinners disappeared');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
diff --git a/server/sonar-web/src/test/lib.js b/server/sonar-web/src/test/lib.js
index f0743768af0..f1bec2eb442 100644
--- a/server/sonar-web/src/test/lib.js
+++ b/server/sonar-web/src/test/lib.js
@@ -148,6 +148,16 @@ exports.waitForElementCount = function (selector, count, callback) {
}, callback);
};
+
+exports.waitWhileElementCount = function (selector, count, callback) {
+ return casper.waitFor(function () {
+ return casper.evaluate(function (selector, count) {
+ return document.querySelectorAll(selector).length !== count;
+ }, selector, count);
+ }, callback);
+};
+
+
exports.assertLinkHref = function assertElementCount(selector, href, message) {
var linkHref = this.casper.evaluate(function(selector) {
return document.querySelector(selector);
diff --git a/server/sonar-web/src/test/server-coverage.js b/server/sonar-web/src/test/server-coverage.js
index ba0b0cd7156..953d08bac14 100644
--- a/server/sonar-web/src/test/server-coverage.js
+++ b/server/sonar-web/src/test/server-coverage.js
@@ -58,6 +58,17 @@ app.get('/api/l10n/index', function (req, res) {
res.setHeader('Content-Type', 'application/json');
res.end('{}');
});
+app.get('/api/generic/long', function (req, res) {
+ setTimeout(function() {
+ res.setHeader('Content-Type', 'application/json');
+ res.end('{}');
+ }, 2000);
+});
+app.get('/api/generic/failed', function (req, res) {
+ res.setHeader('Content-Type', 'application/json');
+ res.status('400');
+ res.end('{"errors":[{"msg":"Error Message"}]}');
+});
// Pages
diff --git a/server/sonar-web/src/test/server.js b/server/sonar-web/src/test/server.js
index ebf301d3b57..2d099f0d1d4 100644
--- a/server/sonar-web/src/test/server.js
+++ b/server/sonar-web/src/test/server.js
@@ -39,6 +39,17 @@ app.get('/api/l10n/index', function (req, res) {
res.setHeader('Content-Type', 'application/json');
res.end('{}');
});
+app.get('/api/generic/long', function (req, res) {
+ setTimeout(function() {
+ res.setHeader('Content-Type', 'application/json');
+ res.end('{}');
+ }, 2000);
+});
+app.get('/api/generic/failed', function (req, res) {
+ res.setHeader('Content-Type', 'application/json');
+ res.status('400');
+ res.end('{"errors":[{"msg":"Error Message"}]}');
+});
// Pages