mirror of
https://github.com/discourse/discourse.git
synced 2025-07-11 01:43:37 +08:00
FIX: Show empty search results sets (#13604)
If the server returned an empty result set, the client did not update the local set and displayed last search results.
This commit is contained in:
@ -98,16 +98,6 @@ export function translateResults(results, opts) {
|
|||||||
)
|
)
|
||||||
.then((results_) => {
|
.then((results_) => {
|
||||||
translateGroupedSearchResults(results_, opts);
|
translateGroupedSearchResults(results_, opts);
|
||||||
|
|
||||||
if (
|
|
||||||
!results_.topics.length &&
|
|
||||||
!results_.posts.length &&
|
|
||||||
!results_.users.length &&
|
|
||||||
!results_.categories.length
|
|
||||||
) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EmberObject.create(results_);
|
return EmberObject.create(results_);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
acceptance,
|
acceptance,
|
||||||
|
count,
|
||||||
exists,
|
exists,
|
||||||
queryAll,
|
queryAll,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
@ -155,6 +156,38 @@ acceptance("Search - Anonymous", function (needs) {
|
|||||||
acceptance("Search - Authenticated", function (needs) {
|
acceptance("Search - Authenticated", function (needs) {
|
||||||
needs.user();
|
needs.user();
|
||||||
|
|
||||||
|
needs.pretender((server, helper) => {
|
||||||
|
server.get("/search/query", (request) => {
|
||||||
|
if (request.queryParams.term.includes("empty")) {
|
||||||
|
return helper.response({
|
||||||
|
posts: [],
|
||||||
|
users: [],
|
||||||
|
categories: [],
|
||||||
|
tags: [],
|
||||||
|
groups: [],
|
||||||
|
grouped_search_result: {
|
||||||
|
more_posts: null,
|
||||||
|
more_users: null,
|
||||||
|
more_categories: null,
|
||||||
|
term: "plans test",
|
||||||
|
search_log_id: 1,
|
||||||
|
more_full_page_results: null,
|
||||||
|
can_create_topic: true,
|
||||||
|
error: null,
|
||||||
|
type_filter: null,
|
||||||
|
post_ids: [],
|
||||||
|
user_ids: [],
|
||||||
|
category_ids: [],
|
||||||
|
tag_ids: [],
|
||||||
|
group_ids: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return helper.response(searchFixtures["search/query"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("Right filters are shown to logged-in users", async function (assert) {
|
test("Right filters are shown to logged-in users", async function (assert) {
|
||||||
const inSelector = selectKit(".select-kit#in");
|
const inSelector = selectKit(".select-kit#in");
|
||||||
|
|
||||||
@ -177,6 +210,20 @@ acceptance("Search - Authenticated", function (needs) {
|
|||||||
assert.ok(exists(".search-advanced-options .in-private"));
|
assert.ok(exists(".search-advanced-options .in-private"));
|
||||||
assert.ok(exists(".search-advanced-options .in-seen"));
|
assert.ok(exists(".search-advanced-options .in-seen"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Works with empty result sets", async function (assert) {
|
||||||
|
await visit("/t/internationalization-localization/280");
|
||||||
|
await click(".search-dropdown");
|
||||||
|
await click(".search-context input[type=checkbox]");
|
||||||
|
await fillIn("#search-term", "plans");
|
||||||
|
await triggerKeyEvent("#search-term", "keyup", 32);
|
||||||
|
assert.notEqual(count(".item"), 0);
|
||||||
|
|
||||||
|
await fillIn("#search-term", "plans empty");
|
||||||
|
await triggerKeyEvent("#search-term", "keyup", 32);
|
||||||
|
assert.equal(count(".item"), 0);
|
||||||
|
assert.equal(count(".no-results"), 1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
acceptance("Search - with tagging enabled", function (needs) {
|
acceptance("Search - with tagging enabled", function (needs) {
|
||||||
|
Reference in New Issue
Block a user