From 58324bc44a6adabada7125e2b76884a5f7d218b7 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 11 Mar 2015 13:55:22 +0100 Subject: [PATCH] SONAR-6234 apply feedback --- .../src/main/js/widgets/issue-filter.js | 24 +++++-- .../test/js/project-issue-filter-widget.js | 71 +++++++++++++++++++ ...rity-with-IGNORED-differential-period.json | 32 +++++++++ .../resources/org/sonar/l10n/core.properties | 2 +- 4 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 server/sonar-web/src/test/json/project-issues-filter-widget/unresolved-issues-by-severity-with-IGNORED-differential-period.json diff --git a/server/sonar-web/src/main/js/widgets/issue-filter.js b/server/sonar-web/src/main/js/widgets/issue-filter.js index 03479ae361a..e43c28ab946 100644 --- a/server/sonar-web/src/main/js/widgets/issue-filter.js +++ b/server/sonar-web/src/main/js/widgets/issue-filter.js @@ -220,12 +220,19 @@ define(['templates/widgets'], function () { }, initialize: function () { + this.shouldIgnorePeriod = false; this.model = new Backbone.Model({ query: this.options.query, parsedQuery: this.getParsedQuery(), - property: this.options.distributionAxis, - periodDate: this.options.periodDate + property: this.options.distributionAxis }); + + // Ignore the period date if the filter contains any date criteria + // `this.shouldIgnorePeriod` is set in `this.getParsedQuery()` + if (!this.shouldIgnorePeriod) { + this.model.set({ periodDate: this.options.periodDate }); + } + this.listenTo(this.model, 'change', this.render); this.conf = byDistributionConf[this.options.distributionAxis]; this.query = this.getParsedQuery(); @@ -244,12 +251,21 @@ define(['templates/widgets'], function () { if (this.options.componentKey != null) { _.extend(query, { componentKey: this.options.componentKey }); } - if (this.options.periodDate != null) { + if (!this.hasDateFilter(query) && this.options.periodDate != null) { _.extend(query, { createdAfter: this.options.periodDate }); + } else { + this.shouldIgnorePeriod = true; } return query; }, + hasDateFilter: function (query) { + var q = query || this.model.get('parsedQuery'); + return _.some(['createdAt', 'createdBefore', 'createdAfter', 'createdInLast'], function (p) { + return q[p] != null; + }); + }, + sortItems: function (items) { var comparator = this.conf != null && this.conf.comparator != null ? this.conf.comparator : defaultComparator; return _.sortBy(items, comparator); @@ -288,7 +304,7 @@ define(['templates/widgets'], function () { if (this.options.componentUuid != null) { _.extend(options, { componentUuids: this.options.componentUuid }); } - if (this.options.periodDate != null) { + if (this.options.periodDate != null && !this.shouldIgnorePeriod) { _.extend(options, { createdAfter: this.options.periodDate }); } return $.get(url, options).done(function (r) { diff --git a/server/sonar-web/src/test/js/project-issue-filter-widget.js b/server/sonar-web/src/test/js/project-issue-filter-widget.js index 961c79a987c..6b7a1a30116 100644 --- a/server/sonar-web/src/test/js/project-issue-filter-widget.js +++ b/server/sonar-web/src/test/js/project-issue-filter-widget.js @@ -219,3 +219,74 @@ casper.test.begin(testName('Unresolved Issues By Severity With Differential Peri test.done(); }); }); + + +casper.test.begin(testName('Unresolved Issues By Severity With IGNORED Differential Period'), 19, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', + 'unresolved-issues-by-severity-with-IGNORED-differential-period.json', + { data: { resolved: 'false', createdInLast: '1w' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false|createdInLast=1w', + distributionAxis: 'severities', + periodDate: '2014-12-09T17:12:38+0100', + componentUuid: '69e57151-be0d-4157-adff-c06741d88879', + componentKey: 'org.codehaus.sonar:sonar' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 6); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '549'); + test.assertSelectorContains('tr:nth-child(2)', '0'); + test.assertSelectorContains('tr:nth-child(3)', '59'); + test.assertSelectorContains('tr:nth-child(4)', '306'); + test.assertSelectorContains('tr:nth-child(5)', '135'); + test.assertSelectorContains('tr:nth-child(6)', '49'); + + // check that differential period is ignored + test.assertSelectorDoesntContain('tr:nth-child(1)', '+'); + test.assertSelectorDoesntContain('tr:nth-child(2)', '+'); + test.assertSelectorDoesntContain('tr:nth-child(3)', '+'); + test.assertSelectorDoesntContain('tr:nth-child(4)', '+'); + test.assertSelectorDoesntContain('tr:nth-child(5)', '+'); + test.assertSelectorDoesntContain('tr:nth-child(6)', '+'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdInLast=1w"]'); + test.assertExists('tr:nth-child(2) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdInLast=1w|severities=BLOCKER"]'); + test.assertExists('tr:nth-child(3) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdInLast=1w|severities=CRITICAL"]'); + test.assertExists('tr:nth-child(4) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdInLast=1w|severities=MAJOR"]'); + test.assertExists('tr:nth-child(5) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdInLast=1w|severities=MINOR"]'); + test.assertExists('tr:nth-child(6) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdInLast=1w|severities=INFO"]'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); diff --git a/server/sonar-web/src/test/json/project-issues-filter-widget/unresolved-issues-by-severity-with-IGNORED-differential-period.json b/server/sonar-web/src/test/json/project-issues-filter-widget/unresolved-issues-by-severity-with-IGNORED-differential-period.json new file mode 100644 index 00000000000..afa5ed4f5cc --- /dev/null +++ b/server/sonar-web/src/test/json/project-issues-filter-widget/unresolved-issues-by-severity-with-IGNORED-differential-period.json @@ -0,0 +1,32 @@ +{ + "total": 549, + "p": 1, + "ps": 1, + "facets": [ + { + "property": "severities", + "values": [ + { + "val": "MAJOR", + "count": 306 + }, + { + "val": "MINOR", + "count": 135 + }, + { + "val": "CRITICAL", + "count": 59 + }, + { + "val": "INFO", + "count": 49 + }, + { + "val": "BLOCKER", + "count": 0 + } + ] + } + ] +} diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 50b4924df33..1662177c320 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1360,7 +1360,7 @@ widget.project_issue_filter.unknown_filter_warning=This widget is configured to widget.project_issue_filter.insufficient_privileges_warning=Widget cannot be displayed: insufficient privileges. widget.project_issue_filter.property.distributionAxis.option.severities.name=By Severity widget.project_issue_filter.property.distributionAxis.option.statuses.name=By Status -widget.project_issue_filter.property.distributionAxis.option.createdAt.name=New Issues +widget.project_issue_filter.property.distributionAxis.option.createdAt.name=By Creation Date widget.project_issue_filter.property.distributionAxis.option.actionPlans.name=By Action Plan widget.project_issue_filter.property.distributionAxis.option.assignees.name=By Assignee widget.project_issue_filter.property.distributionAxis.option.tags.name=By Tag -- 2.39.5