From 5155b958eea1fef0590809ddb38a8fb9af5021bb Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Tue, 14 Apr 2015 15:45:17 +0200 Subject: [PATCH] SONAR-5851 fix when load next page of filtered changelog --- .../profile-changelog-view.js | 9 +- .../src/main/js/quality-profiles/profile.js | 8 +- .../sonar-web/src/test/js/quality-profiles.js | 87 +++++++++++-------- 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/server/sonar-web/src/main/js/quality-profiles/profile-changelog-view.js b/server/sonar-web/src/main/js/quality-profiles/profile-changelog-view.js index 8c6ffae929d..a07618999bd 100644 --- a/server/sonar-web/src/main/js/quality-profiles/profile-changelog-view.js +++ b/server/sonar-web/src/main/js/quality-profiles/profile-changelog-view.js @@ -29,19 +29,14 @@ define([ 'click .js-show-more-changelog': 'onShowMoreChangelogClick' }, - initialize: function () { - this.searchParameters = {}; - }, - onFormSubmit: function (e) { e.preventDefault(); - this.searchParameters = this.getSearchParameters(); - this.model.fetchChangelog(this.searchParameters); + this.model.fetchChangelog(this.getSearchParameters()); }, onShowMoreChangelogClick: function (e) { e.preventDefault(); - this.model.fetchMoreChangelog(this.searchParameters); + this.model.fetchMoreChangelog(); }, getSearchParameters: function () { diff --git a/server/sonar-web/src/main/js/quality-profiles/profile.js b/server/sonar-web/src/main/js/quality-profiles/profile.js index 7d1c63e2c35..d6b0450caf9 100644 --- a/server/sonar-web/src/main/js/quality-profiles/profile.js +++ b/server/sonar-web/src/main/js/quality-profiles/profile.js @@ -88,18 +88,18 @@ define(function () { }); }, - fetchMoreChangelog: function (options) { + fetchMoreChangelog: function () { var that = this, url = baseUrl + '/api/qualityprofiles/changelog', page = this.get('eventsPage') || 0, - opts = _.extend({}, options, { profileKey: this.id, p: page + 1 }); + parameters = this.get('eventsParameters') || {}, + opts = _.extend({}, parameters, { profileKey: this.id, p: page + 1 }); return $.get(url, opts).done(function (r) { var events = that.get('events') || []; that.set({ events: [].concat(events, r.events), eventsPage: r.p, - totalEvents: r.total, - eventsParameters: _.clone(options) + totalEvents: r.total }); }); } diff --git a/server/sonar-web/src/test/js/quality-profiles.js b/server/sonar-web/src/test/js/quality-profiles.js index c330bc6de80..7a248a27ac9 100644 --- a/server/sonar-web/src/test/js/quality-profiles.js +++ b/server/sonar-web/src/test/js/quality-profiles.js @@ -551,7 +551,8 @@ casper.test.begin(testName('Change Parent'), 1, function (test) { this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-change-parent.json'); lib.mockRequestFromFile('/api/rules/search', 'rules.json'); - this.inheritanceMock = lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance-change-parent.json'); + this.inheritanceMock = lib.mockRequestFromFile('/api/qualityprofiles/inheritance', + 'inheritance-change-parent.json'); lib.mockRequest('/api/qualityprofiles/change_parent', '{}'); }) @@ -717,39 +718,55 @@ casper.test.begin(testName('Changelog'), 21, function (test) { }); -casper.test.begin(testName('Changelog Permalink'), 1, function (test) { - casper - .start(lib.buildUrl('profiles#changelog?since=2015-03-25&key=java-sonar-way-67887&to=2015-03-26'), function () { - lib.setDefaultViewport(); - - lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json'); - lib.mockRequestFromFile('/api/rules/search', 'rules.json'); - lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json'); - lib.mockRequestFromFile('/api/qualityprofiles/changelog', 'changelog.json', { data: { - since: '2015-03-25', - to: '2015-03-26' - }}); - }) - - .then(function () { - casper.evaluate(function () { - require(['/js/quality-profiles/app.js']); - }); - }) - - .then(function () { - casper.waitForSelector('.js-show-more-changelog'); - }) - - .then(function () { - test.assertElementCount('#quality-profile-changelog tbody tr', 2); - }) - - .then(function () { - lib.sendCoverage(); - }) - - .run(function () { - test.done(); +casper.test.begin(testName('Changelog Permalink'), 2, function (test) { + casper + .start(lib.buildUrl('profiles#changelog?since=2015-03-25&key=java-sonar-way-67887&to=2015-03-26'), function () { + lib.setDefaultViewport(); + + lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json'); + lib.mockRequestFromFile('/api/rules/search', 'rules.json'); + lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json'); + lib.mockRequestFromFile('/api/qualityprofiles/changelog', 'changelog2.json', { + data: { + p: '2', + since: '2015-03-25', + to: '2015-03-26' + } + }); + lib.mockRequestFromFile('/api/qualityprofiles/changelog', 'changelog.json', { + data: { + since: '2015-03-25', + to: '2015-03-26' + } + }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/quality-profiles/app.js']); }); + }) + + .then(function () { + casper.waitForSelector('.js-show-more-changelog'); + }) + + .then(function () { + test.assertElementCount('#quality-profile-changelog tbody tr', 2); + + casper.click('.js-show-more-changelog'); + lib.waitForElementCount('#quality-profile-changelog tbody tr', 3); + }) + + .then(function () { + test.assertDoesntExist('.js-show-more-changelog'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); }); -- 2.39.5