diff options
author | Scott Bell <scott@traclabs.com> | 2022-10-07 01:33:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-07 01:33:51 +0300 |
commit | db495ea12ecc4f77bd651d655ccb062b5eef5e14 (patch) | |
tree | 85e6566afa21c0fb84cb1958d8490764674d1394 | |
parent | 9022d5d85989dbd5cdd6e508d7c382f12807cfef (diff) |
If no matching tags, do not attempt tag search (#5839)v2.1.1release/2.1.1
* 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 <akhenry@gmail.com>
-rw-r--r-- | e2e/tests/functional/plugins/notebook/notebookWithCouchDB.e2e.spec.js | 41 | ||||
-rw-r--r-- | e2e/tests/functional/plugins/notebook/tags.e2e.spec.js | 2 | ||||
-rw-r--r-- | src/api/annotation/AnnotationAPI.js | 4 | ||||
-rw-r--r-- | src/api/annotation/AnnotationAPISpec.js | 5 | ||||
-rw-r--r-- | src/plugins/persistence/couch/CouchSearchProvider.js | 4 | ||||
-rw-r--r-- | src/ui/layout/search/GrandSearchSpec.js | 9 |
6 files changed, 63 insertions, 2 deletions
diff --git a/e2e/tests/functional/plugins/notebook/notebookWithCouchDB.e2e.spec.js b/e2e/tests/functional/plugins/notebook/notebookWithCouchDB.e2e.spec.js index 4edb1ff28..97f5ab3c6 100644 --- a/e2e/tests/functional/plugins/notebook/notebookWithCouchDB.e2e.spec.js +++ b/e2e/tests/functional/plugins/notebook/notebookWithCouchDB.e2e.spec.js @@ -27,7 +27,7 @@ This test suite is dedicated to tests which verify the basic operations surround const { test, expect } = require('../../../../baseFixtures'); const { createDomainObjectWithDefaults } = require('../../../../appActions'); -test.describe('Notebook Network Request Inspection @couchdb', () => { +test.describe('Notebook Tests with CouchDB @couchdb', () => { let testNotebook; test.beforeEach(async ({ page }) => { //Navigate to baseURL @@ -221,6 +221,45 @@ test.describe('Notebook Network Request Inspection @couchdb', () => { expect(filterNonFetchRequests(addingNotebookElementsRequests).length).toBeLessThanOrEqual(4); }); + + test('Search tests', async ({ page }) => { + test.info().annotations.push({ + type: 'issue', + description: 'https://github.com/akhenry/openmct-yamcs/issues/69' + }); + await page.locator('text=To start a new entry, click here or drag and drop any object').click(); + await page.locator('[aria-label="Notebook Entry Input"]').click(); + await page.locator('[aria-label="Notebook Entry Input"]').fill(`First Entry`); + await page.locator('[aria-label="Notebook Entry Input"]').press('Enter'); + + // Add three tags + await page.hover(`button:has-text("Add Tag")`); + await page.locator(`button:has-text("Add Tag")`).click(); + await page.locator('[placeholder="Type to select tag"]').click(); + await page.locator('[aria-label="Autocomplete Options"] >> text=Science').click(); + await page.waitForSelector('[aria-label="Tag"]:has-text("Science")'); + + await page.hover(`button:has-text("Add Tag")`); + await page.locator(`button:has-text("Add Tag")`).click(); + await page.locator('[placeholder="Type to select tag"]').click(); + await page.locator('[aria-label="Autocomplete Options"] >> text=Drilling').click(); + await page.waitForSelector('[aria-label="Tag"]:has-text("Drilling")'); + + await page.hover(`button:has-text("Add Tag")`); + await page.locator(`button:has-text("Add Tag")`).click(); + await page.locator('[placeholder="Type to select tag"]').click(); + await page.locator('[aria-label="Autocomplete Options"] >> text=Driving').click(); + await page.waitForSelector('[aria-label="Tag"]:has-text("Driving")'); + + await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').click(); + await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('Sc'); + await expect(page.locator('[aria-label="Search Result"]').first()).toContainText("Science"); + await expect(page.locator('[aria-label="Search Result"]').first()).not.toContainText("Driving"); + + await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').click(); + await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('Xq'); + await expect(page.locator('text=No results found')).toBeVisible(); + }); }); // Try to reduce indeterminism of browser requests by only returning fetch requests. diff --git a/e2e/tests/functional/plugins/notebook/tags.e2e.spec.js b/e2e/tests/functional/plugins/notebook/tags.e2e.spec.js index 498f196c9..792117b3e 100644 --- a/e2e/tests/functional/plugins/notebook/tags.e2e.spec.js +++ b/e2e/tests/functional/plugins/notebook/tags.e2e.spec.js @@ -116,7 +116,7 @@ test.describe('Tagging in Notebooks @addInit', () => { await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').click(); await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('Xq'); - await expect(page.locator('[aria-label="Search Result"]')).toBeHidden(); + await expect(page.locator('text=No results found')).toBeVisible(); }); test('Can delete tags', async ({ page }) => { diff --git a/src/api/annotation/AnnotationAPI.js b/src/api/annotation/AnnotationAPI.js index 148b1d3c4..618d6f874 100644 --- a/src/api/annotation/AnnotationAPI.js +++ b/src/api/annotation/AnnotationAPI.js @@ -346,6 +346,10 @@ export default class AnnotationAPI extends EventEmitter { */ async searchForTags(query, abortController) { const matchingTagKeys = this.#getMatchingTags(query); + if (!matchingTagKeys.length) { + return []; + } + const searchResults = (await Promise.all(this.openmct.objects.search(matchingTagKeys, abortController, this.openmct.objects.SEARCH_TYPES.TAGS))).flat(); const filteredDeletedResults = searchResults.filter((result) => { return !(result._deleted); diff --git a/src/api/annotation/AnnotationAPISpec.js b/src/api/annotation/AnnotationAPISpec.js index a7e2a162d..cc362d8a1 100644 --- a/src/api/annotation/AnnotationAPISpec.js +++ b/src/api/annotation/AnnotationAPISpec.js @@ -185,5 +185,10 @@ describe("The Annotation API", () => { expect(results).toBeDefined(); expect(results.length).toEqual(1); }); + it("returns no tags for empty search", async () => { + const results = await openmct.annotation.searchForTags('q'); + expect(results).toBeDefined(); + expect(results.length).toEqual(0); + }); }); }); diff --git a/src/plugins/persistence/couch/CouchSearchProvider.js b/src/plugins/persistence/couch/CouchSearchProvider.js index 5d9ef5e4f..d89d13050 100644 --- a/src/plugins/persistence/couch/CouchSearchProvider.js +++ b/src/plugins/persistence/couch/CouchSearchProvider.js @@ -90,6 +90,10 @@ class CouchSearchProvider { } searchForTags(tagsArray, abortSignal) { + if (!tagsArray || !tagsArray.length) { + return []; + } + const filter = { "selector": { "$and": [ diff --git a/src/ui/layout/search/GrandSearchSpec.js b/src/ui/layout/search/GrandSearchSpec.js index 5235fc2b3..a4b84515a 100644 --- a/src/ui/layout/search/GrandSearchSpec.js +++ b/src/ui/layout/search/GrandSearchSpec.js @@ -232,6 +232,8 @@ describe("GrandSearch", () => { it("should render an object search result if new object added", async () => { const composition = openmct.composition.get(mockFolderObject); composition.add(mockNewObject); + // after adding, need to wait a beat for the folder to be indexed + await Vue.nextTick(); await grandSearchComponent.$children[0].searchEverything('apple'); await Vue.nextTick(); const searchResults = document.querySelectorAll('[aria-label="New Apple Test Folder folder result"]'); @@ -271,6 +273,13 @@ describe("GrandSearch", () => { expect(annotationResults[1].innerText).toContain('Driving'); }); + it("should render no annotation search results if no match", async () => { + await grandSearchComponent.$children[0].searchEverything('Qbert'); + await Vue.nextTick(); + const annotationResults = document.querySelectorAll('[aria-label="Search Result"]'); + expect(annotationResults.length).toBe(0); + }); + it("should preview object search results in edit mode if object clicked", async () => { await grandSearchComponent.$children[0].searchEverything('Folder'); grandSearchComponent._provided.openmct.router.path = [mockDisplayLayout]; |