Skip to content

Commit db495ea

Browse files
scottbellakhenry
andauthored
If no matching tags, do not attempt tag search (#5839)
* do not attempt search if no matching tags * fix timing on test * commit again in hopes that github will run checks * add back null tag check * add some better documentation to tests Co-authored-by: Andrew Henry <[email protected]>
1 parent 9022d5d commit db495ea

File tree

6 files changed

+63
-2
lines changed

6 files changed

+63
-2
lines changed

e2e/tests/functional/plugins/notebook/notebookWithCouchDB.e2e.spec.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This test suite is dedicated to tests which verify the basic operations surround
2727
const { test, expect } = require('../../../../baseFixtures');
2828
const { createDomainObjectWithDefaults } = require('../../../../appActions');
2929

30-
test.describe('Notebook Network Request Inspection @couchdb', () => {
30+
test.describe('Notebook Tests with CouchDB @couchdb', () => {
3131
let testNotebook;
3232
test.beforeEach(async ({ page }) => {
3333
//Navigate to baseURL
@@ -221,6 +221,45 @@ test.describe('Notebook Network Request Inspection @couchdb', () => {
221221

222222
expect(filterNonFetchRequests(addingNotebookElementsRequests).length).toBeLessThanOrEqual(4);
223223
});
224+
225+
test('Search tests', async ({ page }) => {
226+
test.info().annotations.push({
227+
type: 'issue',
228+
description: 'https://github.com/akhenry/openmct-yamcs/issues/69'
229+
});
230+
await page.locator('text=To start a new entry, click here or drag and drop any object').click();
231+
await page.locator('[aria-label="Notebook Entry Input"]').click();
232+
await page.locator('[aria-label="Notebook Entry Input"]').fill(`First Entry`);
233+
await page.locator('[aria-label="Notebook Entry Input"]').press('Enter');
234+
235+
// Add three tags
236+
await page.hover(`button:has-text("Add Tag")`);
237+
await page.locator(`button:has-text("Add Tag")`).click();
238+
await page.locator('[placeholder="Type to select tag"]').click();
239+
await page.locator('[aria-label="Autocomplete Options"] >> text=Science').click();
240+
await page.waitForSelector('[aria-label="Tag"]:has-text("Science")');
241+
242+
await page.hover(`button:has-text("Add Tag")`);
243+
await page.locator(`button:has-text("Add Tag")`).click();
244+
await page.locator('[placeholder="Type to select tag"]').click();
245+
await page.locator('[aria-label="Autocomplete Options"] >> text=Drilling').click();
246+
await page.waitForSelector('[aria-label="Tag"]:has-text("Drilling")');
247+
248+
await page.hover(`button:has-text("Add Tag")`);
249+
await page.locator(`button:has-text("Add Tag")`).click();
250+
await page.locator('[placeholder="Type to select tag"]').click();
251+
await page.locator('[aria-label="Autocomplete Options"] >> text=Driving').click();
252+
await page.waitForSelector('[aria-label="Tag"]:has-text("Driving")');
253+
254+
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').click();
255+
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('Sc');
256+
await expect(page.locator('[aria-label="Search Result"]').first()).toContainText("Science");
257+
await expect(page.locator('[aria-label="Search Result"]').first()).not.toContainText("Driving");
258+
259+
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').click();
260+
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('Xq');
261+
await expect(page.locator('text=No results found')).toBeVisible();
262+
});
224263
});
225264

226265
// Try to reduce indeterminism of browser requests by only returning fetch requests.

e2e/tests/functional/plugins/notebook/tags.e2e.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ test.describe('Tagging in Notebooks @addInit', () => {
116116

117117
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').click();
118118
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('Xq');
119-
await expect(page.locator('[aria-label="Search Result"]')).toBeHidden();
119+
await expect(page.locator('text=No results found')).toBeVisible();
120120
});
121121

122122
test('Can delete tags', async ({ page }) => {

src/api/annotation/AnnotationAPI.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ export default class AnnotationAPI extends EventEmitter {
346346
*/
347347
async searchForTags(query, abortController) {
348348
const matchingTagKeys = this.#getMatchingTags(query);
349+
if (!matchingTagKeys.length) {
350+
return [];
351+
}
352+
349353
const searchResults = (await Promise.all(this.openmct.objects.search(matchingTagKeys, abortController, this.openmct.objects.SEARCH_TYPES.TAGS))).flat();
350354
const filteredDeletedResults = searchResults.filter((result) => {
351355
return !(result._deleted);

src/api/annotation/AnnotationAPISpec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,10 @@ describe("The Annotation API", () => {
185185
expect(results).toBeDefined();
186186
expect(results.length).toEqual(1);
187187
});
188+
it("returns no tags for empty search", async () => {
189+
const results = await openmct.annotation.searchForTags('q');
190+
expect(results).toBeDefined();
191+
expect(results.length).toEqual(0);
192+
});
188193
});
189194
});

src/plugins/persistence/couch/CouchSearchProvider.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class CouchSearchProvider {
9090
}
9191

9292
searchForTags(tagsArray, abortSignal) {
93+
if (!tagsArray || !tagsArray.length) {
94+
return [];
95+
}
96+
9397
const filter = {
9498
"selector": {
9599
"$and": [

src/ui/layout/search/GrandSearchSpec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ describe("GrandSearch", () => {
232232
it("should render an object search result if new object added", async () => {
233233
const composition = openmct.composition.get(mockFolderObject);
234234
composition.add(mockNewObject);
235+
// after adding, need to wait a beat for the folder to be indexed
236+
await Vue.nextTick();
235237
await grandSearchComponent.$children[0].searchEverything('apple');
236238
await Vue.nextTick();
237239
const searchResults = document.querySelectorAll('[aria-label="New Apple Test Folder folder result"]');
@@ -271,6 +273,13 @@ describe("GrandSearch", () => {
271273
expect(annotationResults[1].innerText).toContain('Driving');
272274
});
273275

276+
it("should render no annotation search results if no match", async () => {
277+
await grandSearchComponent.$children[0].searchEverything('Qbert');
278+
await Vue.nextTick();
279+
const annotationResults = document.querySelectorAll('[aria-label="Search Result"]');
280+
expect(annotationResults.length).toBe(0);
281+
});
282+
274283
it("should preview object search results in edit mode if object clicked", async () => {
275284
await grandSearchComponent.$children[0].searchEverything('Folder');
276285
grandSearchComponent._provided.openmct.router.path = [mockDisplayLayout];

0 commit comments

Comments
 (0)