aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2014-07-28 12:17:56 +0200
committerStas Vilchik <vilchiks@gmail.com>2014-07-28 12:17:56 +0200
commit5f055a33b0185e62e01cb097af1d11c36ef12ee0 (patch)
tree4c970699eff23fe912e915e149312af26167db7b /server
parent783c67d13eb8c01fe4f36cc07e321a5102808b0b (diff)
downloadsonarqube-5f055a33b0185e62e01cb097af1d11c36ef12ee0.tar.gz
sonarqube-5f055a33b0185e62e01cb097af1d11c36ef12ee0.zip
Component Viewer Tests: favorites
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/lib.js12
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-favorite-spec.js64
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-spec/app-not-logged-in.json64
3 files changed, 134 insertions, 6 deletions
diff --git a/server/sonar-web/src/main/js/tests/e2e/lib.js b/server/sonar-web/src/main/js/tests/e2e/lib.js
index 8ade46d3aca..30b2b4aa88d 100644
--- a/server/sonar-web/src/main/js/tests/e2e/lib.js
+++ b/server/sonar-web/src/main/js/tests/e2e/lib.js
@@ -49,17 +49,17 @@ exports.testName = function () {
};
-var mockRequest = function (url, response) {
- return casper.evaluate(function (url, response) {
- return jQuery.mockjax({ url: url, responseText: response});
- }, url, response);
+var mockRequest = function (url, response, options) {
+ return casper.evaluate(function (url, response, options) {
+ return jQuery.mockjax(_.extend({ url: url, responseText: response}, options));
+ }, url, response, options || {});
};
exports.mockRequest = mockRequest;
-exports.mockRequestFromFile = function (url, fileName) {
+exports.mockRequestFromFile = function (url, fileName, options) {
var response = fs.read(fileName);
- return mockRequest(url, response);
+ return mockRequest(url, response, options);
};
diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-favorite-spec.js b/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-favorite-spec.js
new file mode 100644
index 00000000000..8776419f7b0
--- /dev/null
+++ b/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-favorite-spec.js
@@ -0,0 +1,64 @@
+var lib = require('../lib'),
+ testName = lib.testName('Component Viewer');
+
+lib.initMessages();
+lib.changeWorkingDirectory('component-viewer-spec');
+
+
+casper.test.begin(testName('Mark as Favorite'), function (test) {
+ casper
+ .start(lib.buildUrl('component-viewer#component=component'), function () {
+ lib.setDefaultViewport();
+ lib.mockRequest('/api/l10n/index', '{}');
+ lib.mockRequest('/api/favourites', '{}', { type: 'POST' });
+ lib.mockRequest('/api/favourites/*', '{}', { type: 'DELETE' });
+ lib.mockRequestFromFile('/api/components/app', 'app.json');
+ lib.mockRequestFromFile('/api/sources/show', 'source.json');
+ })
+
+ .then(function () {
+ casper.waitForSelector('.component-viewer-source .row');
+ })
+
+ .then(function () {
+ test.assertExists('.js-favorite');
+ test.assertExists('.icon-not-favorite');
+ casper.click('.js-favorite');
+ casper.waitForSelector('.icon-favorite', function () {
+ test.assertExists('.icon-favorite');
+ casper.click('.js-favorite');
+ casper.waitForSelector('.icon-not-favorite', function () {
+ test.assertExists('.icon-not-favorite');
+ });
+ });
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Don\'t Show Favorite If Not Logged In'), function (test) {
+ casper
+ .start(lib.buildUrl('component-viewer#component=component'), function () {
+ lib.setDefaultViewport();
+ lib.mockRequest('/api/l10n/index', '{}');
+ lib.mockRequestFromFile('/api/components/app', 'app-not-logged-in.json');
+ lib.mockRequestFromFile('/api/sources/show', 'source.json');
+ })
+
+ .then(function () {
+ casper.waitForSelector('.component-viewer-source .row');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.js-favorite');
+ test.assertDoesntExist('.icon-favorite');
+ test.assertDoesntExist('.icon-not-favorite');
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-spec/app-not-logged-in.json b/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-spec/app-not-logged-in.json
new file mode 100644
index 00000000000..3fc5d9091db
--- /dev/null
+++ b/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-spec/app-not-logged-in.json
@@ -0,0 +1,64 @@
+{
+ "key": "org.codehaus.sonar:sonar-batch:src/main/java/org/sonar/batch/index/Cache.java",
+ "path": "src/main/java/org/sonar/batch/index/Cache.java",
+ "name": "Cache.java",
+ "longName": "src/main/java/org/sonar/batch/index/Cache.java",
+ "q": "FIL",
+ "subProject": "org.codehaus.sonar:sonar-batch",
+ "subProjectName": "SonarQube :: Batch",
+ "project": "org.codehaus.sonar:sonar",
+ "projectName": "SonarQube",
+ "fav": false,
+ "canMarkAsFavourite": false,
+ "canBulkChange": false,
+ "canCreateManualIssue": false,
+ "periods": [
+ [1, "since previous analysis (2014 Jul 08)", "2014-07-08T23:17:21+0200"],
+ [2, "over 365 days (2013 Jul 10)", "2013-07-10T00:41:28+0200"],
+ [3, "since previous version (4.4 - 2014 Jul 02)", "2014-07-02T15:39:51+0200"]
+ ],
+ "severities": [
+ ["MINOR", "Minor", 1],
+ ["MAJOR", "Major", 1],
+ ["INFO", "Info", 4]
+ ],
+ "rules": [
+ ["common-java:DuplicatedBlocks", "Duplicated blocks", 1],
+ ["squid:S1192", "String literals should not be duplicated", 1],
+ ["squid:S1135", "TODO tags should be handled", 4]
+ ],
+ "measures": {
+ "fNcloc": "379",
+ "fCoverage": "74.3%",
+ "fDuplicationDensity": "5.8%",
+ "fDebt": "3h 30min",
+ "fIssues": "6",
+ "fMinorIssues": "1",
+ "fMajorIssues": "1",
+ "fInfoIssues": "4",
+ "fSqaleRating": "A"
+ },
+ "tabs": ["scm", "coverage", "duplications"],
+ "manual_rules": [
+ {
+ "key": "manual:api",
+ "name": "API"
+ },
+ {
+ "key": "manual:design",
+ "name": "Design"
+ },
+ {
+ "key": "manual:error_handling",
+ "name": "Error handling"
+ },
+ {
+ "key": "manual:performance",
+ "name": "Performance"
+ },
+ {
+ "key": "manual:sql_pitfalls",
+ "name": "SQL Pitfall"
+ }
+ ]
+}