diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-03-27 10:33:11 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-03-27 10:43:05 +0100 |
commit | 3fff0e8918b8de03e413b357ed46e4adaa71d2ca (patch) | |
tree | bac5ac8f53f729ce7e36b2d89032bf205e6fa2c3 | |
parent | 7bad03950e4ec3e82a5fef2ef50867a2e4ac29e2 (diff) | |
download | sonarqube-3fff0e8918b8de03e413b357ed46e4adaa71d2ca.tar.gz sonarqube-3fff0e8918b8de03e413b357ed46e4adaa71d2ca.zip |
show warning when find a duplication in a removed component
5 files changed, 142 insertions, 60 deletions
diff --git a/server/sonar-web/src/main/hbs/source-viewer/source-viewer-duplication-popup.hbs b/server/sonar-web/src/main/hbs/source-viewer/source-viewer-duplication-popup.hbs index d3553ed3e58..4a596a1959d 100644 --- a/server/sonar-web/src/main/hbs/source-viewer/source-viewer-duplication-popup.hbs +++ b/server/sonar-web/src/main/hbs/source-viewer/source-viewer-duplication-popup.hbs @@ -1,42 +1,45 @@ <div class="bubble-popup-container"> - <div class="bubble-popup-title">{{t 'component_viewer.transition.duplication'}}</div> - {{#each duplications}} - <div class="bubble-popup-section"> - <div class="component-name"> - {{#notEqComponents file ../component}} - <div class="component-name-parent"> - <i class="icon-qualifier-trk"></i> <a href="{{dashboardUrl file.project}}">{{file.projectName}}</a> - </div> - {{#if file.subProjectName}} + {{#if inRemovedComponent}} + <div class="alert alert-warning spacer-bottom">{{t 'duplications.dups_found_on_deleted_resource'}}</div> + {{/if}} + {{#notEmpty duplications}} + <div class="bubble-popup-title">{{t 'component_viewer.transition.duplication'}}</div> + {{#each duplications}} + <div class="bubble-popup-section"> + <div class="component-name"> + {{#notEqComponents file ../component}} <div class="component-name-parent"> - <i class="icon-qualifier-trk"></i> <a - href="{{dashboardUrl file.subProject}}">{{file.subProjectName}}</a> + <i class="icon-qualifier-trk"></i> <a href="{{dashboardUrl file.project}}">{{file.projectName}}</a> + </div> + {{#if file.subProjectName}} + <div class="component-name-parent"> + <i class="icon-qualifier-trk"></i> <a + href="{{dashboardUrl file.subProject}}">{{file.subProjectName}}</a> + </div> + {{/if}} + {{/notEqComponents}} + + {{#notEq file.key ../component.key}} + <div class="component-name-path"> + <a data-uuid="{{file.uuid}}" title="{{file.name}}"> + <span>{{collapsedDirFromPath file.name}}</span><span + class="component-name-file">{{fileFromPath file.name}}</span> + </a> </div> - {{/if}} - {{/notEqComponents}} + {{/notEq}} - {{#notEq file.key ../component.key}} <div class="component-name-path"> - <a data-uuid="{{file.uuid}}" title="{{file.name}}"> - <span>{{collapsedDirFromPath file.name}}</span><span - class="component-name-file">{{fileFromPath file.name}}</span> - </a> + Lines: + {{#joinEach blocks ','}} + <a class="link-action" data-uuid="{{../file.uuid}}" data-line="{{from}}"> + {{from}} – {{sum from size -1}} + </a> + {{/joinEach}} </div> - {{/notEq}} - - <div class="component-name-path"> - Lines: - {{#joinEach blocks ','}} - <a class="link-action" data-uuid="{{../file.uuid}}" data-line="{{from}}"> - {{from}} – {{sum from size -1}} - </a> - {{/joinEach}} </div> </div> - </div> - {{else}} - {{t 'duplications.block_was_duplicated_by_a_deleted_resource'}} - {{/each}} + {{/each}} + {{/notEmpty}} </div> <div class="bubble-popup-arrow"></div> diff --git a/server/sonar-web/src/main/js/source-viewer/popups/duplication-popup.js b/server/sonar-web/src/main/js/source-viewer/popups/duplication-popup.js index 4564bfd8d1d..73dbec36ed8 100644 --- a/server/sonar-web/src/main/js/source-viewer/popups/duplication-popup.js +++ b/server/sonar-web/src/main/js/source-viewer/popups/duplication-popup.js @@ -42,27 +42,25 @@ define([ }, serializeData: function () { - var duplications, files, groupedBlocks; - files = this.model.get('duplicationFiles'); - groupedBlocks = _.groupBy(this.collection.toJSON(), '_ref'); - duplications = _.map(groupedBlocks, function (blocks, fileRef) { - return { - blocks: blocks, - file: files[fileRef] - }; + var that = this, + files = this.model.get('duplicationFiles'), + groupedBlocks = _.groupBy(this.collection.toJSON(), '_ref'), + duplications = _.map(groupedBlocks, function (blocks, fileRef) { + return { + blocks: blocks, + file: files[fileRef] + }; + }); + duplications = _.sortBy(duplications, function (d) { + var a = d.file.projectName !== that.model.get('projectName'), + b = d.file.subProjectName !== that.model.get('subProjectName'), + c = d.file.key !== that.model.get('key'); + return '' + a + b + c; }); - duplications = _.sortBy(duplications, (function (_this) { - return function (d) { - var a, b, c; - a = d.file.projectName !== _this.model.get('projectName'); - b = d.file.subProjectName !== _this.model.get('subProjectName'); - c = d.file.key !== _this.model.get('key'); - return '' + a + b + c; - }; - })(this)); return { component: this.model.toJSON(), - duplications: duplications + duplications: duplications, + inRemovedComponent: this.options.inRemovedComponent }; } }); diff --git a/server/sonar-web/src/main/js/source-viewer/viewer.js b/server/sonar-web/src/main/js/source-viewer/viewer.js index 9dabf5698c8..72f197f7008 100644 --- a/server/sonar-web/src/main/js/source-viewer/viewer.js +++ b/server/sonar-web/src/main/js/source-viewer/viewer.js @@ -142,7 +142,7 @@ define([ .fail(function () { that.model.set({ source: [ - {line: 0} + { line: 0 } ] }); finalize(); @@ -157,7 +157,7 @@ define([ options = { uuid: this.model.id }; return $.get(url, options).done(function (data) { that.model.set(data); - that.model.set({isUnitTest: data.q === 'UTS'}); + that.model.set({ isUnitTest: data.q === 'UTS' }); }); }, @@ -199,11 +199,11 @@ define([ requestSource: function () { var that = this, url = baseUrl + '/api/sources/lines', - options = _.extend({uuid: this.model.id}, this.linesLimit()); + options = _.extend({ uuid: this.model.id }, this.linesLimit()); return $.get(url, options).done(function (data) { var source = (data.sources || []).slice(0); if (source.length === 0 || (source.length > 0 && _.first(source).line === 1)) { - source.unshift({line: 0}); + source.unshift({ line: 0 }); } source = source.map(function (row) { return _.extend(row, { @@ -236,7 +236,7 @@ define([ requestDuplications: function () { var that = this, url = baseUrl + '/api/duplications/show', - options = { uuid : this.model.id }; + options = { uuid: this.model.id }; return $.get(url, options, function (data) { var hasDuplications = (data != null) && (data.duplications != null), duplications = []; @@ -378,7 +378,7 @@ define([ e.stopPropagation(); $('body').click(); var line = +$(e.currentTarget).data('line-number'), - row = _.findWhere(this.model.get('source'), {line: line}), + row = _.findWhere(this.model.get('source'), { line: line }), popup = new SCMPopupView({ triggerEl: $(e.currentTarget), model: new Backbone.Model(row) @@ -431,14 +431,18 @@ define([ this.clearTooltips(); var index = $(e.currentTarget).data('index'), line = $(e.currentTarget).data('line-number'), - blocks = this.model.get('duplications')[index - 1].blocks; + blocks = this.model.get('duplications')[index - 1].blocks, + inRemovedComponent = _.some(blocks, function (b) { + return b._ref == null; + }); blocks = _.filter(blocks, function (b) { var outOfBounds = b.from > line || b.from + b.size < line; - return (b._ref !== '1') || (b._ref === '1' && outOfBounds); + return (b._ref != null) && ((b._ref !== '1') || (b._ref === '1' && outOfBounds)); }); var popup = new DuplicationPopupView({ triggerEl: $(e.currentTarget), model: this.model, + inRemovedComponent: inRemovedComponent, collection: new Backbone.Collection(blocks) }); popup.render(); @@ -583,7 +587,7 @@ define([ that.model.set({ hasSourceAfter: true }); } if (source.length === 0 || (source.length > 0 && _.first(source).line === 1)) { - source.unshift({line: 0}); + source.unshift({ line: 0 }); } source = source.map(function (row) { return _.extend(row, { diff --git a/server/sonar-web/src/test/js/source-viewer-duplications.js b/server/sonar-web/src/test/js/source-viewer-duplications.js index c0046e3bc40..35743ff2e20 100644 --- a/server/sonar-web/src/test/js/source-viewer-duplications.js +++ b/server/sonar-web/src/test/js/source-viewer-duplications.js @@ -21,14 +21,14 @@ var lib = require('../lib'), - testName = lib.testName('Source Viewer'); + testName = lib.testName('Source Viewer', 'Duplications'); lib.initMessages(); lib.changeWorkingDirectory('source-viewer-duplications'); lib.configureCasper(); -casper.test.begin(testName('Duplications'), 4, function (test) { +casper.test.begin(testName(), 4, function (test) { casper .start(lib.buildUrl('source-viewer'), function () { lib.setDefaultViewport(); @@ -74,3 +74,50 @@ casper.test.begin(testName('Duplications'), 4, function (test) { test.done(); }); }); + + +casper.test.begin(testName('In Removed Component'), 2, function (test) { + casper + .start(lib.buildUrl('source-viewer'), function () { + lib.setDefaultViewport(); + + + lib.mockRequestFromFile('/api/components/app', 'app.json'); + lib.mockRequestFromFile('/api/sources/lines', 'lines.json'); + lib.mockRequestFromFile('/api/issues/search', 'issues.json'); + lib.mockRequestFromFile('/api/duplications/show', 'duplications-removed.json'); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/source-viewer/app.js']); + }); + }) + + .then(function () { + casper.waitForSelector('.source-line'); + }) + + .then(function () { + test.assertElementCount('.source-line-duplications.source-line-duplicated', 5); + casper.click('.source-line-duplicated'); + lib.waitForElementCount('.source-line-duplications-extra.source-line-duplicated', 5); + }) + + .then(function () { + casper.waitForSelector('.bubble-popup'); + }) + + .then(function () { + lib.capture(); + test.assertExists('.bubble-popup .alert'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); diff --git a/server/sonar-web/src/test/json/source-viewer-duplications/duplications-removed.json b/server/sonar-web/src/test/json/source-viewer-duplications/duplications-removed.json new file mode 100644 index 00000000000..8d4f832697a --- /dev/null +++ b/server/sonar-web/src/test/json/source-viewer-duplications/duplications-removed.json @@ -0,0 +1,30 @@ +{ + "duplications": [ + { + "blocks": [ + { + "from": 11, + "size": 5, + "_ref": "1" + }, + { + "from": 12, + "size": 5 + } + ] + } + ], + "files": { + "1": { + "uuid": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaaa", + "key": "sample:sample", + "name": "Sample", + "longName": "Sample", + "q": "FIL", + "subProject": "sample:subproject", + "subProjectName": "Sample Sub-Project", + "project": "sample:project", + "projectName": "Sample Project" + } + } +} |