update search description on new search string (#24619)
* update search description on new search string * disable xss-lint rule for jquery.html
This commit is contained in:
@@ -340,15 +340,28 @@ define([
|
|||||||
teamsTabView.$('.search-field').val('');
|
teamsTabView.$('.search-field').val('');
|
||||||
teamsTabView.$('.action-search').click();
|
teamsTabView.$('.action-search').click();
|
||||||
|
|
||||||
verifyTeamsRequest({
|
verifyTeamsRequest({ order_by: 'last_activity_at' });
|
||||||
order_by: 'last_activity_at'
|
|
||||||
});
|
|
||||||
AjaxHelpers.respondWithJson(requests, {});
|
AjaxHelpers.respondWithJson(requests, {});
|
||||||
AjaxHelpers.respondWithJson(requests, { count: 0 });
|
AjaxHelpers.respondWithJson(requests, { count: 0 });
|
||||||
expect(teamsTabView.$('.page-title').text()).toBe('Test Topic 1');
|
expect(teamsTabView.$('.page-title').text()).toBe('Test Topic 1');
|
||||||
expect(teamsTabView.$('.page-description').text()).toBe('Test description 1');
|
expect(teamsTabView.$('.page-description').text()).toBe('Test description 1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('updates the description when search string updates', function() {
|
||||||
|
var newString = 'bar';
|
||||||
|
setUpTopicTab();
|
||||||
|
performSearch();
|
||||||
|
expect(teamsTabView.$('.page-title').text()).toBe('Team Search');
|
||||||
|
expect(teamsTabView.$('.page-description').text()).toBe('Showing results for "foo"');
|
||||||
|
teamsTabView.$('.search-field').val(newString);
|
||||||
|
teamsTabView.$('.action-search').click();
|
||||||
|
AjaxHelpers.respondWithJson(requests, { count: 0 });
|
||||||
|
expect(teamsTabView.$('.page-title').text()).toBe('Team Search');
|
||||||
|
expect(teamsTabView.$('.page-description').text()).toBe(
|
||||||
|
'Showing results for "' + newString + '"'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('can navigate back to all teams from a search', function() {
|
it('can navigate back to all teams from a search', function() {
|
||||||
setUpTopicTab();
|
setUpTopicTab();
|
||||||
// Perform a search
|
// Perform a search
|
||||||
|
|||||||
@@ -238,10 +238,7 @@
|
|||||||
collection: view.teamsCollection,
|
collection: view.teamsCollection,
|
||||||
breadcrumbs: view.createBreadcrumbs(topic),
|
breadcrumbs: view.createBreadcrumbs(topic),
|
||||||
title: gettext('Team Search'),
|
title: gettext('Team Search'),
|
||||||
description: StringUtils.interpolate(
|
description: view.searchDescription(),
|
||||||
gettext('Showing results for "{searchString}"'),
|
|
||||||
{searchString: view.teamsCollection.getSearchString()}
|
|
||||||
),
|
|
||||||
showSortControls: false
|
showSortControls: false
|
||||||
});
|
});
|
||||||
view.render();
|
view.render();
|
||||||
@@ -377,6 +374,16 @@
|
|||||||
return deferred.promise();
|
return deferred.promise();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a translated search description string from the teams collection
|
||||||
|
*/
|
||||||
|
searchDescription: function() {
|
||||||
|
return StringUtils.interpolate(
|
||||||
|
gettext('Showing results for "{searchString}"'),
|
||||||
|
{searchString: this.teamsCollection.getSearchString()}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
createTeamsListView: function(options) {
|
createTeamsListView: function(options) {
|
||||||
var topic = options.topic,
|
var topic = options.topic,
|
||||||
collection = options.collection,
|
collection = options.collection,
|
||||||
@@ -408,18 +415,24 @@
|
|||||||
// topic teams page.
|
// topic teams page.
|
||||||
// 3. Otherwise, do nothing and remain on the current page.
|
// 3. Otherwise, do nothing and remain on the current page.
|
||||||
// Note: Backbone makes this a no-op if redirecting to the current page.
|
// Note: Backbone makes this a no-op if redirecting to the current page.
|
||||||
this.listenTo(collection, 'sync', function() {
|
this.listenTo(
|
||||||
// Clear the stale flag here as by definition the collection is up-to-date,
|
collection,
|
||||||
// and the flag itself isn't guaranteed to be cleared yet. This is to ensure
|
'sync',
|
||||||
// that the collection doesn't unnecessarily get refreshed again.
|
_.bind(function() {
|
||||||
collection.isStale = false;
|
// Clear the stale flag here as by definition the collection is up-to-date,
|
||||||
|
// and the flag itself isn't guaranteed to be cleared yet. This is to ensure
|
||||||
|
// that the collection doesn't unnecessarily get refreshed again.
|
||||||
|
collection.isStale = false;
|
||||||
|
|
||||||
if (collection.getSearchString()) {
|
if (collection.getSearchString()) {
|
||||||
Backbone.history.navigate(searchUrl, {trigger: true});
|
Backbone.history.navigate(searchUrl, {trigger: true});
|
||||||
} else if (Backbone.history.getFragment() === searchUrl) {
|
// xss-lint: disable=javascript-jquery-html
|
||||||
Backbone.history.navigate('topics/' + topic.get('id'), {trigger: true});
|
this.$el.find('.page-description').html(this.searchDescription());
|
||||||
}
|
} else if (Backbone.history.getFragment() === searchUrl) {
|
||||||
});
|
Backbone.history.navigate('topics/' + topic.get('id'), {trigger: true});
|
||||||
|
}
|
||||||
|
}, this)
|
||||||
|
);
|
||||||
return viewWithHeader;
|
return viewWithHeader;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user