FEATURE: Allow scoping search to tag (#8345)

* When viewing a tag, the search widget will now show a checkbox to scope the search by tag, which will limit search results to that tag on desktop and mobile
This commit is contained in:
Martin Brennan
2019-11-14 10:40:26 +10:00
committed by GitHub
parent 6e1fe22a9d
commit e7226a8c84
14 changed files with 204 additions and 7 deletions
@@ -50,6 +50,14 @@ QUnit.test("search for a tag", async assert => {
});
QUnit.test("search scope checkbox", async assert => {
await visit("/tags/important");
await click("#search-button");
assert.ok(
exists(".search-context input:checked"),
"scope to tag checkbox is checked"
);
await click("#search-button");
await visit("/c/bug");
await click("#search-button");
assert.ok(
@@ -3756,6 +3756,113 @@ export default {
]
}
},
"/tags/important/l/latest.json": {
users: [{ id: 1, username: "sam", avatar_template: "/images/avatar.png" }],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 4,
per_page: 30,
tags: [
{
id: 1,
name: "test",
topic_count: 2,
staff: false
}
],
topics: [
{
id: 16,
title: "Dinosaurs are the best",
fancy_title: "Dinosaurs are the best",
slug: "dinosaurs-are-the-best",
posts_count: 1,
reply_count: 0,
highest_post_number: 1,
image_url: null,
created_at: "2019-11-12T05:19:52.300Z",
last_posted_at: "2019-11-12T05:19:52.848Z",
bumped: true,
bumped_at: "2019-11-12T05:19:52.848Z",
unseen: false,
last_read_post_number: 1,
unread: 0,
new_posts: 0,
pinned: false,
unpinned: null,
visible: true,
closed: false,
archived: false,
notification_level: 3,
bookmarked: false,
liked: false,
tags: ["test"],
views: 2,
like_count: 0,
has_summary: false,
archetype: "regular",
last_poster_username: "sam",
category_id: 1,
pinned_globally: false,
featured_link: null,
posters: [
{
extras: "latest single",
description: "Original Poster, Most Recent Poster",
user_id: 1,
primary_group_id: null
}
]
},
{
id: 15,
title: "This is a test tagged post",
fancy_title: "This is a test tagged post",
slug: "this-is-a-test-tagged-post",
posts_count: 1,
reply_count: 0,
highest_post_number: 1,
image_url: null,
created_at: "2019-11-12T05:19:32.032Z",
last_posted_at: "2019-11-12T05:19:32.516Z",
bumped: true,
bumped_at: "2019-11-12T05:19:32.516Z",
unseen: false,
last_read_post_number: 1,
unread: 0,
new_posts: 0,
pinned: false,
unpinned: null,
visible: true,
closed: false,
archived: false,
notification_level: 3,
bookmarked: false,
liked: false,
tags: ["test"],
views: 1,
like_count: 0,
has_summary: false,
archetype: "regular",
last_poster_username: "sam",
category_id: 3,
pinned_globally: false,
featured_link: null,
posters: [
{
extras: "latest single",
description: "Original Poster, Most Recent Poster",
user_id: 1,
primary_group_id: null
}
]
}
]
}
},
"/c/feature/l/latest.json": {
users: [
{ id: 1, username: "sam", avatar_template: "/images/avatar.png" },
+28 -1
View File
@@ -1,4 +1,7 @@
import { translateResults } from "discourse/lib/search";
import {
translateResults,
searchContextDescription
} from "discourse/lib/search";
QUnit.module("lib:search");
@@ -31,3 +34,27 @@ QUnit.test("unescapesEmojisInBlurbs", assert => {
assert.ok(blurb.indexOf("<img src") === 0);
assert.ok(blurb.indexOf(":thinking:") === -1);
});
QUnit.test("searchContextDescription", assert => {
assert.equal(
searchContextDescription("topic"),
I18n.t("search.context.topic")
);
assert.equal(
searchContextDescription("user", "silvio.dante"),
I18n.t("search.context.user", { username: "silvio.dante" })
);
assert.equal(
searchContextDescription("category", "staff"),
I18n.t("search.context.category", { category: "staff" })
);
assert.equal(
searchContextDescription("tag", "important"),
I18n.t("search.context.tag", { tag: "important" })
);
assert.equal(
searchContextDescription("private_messages"),
I18n.t("search.context.private_messages")
);
assert.equal(searchContextDescription("bad_type"), null);
});