diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-07-23 14:15:40 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-07-23 16:34:56 +0200 |
commit | 64fe4e04f34462d77129c3ae0603231dcc423ff8 (patch) | |
tree | 9ce7fb3fc2120abbc3d80fb827749c80b5ed6175 | |
parent | 7d89083b6d86dc07c3a0be778ee1e55f4ede9a8f (diff) | |
download | sonarqube-64fe4e04f34462d77129c3ae0603231dcc423ff8.tar.gz sonarqube-64fe4e04f34462d77129c3ae0603231dcc423ff8.zip |
SONAR-5001 Add initial medium test for Rules space
9 files changed, 463 insertions, 6 deletions
diff --git a/server/sonar-web/src/main/coffee/coding-rules/app.coffee b/server/sonar-web/src/main/coffee/coding-rules/app.coffee index 6aecd42562e..d87badeec08 100644 --- a/server/sonar-web/src/main/coffee/coding-rules/app.coffee +++ b/server/sonar-web/src/main/coffee/coding-rules/app.coffee @@ -5,7 +5,6 @@ requirejs.config 'backbone': 'third-party/backbone' 'backbone.marionette': 'third-party/backbone.marionette' 'handlebars': 'third-party/handlebars' - 'jquery.mockjax': 'third-party/jquery.mockjax' shim: 'backbone.marionette': @@ -52,7 +51,6 @@ requirejs [ 'coding-rules/views/filters/tag-filter-view', 'coding-rules/views/filters/language-filter-view', - 'coding-rules/mockjax', 'common/handlebars-extensions' ], ( Backbone, Marionette, 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 ece72a64032..20ba1903c6c 100644 --- a/server/sonar-web/src/main/js/tests/e2e/lib.js +++ b/server/sonar-web/src/main/js/tests/e2e/lib.js @@ -34,8 +34,8 @@ exports.changeWorkingDirectory = function (dir) { var mockRequest = function (url, response) { - casper.evaluate(function (url, response) { - jQuery.mockjax({ url: url, responseText: response}); + return casper.evaluate(function (url, response) { + return jQuery.mockjax({ url: url, responseText: response}); }, url, response); }; exports.mockRequest = mockRequest; @@ -43,10 +43,24 @@ exports.mockRequest = mockRequest; exports.mockRequestFromFile = function (url, fileName) { var response = fs.read(fileName); - mockRequest(url, response); + return mockRequest(url, response); }; +exports.clearRequestMocks = function () { + casper.evaluate(function() { + jQuery.mockjaxClear(); + }); +} + + +exports.clearRequestMock = function (mockId) { + casper.evaluate(function(mockId) { + jQuery.mockjaxClear(mockId); + }, mockId); +} + + exports.buildUrl = function (urlTail) { return BASE_URL + urlTail; }; @@ -60,4 +74,3 @@ exports.setDefaultViewport = function () { exports.capture = function (fileName) { casper.capture(fileName, { top: 0, left: 0, width: WINDOW_WIDTH, height: WINDOW_HEIGHT }); }; - diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec.js b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec.js new file mode 100644 index 00000000000..48049d18f24 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec.js @@ -0,0 +1,84 @@ +var lib = require('../lib'); + + +lib.initMessages(); +lib.changeWorkingDirectory('coding-rules-spec'); + + +casper.test.begin('Coding Rules - Readonly Tests', function suite(test) { + + var showId = null; + + casper.start(lib.buildUrl('coding-rules'), function() { + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/rules/app', 'app.json'); + lib.mockRequestFromFile('/api/rules/tags', 'tags.json'); + lib.mockRequestFromFile('/api/rules/search', 'search_initial.json'); + showId = lib.mockRequestFromFile('/api/rules/show', 'show_x1.json'); + }); + +/* + jQuery.mockjax({ url: '../api/rules/search', data: { + 'p': 1, 'ps': 25, 'facets': true, 's': 'createdAt', 'asc': false, 'f': 'name,lang,status' + }, responseText: searchInitialResponse}); + jQuery.mockjax({ url: '../api/rules/show', data: { + 'key': 'squid-xoo:x1', 'actives': true + }, responseText: showX1Response}); + jQuery.mockjax({ url: '../api/rules/show', data: { + 'key': 'squid:S0001', 'actives': true + }, responseText: showDeprecatedResponse}); +*/ + + casper.waitWhileSelector("div#coding-rules-page-loader", function checkInitialPageLoad() { + + casper.waitForSelector('.navigator-header', function checkHeader() { + test.assertExists('.navigator-header h1'); + test.assertExists('button#coding-rules-new-search'); + test.assertDoesntExist('button#coding-rules-create-rule'); + }); + + + casper.waitForSelector('.navigator-filters', function checkDefaultFilters() { + test.assertVisible('input[type="text"].query-filter-input'); + test.assertElementCount('.navigator-filter', 15); + test.assertElementCount('.navigator-filter-optional', 12 /* Only query, qProfile and 'More' are visible by default */); + test.assertVisible('button.navigator-filter-submit'); + }); + + + casper.waitForSelector('li.active', function checkResultsList() { + test.assertElementCount('ol.navigator-results-list li', 10); + test.assertElementCount('li.active', 1); + test.assertSelectorHasText('ol.navigator-results-list li.active', 'Xoo'); + test.assertSelectorHasText('ol.navigator-results-list li.active', 'No empty line'); + test.assertSelectorHasText('ol.navigator-results-list li.active', 'BETA'); + }); + + casper.waitForSelector('h3.coding-rules-detail-header', function showFirstRule() { + test.assertSelectorHasText('h3.coding-rules-detail-header', 'No empty line'); + test.assertSelectorHasText('.navigator-details .subtitle', 'squid-xoo:x1'); + test.assertSelectorHasText('.coding-rules-detail-property:nth-child(1)', 'severity.MINOR'); + test.assertSelectorHasText('.coding-rules-detail-property:nth-child(2)', 'BETA'); + test.assertSelectorHasText('.coding-rules-detail-property:nth-child(3)', 'convention, pitfall'); + test.assertSelectorHasText('.coding-rules-detail-property:nth-child(4)', 'Testability > Integration level testability'); + test.assertSelectorHasText('.coding-rules-detail-property:nth-child(6)', 'SonarQube (Xoo)'); + }); + }); + + casper.then(function showDeprecated() { + lib.clearRequestMock(showId); + showId = lib.mockRequestFromFile('/api/rules/show', 'show_deprecated.json'); + + casper.click('div[name="squid:S0001"]'); + + casper.waitWhileSelector('.navigator-details i.spinner'); + casper.waitForSelector('h3.coding-rules-detail-header', function() { + test.assertSelectorHasText('h3.coding-rules-detail-header', 'Deprecated rule'); + }); + + }); + + casper.run(function() { + test.done(); + }); +}); diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/app.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/app.json new file mode 100644 index 00000000000..b0cbb0e1c98 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/app.json @@ -0,0 +1,109 @@ +{ + "canWrite": false, + "qualityprofiles": [ + { + "key": "xoo-sonar-way", + "name": "Sonar way", + "lang": "xoo" + }, + { + "key": "xoo-empty", + "name": "Empty", + "lang": "xoo" + }, + { + "key": "java-sonar-way", + "name": "Sonar way", + "lang": "java" + }, + { + "key": "coffee-sonar-way", + "name": "Sonar way", + "lang": "coffee" + }, + { + "key": "java-sonar-way-with-findbugs", + "name": "Sonar way with Findbugs", + "lang": "java", + "parentKey": "java-sonar-way" + } + ], + "languages": { + "xoo": "Xoo", + "java": "Java", + "coffee": "CoffeeScript" + }, + "repositories": [ + { + "key": "squid", + "name": "SonarQube", + "language": "java" + }, + { + "key": "squid-xoo", + "name": "SonarQube", + "language": "xoo" + }, + { + "key": "squid-coffee", + "name": "SonarQube", + "language": "coffee" + }, + { + "key": "common-coffee", + "name": "Common SonarQube", + "language": "coffee" + }, + { + "key": "common-java", + "name": "Common 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-spec/search_initial.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/search_initial.json new file mode 100644 index 00000000000..19000b26a88 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/search_initial.json @@ -0,0 +1,133 @@ +{ + + "total": 10, + "p": 1, + "ps": 25, + "rules": [ + { + "key": "squid-xoo:x1", + "name": "No empty line", + "lang": "xoo", + "status": "BETA" + }, + { + "key": "squid:S0001", + "name": "Deprecated rule", + "lang": "java", + "status": "DEPRECATED" + }, + { + "key": "squid-coffee:S0001", + "name": "First rule of Coffee is: you don't talk about Coffee", + "lang": "coffee", + "status": "READY" + }, + { + "key": "squid-coffee:S0002", + "name": "Second rule of Coffee is: you DO NOT talk about Coffee", + "lang": "coffee", + "status": "READY" + }, + { + "key": "common-coffee:TrailingWhitespace", + "name": "Avoid trailing whitespace on lines", + "lang": "coffee", + "status": "READY" + }, + { + "key": "squid:S0002", + "name": "Deprecating rule", + "lang": "java", + "status": "READY" + }, + { + "key": "squid:S0003", + "name": "Always put a newline at end of file", + "lang": "java", + "status": "READY" + }, + { + "key": "common-java:TrailingWhitespace", + "name": "Avoid trailing whitespace on lines", + "lang": "java", + "status": "READY" + }, + { + "key": "common-java:ConvertSingleMethodInterfacesToLambdas", + "name": "Single method interfaces should be converted to lambdas", + "lang": "java", + "status": "READY" + }, + { + "key": "common-java:LambdaOneStatementBlock", + "name": "Lamdbas containing only one statement should not nest this statement in a block ", + "lang": "java", + "status": "READY" + } + ], + "facets": [ + { + "property": "tags", + "values": [ + { + "val": "java8", + "count": 5 + }, + { + "val": "pitfall", + "count": 4 + }, + { + "val": "convention", + "count": 3 + }, + { + "val": "multithreading", + "count": 1 + } + ] + }, + { + "property": "languages", + "values": [ + { + "val": "java", + "count": 6 + }, + { + "val": "coffee", + "count": 3 + }, + { + "val": "xoo", + "count": 1 + } + ] + }, + { + "property": "repositories", + "values": [ + { + "val": "squid", + "count": 3 + }, + { + "val": "common-java", + "count": 3 + }, + { + "val": "squid-coffee", + "count": 2 + }, + { + "val": "common-coffee", + "count": 1 + }, + { + "val": "squid-xoo", + "count": 1 + } + ] + } + ] +} diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/show_deprecated.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/show_deprecated.json new file mode 100644 index 00000000000..ed4cca4b5cf --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/show_deprecated.json @@ -0,0 +1,37 @@ +{ + "rule": { + "key": "squid:S0001", + "repo": "squid", + "name": "Deprecated rule", + "createdAt": "2014-07-23T11:17:26+0200", + "severity": "MINOR", + "status": "DEPRECATED", + "isTemplate": false, + "tags": [ + "convention" + ], + "sysTags": [ + "pitfall" + ], + "lang": "java", + "langName": "Java", + "htmlDesc": "Deprecated rule", + "mdDesc": "Deprecated rule", + "defaultDebtChar": "TESTABILITY", + "defaultDebtSubChar": "INTEGRATION_TESTABILITY", + "debtChar": "TESTABILITY", + "debtSubChar": "INTEGRATION_TESTABILITY", + "debtCharName": "Testability", + "debtSubCharName": "Integration level", + "debtRemFnType": "LINEAR_OFFSET", + "debtRemFnCoeff": "1h", + "debtRemFnOffset": "30min", + "defaultDebtRemFnType": "LINEAR_OFFSET", + "defaultDebtRemFnCoeff": "1h", + "defaultDebtRemFnOffset": "30min", + "effortToFixDescription": "Effort to fix issue on one line", + "debtOverloaded": false, + "params": [ ] + }, + "actives": [ ] +} diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/show_x1.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/show_x1.json new file mode 100644 index 00000000000..e3c47578ff2 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/show_x1.json @@ -0,0 +1,59 @@ +{ + + "rule": { + "key": "squid-xoo:x1", + "repo": "squid-xoo", + "name": "No empty line", + "createdAt": "2014-07-23T11:17:26+0200", + "severity": "MINOR", + "status": "BETA", + "isTemplate": false, + "tags": [ ], + "sysTags": [ + "convention", + "pitfall" + ], + "lang": "xoo", + "langName": "Xoo", + "htmlDesc": "Generate an issue on <em>empty</em> lines of Xoo source files", + "mdDesc": "Generate an issue on *empty* lines of Xoo source files", + "noteLogin": "admin", + "mdNote": "As per the [Book of Xoo](http://xoo.sonarsource.com/book):\n> Xoo shall not pass!", + "htmlNote": "As per the <a href=\"http://xoo.sonarsource.com/book\" target=\"_blank\">Book of Xoo</a>:<br/><blockquote>Xoo shall not pass!<br/></blockquote>", + "defaultDebtChar": "TESTABILITY", + "defaultDebtSubChar": "INTEGRATION_TESTABILITY", + "debtChar": "TESTABILITY", + "debtSubChar": "INTEGRATION_TESTABILITY", + "debtCharName": "Testability", + "debtSubCharName": "Integration level", + "debtRemFnType": "LINEAR_OFFSET", + "debtRemFnCoeff": "1h", + "debtRemFnOffset": "30min", + "defaultDebtRemFnType": "LINEAR_OFFSET", + "defaultDebtRemFnCoeff": "1h", + "defaultDebtRemFnOffset": "30min", + "effortToFixDescription": "Effort to fix issue on one line", + "debtOverloaded": false, + "params": [ + { + "key": "acceptWhitespace", + "htmlDesc": "<h1>Accept whitespace (<code>\\s|\\t</code>) on the line\n</h1>This property is available so that a line containing only whitespace is not considered empty.<br/><h2>Example with property set to ``false``\n</h2><pre lang=\"xoo\"><code> <- One issue here\n<- And one here</code></pre><br/><br/><h2>Example with property set to ``true``\n</h2><pre lang=\"xoo\"><code> <- No issue here\n<- But one here</code></pre><br/>", + "defaultValue": "false" + } + ] + }, + "actives": [ + { + "qProfile": "xoo-sonar-way", + "inherit": "NONE", + "severity": "MAJOR", + "params": [ + { + "key": "acceptWhitespace", + "value": "true" + } + ] + } + ] + +} diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/tags.json b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/tags.json new file mode 100644 index 00000000000..0f9a1c49e96 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/tests/coding-rules-spec/tags.json @@ -0,0 +1,15 @@ +{ + "tags": [ + "error-handling", + "misra-coffee", + "multithreading", + "performance", + "pitfall", + "bug", + "convention", + "security", + "java8", + "unused", + "brain-overload" + ] +} 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 new file mode 100644 index 00000000000..079c33b4b43 --- /dev/null +++ b/server/sonar-web/src/main/js/tests/e2e/views/coding-rules.jade @@ -0,0 +1,9 @@ +extends ./layouts/main + +block header + script(data-main='/js/coding-rules/app', src='../js/require.js') + +block body + #content + #coding-rules-page-loader.navigator-page-loader + i.spinner |