From 70b27899c639b72c79e932fee6237f876b7b0d4b Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Tue, 23 Dec 2014 16:49:16 +0100 Subject: [PATCH] SONAR-5820 Fix profile activation --- .../rule/profile-activation-view.js | 3 +- ...ding-rules-page-should-activate-profile.js | 54 ++++++ .../app.json | 168 +++++++++++++++++ .../search.json | 171 ++++++++++++++++++ .../show-with-profile.json | 39 ++++ .../show.json | 32 ++++ .../main/js/tests/e2e/views/coding-rules.jade | 3 +- 7 files changed, 468 insertions(+), 2 deletions(-) create mode 100644 server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile.js create mode 100644 server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/app.json create mode 100644 server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/search.json create mode 100644 server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/show-with-profile.json create mode 100644 server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/show.json diff --git a/server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js b/server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js index 3bd8855bddb..b34b4d83125 100644 --- a/server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js +++ b/server/sonar-web/src/main/js/coding-rules/rule/profile-activation-view.js @@ -46,7 +46,8 @@ define([ }); }, - activate: function () { + activate: function (e) { + e.preventDefault(); var that = this, p = window.process.addBackgroundProcess(), profileKey = this.ui.qualityProfileSelect.val(), diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile.js b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile.js new file mode 100644 index 00000000000..fe049606765 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile.js @@ -0,0 +1,54 @@ +/* global casper:false */ + +var lib = require('../lib'); + +lib.initMessages(); +lib.changeWorkingDirectory('coding-rules-page-should-activate-profile'); + + +casper.test.begin('coding-rules-page-should-activate-profile', 5, function (test) { + casper + .start(lib.buildUrl('coding-rules'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/rules/app', 'app.json'); + lib.mockRequestFromFile('/api/rules/search', 'search.json'); + this.showMock = lib.mockRequestFromFile('/api/rules/show', 'show.json'); + lib.mockRequest('/api/qualityprofiles/activate_rule', '{}'); + }) + + .then(function () { + casper.waitForSelector('.coding-rule.selected', function () { + casper.click('.coding-rule.selected .js-rule'); + }); + }) + + .then(function () { + casper.waitForSelector('.coding-rules-detail-header'); + }) + + .then(function () { + test.assertDoesntExist('.coding-rules-detail-quality-profile-name'); + test.assertExist('#coding-rules-quality-profile-activate'); + casper.click('#coding-rules-quality-profile-activate'); + casper.waitForSelector('.modal'); + }) + + .then(function () { + lib.clearRequestMock(this.showMock); + lib.mockRequestFromFile('/api/rules/show', 'show-with-profile.json'); + casper.click('#coding-rules-quality-profile-activation-activate'); + casper.waitForSelector('.coding-rules-detail-quality-profile-name'); + }) + + .then(function () { + test.assertExists('.coding-rules-detail-quality-profile-name'); + test.assertExists('.coding-rules-detail-quality-profile-severity'); + test.assertExists('.coding-rules-detail-quality-profile-deactivate'); + }) + + .run(function () { + test.done(); + }); +}); diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/app.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/app.json new file mode 100644 index 00000000000..f66b07ba5a1 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/app.json @@ -0,0 +1,168 @@ +{ + "canWrite": true, + "qualityprofiles": [ + { + "key": "java-default-with-mojo-conventions-49307", + "name": "Default - Maven Conventions", + "lang": "java", + "parentKey": "java-top-profile-without-formatting-conventions-50037" + }, + { + "key": "java-default-with-sonarsource-conventions-27339", + "name": "Default - SonarSource conventions", + "lang": "java", + "parentKey": "java-top-profile-without-formatting-conventions-50037" + }, + { + "key": "java-top-profile-without-formatting-conventions-50037", + "name": "Default - Top", + "lang": "java" + }, + { + "key": "java-findbugs-14954", + "name": "FindBugs", + "lang": "java" + }, + { + "key": "java-for-sq-java-plugin-only-92289", + "name": "For SQ Java Plugin Only", + "lang": "java", + "parentKey": "java-default-with-sonarsource-conventions-27339" + }, + { + "key": "java-for-sq-only-95381", + "name": "For SQ Only", + "lang": "java", + "parentKey": "java-default-with-sonarsource-conventions-27339" + }, + { + "key": "php-psr-2-06315", + "name": "PSR-2", + "lang": "php" + }, + { + "key": "java-sonar-way-80423", + "name": "Sonar way", + "lang": "java" + }, + { + "key": "js-sonar-way", + "name": "Sonar way", + "lang": "js" + }, + { + "key": "php-sonar-way-05548", + "name": "Sonar way", + "lang": "php" + }, + { + "key": "py-sonar-way-80265", + "name": "Sonar way", + "lang": "py" + }, + { + "key": "java-without-findbugs", + "name": "Without Findbugs", + "lang": "java" + } + ], + "languages": { + "py": "Python", + "js": "JavaScript", + "php": "PHP", + "java": "Java" + }, + "repositories": [ + { + "key": "common-java", + "name": "Common SonarQube", + "language": "java" + }, + { + "key": "common-js", + "name": "Common SonarQube", + "language": "js" + }, + { + "key": "common-php", + "name": "Common SonarQube", + "language": "php" + }, + { + "key": "common-py", + "name": "Common SonarQube", + "language": "py" + }, + { + "key": "Pylint", + "name": "Pylint", + "language": "py" + }, + { + "key": "javascript", + "name": "SonarQube", + "language": "js" + }, + { + "key": "php", + "name": "SonarQube", + "language": "php" + }, + { + "key": "python", + "name": "SonarQube", + "language": "py" + }, + { + "key": "squid", + "name": "SonarQube", + "language": "java" + } + ], + "statuses": { + "BETA": "Beta", + "DEPRECATED": "Deprecated", + "READY": "Ready" + }, + "characteristics": { + "UNDERSTANDABILITY": "Maintainability: Understandability", + "MAINTAINABILITY": "Maintainability", + "TIME_ZONE_RELATED_PORTABILITY": "Portability: Time zone related portability", + "READABILITY": "Maintainability: Readability", + "SECURITY_FEATURES": "Security: Security features", + "ARCHITECTURE_RELIABILITY": "Reliability: Architecture related reliability", + "OS_RELATED_PORTABILITY": "Portability: OS related portability", + "EXCEPTION_HANDLING": "Reliability: Exception handling", + "LOGIC_CHANGEABILITY": "Changeability: Logic related changeability", + "SOFTWARE_RELATED_PORTABILITY": "Portability: Software related portability", + "INPUT_VALIDATION_AND_REPRESENTATION": "Security: Input validation and representation", + "LANGUAGE_RELATED_PORTABILITY": "Portability: Language related portability", + "ERRORS": "Security: Errors", + "SECURITY": "Security", + "RELIABILITY": "Reliability", + "PORTABILITY": "Portability", + "HARDWARE_RELATED_PORTABILITY": "Portability: Hardware related portability", + "SYNCHRONIZATION_RELIABILITY": "Reliability: Synchronization related reliability", + "TRANSPORTABILITY": "Reusability: Transportability", + "COMPILER_RELATED_PORTABILITY": "Portability: Compiler related portability", + "RESOURCE_RELIABILITY": "Reliability: Resource", + "CPU_EFFICIENCY": "Efficiency: Processor use", + "EFFICIENCY": "Efficiency", + "CHANGEABILITY": "Changeability", + "DATA_CHANGEABILITY": "Changeability: Data related changeability", + "API_ABUSE": "Security: API abuse", + "ARCHITECTURE_CHANGEABILITY": "Changeability: Architecture related changeability", + "UNIT_TESTS": "Reliability: Unit tests", + "INSTRUCTION_RELIABILITY": "Reliability: Instruction related reliability", + "REUSABILITY": "Reusability", + "MODULARITY": "Reusability: Modularity", + "UNIT_TESTABILITY": "Testability: Unit level testability", + "TESTABILITY": "Testability", + "INTEGRATION_TESTABILITY": "Testability: Integration level testability", + "NETWORK_USE": "Efficiency: Network use", + "MEMORY_EFFICIENCY": "Efficiency: Memory use", + "DATA_RELIABILITY": "Reliability: Data related reliability", + "FAULT_TOLERANCE": "Reliability: Fault tolerance", + "LOGIC_RELIABILITY": "Reliability: Logic related reliability" + } +} diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/search.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/search.json new file mode 100644 index 00000000000..b5a6bc269b9 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/search.json @@ -0,0 +1,171 @@ +{ + "total": 10, + "p": 1, + "ps": 200, + "rules": [ + { + "key": "squid:S1181", + "name": "Throwable and Error classes should not be caught", + "lang": "java", + "langName": "Java", + "sysTags": [ + "error-handling" + ], + "tags": [] + }, + { + "key": "squid:S1849", + "name": "\"Iterator.hasNext()\" should not call \"Iterator.next()\"", + "lang": "java", + "langName": "Java", + "sysTags": [ + "bug" + ], + "tags": [] + }, + { + "key": "squid:S1844", + "name": "\"Object.wait(...)\" should never be called on objects that implement \"java.util.concurrent.locks.Condition\"", + "lang": "java", + "langName": "Java", + "sysTags": [ + "bug", + "pitfall" + ], + "tags": [] + }, + { + "key": "squid:S2258", + "name": "\"javax.crypto.NullCipher\" should not be used for anything other than testing", + "lang": "java", + "langName": "Java", + "sysTags": [ + "cwe", + "owasp-top10", + "security" + ], + "tags": [] + }, + { + "key": "squid:S2251", + "name": "A \"for\" loop update clause should move the counter in the right direction", + "lang": "java", + "langName": "Java", + "sysTags": [ + "bug" + ], + "tags": [] + }, + { + "key": "squid:ObjectFinalizeOverridenCallsSuperFinalizeCheck", + "name": "super.finalize() should be called at the end of Object.finalize() implementations", + "lang": "java", + "langName": "Java", + "sysTags": [ + "bug" + ], + "tags": [] + }, + { + "key": "squid:S1143", + "name": "Return statements should not occur in finally blocks", + "lang": "java", + "langName": "Java", + "sysTags": [ + "bug" + ], + "tags": [] + }, + { + "key": "squid:S1206", + "name": "\"equals(Object obj)\" and \"hashCode()\" should be overridden in pairs", + "lang": "java", + "langName": "Java", + "sysTags": [ + "bug" + ], + "tags": [] + }, + { + "key": "squid:S1451", + "name": "Copyright and license headers should be defined in all source files", + "lang": "java", + "langName": "Java", + "sysTags": [ + "convention" + ], + "tags": [] + }, + { + "key": "squid:S1697", + "name": "Short-circuit logic should be used to prevent null pointer dereferences in conditionals", + "lang": "java", + "langName": "Java", + "sysTags": [ + "bug" + ], + "tags": [] + } + ], + "facets": [ + { + "property": "tags", + "values": [ + { + "val": "bug", + "count": 7 + }, + { + "val": "convention", + "count": 1 + }, + { + "val": "cwe", + "count": 1 + }, + { + "val": "error-handling", + "count": 1 + }, + { + "val": "owasp-top10", + "count": 1 + }, + { + "val": "pitfall", + "count": 1 + }, + { + "val": "security", + "count": 1 + } + ] + }, + { + "property": "languages", + "values": [ + { + "val": "java", + "count": 10 + }, + { + "val": "js", + "count": 6 + }, + { + "val": "php", + "count": 2 + } + ] + }, + { + "property": "repositories", + "values": [ + { + "val": "squid", + "count": 10 + } + ] + } + ] +} diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/show-with-profile.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/show-with-profile.json new file mode 100644 index 00000000000..1fddeb6a632 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/show-with-profile.json @@ -0,0 +1,39 @@ +{ + "rule": { + "key": "squid:S1181", + "repo": "squid", + "name": "Throwable and Error classes should not be caught", + "createdAt": "2013-08-09T14:40:54+0200", + "severity": "BLOCKER", + "status": "READY", + "internalKey": "S1181", + "isTemplate": false, + "tags": [], + "sysTags": [ + "error-handling" + ], + "lang": "java", + "langName": "Java", + "htmlDesc": "

\nThrowable is the superclass of all errors and exceptions in Java.\nError is the superclass of all errors which are not meant to be caught by applications.\n

\n\n

\nCatching either Throwable or Error will also catch OutOfMemoryError or InternalError from which an application should not attempt to recover.\n

\n\n

Only Exception and its subclasses should be caught.

\n\n

Noncompliant Code Example

\n\n
\ntry { /* ... */ } catch (Throwable t) { /* ... */ }\ntry { /* ... */ } catch (Error e) { /* ... */ } \n
\n\n

Compliant Solution

\n\n
\ntry { /* ... */ } catch (Exception e) { /* ... */ }  \ntry { /* ... */ } catch (RuntimeException e) { /* ... */ }  \ntry { /* ... */ } catch (MyException e) { /* ... */ }  \n
", + "defaultDebtChar": "RELIABILITY", + "defaultDebtSubChar": "EXCEPTION_HANDLING", + "debtChar": "RELIABILITY", + "debtSubChar": "EXCEPTION_HANDLING", + "debtCharName": "Reliability", + "debtSubCharName": "Exception handling", + "defaultDebtRemFnType": "CONSTANT_ISSUE", + "defaultDebtRemFnOffset": "20min", + "debtOverloaded": true, + "debtRemFnType": "LINEAR", + "debtRemFnCoeff": "20min", + "params": [] + }, + "actives": [ + { + "qProfile": "java-default-with-mojo-conventions-49307", + "inherit": "NONE", + "severity": "BLOCKER", + "params": [] + } + ] +} diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/show.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/show.json new file mode 100644 index 00000000000..cf4b206221e --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-page-should-activate-profile/show.json @@ -0,0 +1,32 @@ +{ + "rule": { + "key": "squid:S1181", + "repo": "squid", + "name": "Throwable and Error classes should not be caught", + "createdAt": "2013-08-09T14:40:54+0200", + "severity": "BLOCKER", + "status": "READY", + "internalKey": "S1181", + "isTemplate": false, + "tags": [], + "sysTags": [ + "error-handling" + ], + "lang": "java", + "langName": "Java", + "htmlDesc": "

\nThrowable is the superclass of all errors and exceptions in Java.\nError is the superclass of all errors which are not meant to be caught by applications.\n

\n\n

\nCatching either Throwable or Error will also catch OutOfMemoryError or InternalError from which an application should not attempt to recover.\n

\n\n

Only Exception and its subclasses should be caught.

\n\n

Noncompliant Code Example

\n\n
\ntry { /* ... */ } catch (Throwable t) { /* ... */ }\ntry { /* ... */ } catch (Error e) { /* ... */ } \n
\n\n

Compliant Solution

\n\n
\ntry { /* ... */ } catch (Exception e) { /* ... */ }  \ntry { /* ... */ } catch (RuntimeException e) { /* ... */ }  \ntry { /* ... */ } catch (MyException e) { /* ... */ }  \n
", + "defaultDebtChar": "RELIABILITY", + "defaultDebtSubChar": "EXCEPTION_HANDLING", + "debtChar": "RELIABILITY", + "debtSubChar": "EXCEPTION_HANDLING", + "debtCharName": "Reliability", + "debtSubCharName": "Exception handling", + "defaultDebtRemFnType": "CONSTANT_ISSUE", + "defaultDebtRemFnOffset": "20min", + "debtOverloaded": true, + "debtRemFnType": "LINEAR", + "debtRemFnCoeff": "20min", + "params": [] + }, + "actives": [] +} diff --git a/server/sonar-web/src/main/js/tests/e2e/views/coding-rules.jade b/server/sonar-web/src/main/js/tests/e2e/views/coding-rules.jade index 6d79ffe695d..a56d076e719 100644 --- a/server/sonar-web/src/main/js/tests/e2e/views/coding-rules.jade +++ b/server/sonar-web/src/main/js/tests/e2e/views/coding-rules.jade @@ -6,4 +6,5 @@ block header window.waitForMocks('/js/coding-rules/app.js'); block body - .coding-rules + #content + .coding-rules.search-navigator -- 2.39.5