Commit b145f5d9 authored by Zufeng Wang's avatar Zufeng Wang Committed by Chromium LUCI CQ

Add subcategory search to help app lss integration

Makes subcategories searchable, but they don't appear in the search
result snippets.

Bug: b/172533871
Change-Id: I6b1e053929bc1a4ecada135ae582a5deba1e673a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2620740
Commit-Queue: Zufeng Wang <zufeng@google.com>
Reviewed-by: default avatardstockwell <dstockwell@google.com>
Cr-Commit-Position: refs/heads/master@{#842374}
parent 25391d68
...@@ -133,6 +133,7 @@ js_library("test_guest_query_receiver_js") { ...@@ -133,6 +133,7 @@ js_library("test_guest_query_receiver_js") {
js_library("test_driver_js") { js_library("test_driver_js") {
testonly = true testonly = true
sources = [ "test/driver.js" ] sources = [ "test/driver.js" ]
externs_list = [ "//third_party/chaijs/externs/chai-3.5.js" ]
deps = [ deps = [
":test_driver_api_js", ":test_driver_api_js",
"//chromeos/components/help_app_ui/resources:browser_proxy", "//chromeos/components/help_app_ui/resources:browser_proxy",
......
...@@ -37,6 +37,7 @@ function toString16(s) { ...@@ -37,6 +37,7 @@ function toString16(s) {
const TITLE_ID = 'title'; const TITLE_ID = 'title';
const BODY_ID = 'body'; const BODY_ID = 'body';
const CATEGORY_ID = 'main-category'; const CATEGORY_ID = 'main-category';
const SUBCATEGORY_ID = 'subcategory';
const SUBHEADING_ID = 'subheading'; const SUBHEADING_ID = 'subheading';
/** /**
...@@ -79,9 +80,17 @@ guestMessagePipe.registerHandler( ...@@ -79,9 +80,17 @@ guestMessagePipe.registerHandler(
weight: 0.1, weight: 0.1,
}, },
]; ];
if (searchable_item.subcategoryNames) {
for (let i = 0; i < searchable_item.subcategoryNames.length; ++i) {
contents.push({
id: SUBCATEGORY_ID + i,
content: toString16(searchable_item.subcategoryNames[i]),
weight: 0.1,
});
}
}
// If there are subheadings, use those instead of the body. // If there are subheadings, use those instead of the body.
if (searchable_item.subheadings if (searchable_item.subheadings) {
&& searchable_item.subheadings.length > 0) {
for (let i = 0; i < searchable_item.subheadings.length; ++i) { for (let i = 0; i < searchable_item.subheadings.length; ++i) {
contents.push({ contents.push({
id: SUBHEADING_ID + i, id: SUBHEADING_ID + i,
......
...@@ -98,6 +98,72 @@ GUEST_TEST('GuestCanSearchWithHeadings', async () => { ...@@ -98,6 +98,72 @@ GUEST_TEST('GuestCanSearchWithHeadings', async () => {
]); ]);
}); });
// Test that search works for the categories and subcategories of searchable
// items.
GUEST_TEST('GuestCanSearchWithCategories', async () => {
const delegate = await waitForInitialIndexUpdate();
await delegate.addOrUpdateSearchIndex([{
// Main category match. No subcategories.
id: 'test-id-1',
title: 'Title with of article',
body: 'Body text',
mainCategoryName: 'Verycomplicatedsearchtoken',
locale: 'en-US',
},{
// Subcategory match.
id: 'test-id-2',
title: 'Title 2',
subcategoryNames: [
'Subcategory 1',
'verycomplicatedsearchtoken in subcategory. Verycomplicatedsearchtoken',
'Another subcategory with verycomplicatedsearchtoken',
],
body: 'Body text',
mainCategoryName: 'Help',
locale: 'en-US',
},{
// Should not appear in the results.
id: 'test-id-3',
title: 'Title of irrelevant article',
body: 'Body text',
mainCategoryName: 'Help',
locale: 'en-US',
}]);
// Keep polling until the index finishes updating or too much time has passed.
/** @type {?helpApp.FindResponse} */
let response = null;
for (let numTries = 0; numTries < 50; numTries++) {
// This search query was chosen because it is unlikely to show any search
// results for the real app's data.
response = await delegate.findInSearchIndex('verycomplicatedsearchtoken');
if (response && response.results && response.results.length > 0) break;
await new Promise(resolve => {setTimeout(resolve, 50)});
}
// Don't test the ordering of search results because they should have similar
// relevance.
chai.expect(response.results).to.have.deep.members([
// This result only matches on the main category.
{
id: 'test-id-1',
titlePositions: [],
subheadingIndex: null,
subheadingPositions: null,
bodyPositions: [],
},
// This result only matches on the second and third subcategories.
{
id: 'test-id-2',
titlePositions: [],
subheadingIndex: null,
subheadingPositions: null,
bodyPositions: [],
},
]);
});
// Test that the guest frame can clear the search index. // Test that the guest frame can clear the search index.
GUEST_TEST('GuestCanClearSearchIndex', async () => { GUEST_TEST('GuestCanClearSearchIndex', async () => {
const delegate = await waitForInitialIndexUpdate(); const delegate = await waitForInitialIndexUpdate();
......
...@@ -84,6 +84,11 @@ TEST_F('HelpAppUIBrowserTest', 'GuestCanSearchWithHeadings', async () => { ...@@ -84,6 +84,11 @@ TEST_F('HelpAppUIBrowserTest', 'GuestCanSearchWithHeadings', async () => {
testDone(); testDone();
}); });
TEST_F('HelpAppUIBrowserTest', 'GuestCanSearchWithCategories', async () => {
await runTestInGuest('GuestCanSearchWithCategories');
testDone();
});
TEST_F('HelpAppUIBrowserTest', 'GuestCanClearSearchIndex', async () => { TEST_F('HelpAppUIBrowserTest', 'GuestCanClearSearchIndex', async () => {
await runTestInGuest('GuestCanClearSearchIndex'); await runTestInGuest('GuestCanClearSearchIndex');
testDone(); testDone();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment