From 465e1896e13fee11a56d3e487e43113d782346d5 Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Fri, 18 Apr 2025 14:38:56 -0700 Subject: [PATCH] Renamed variable for clarity --- e2e/baseFixtures.js | 4 +- e2e/tests/functional/search.e2e.spec.js | 91 +++++++++++++++++++- src/api/composition/CompositionCollection.js | 10 +-- 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/e2e/baseFixtures.js b/e2e/baseFixtures.js index 5d9644f18c..84c762ca5f 100644 --- a/e2e/baseFixtures.js +++ b/e2e/baseFixtures.js @@ -119,7 +119,7 @@ const extendedTest = test.extend({ messages = messages.filter(msg => { let keep = true; - if (msg.text().match(/404 \(Object Not Found\)/) !== null) { + if (msg.text().match(/404 \((Object )?Not Found\)/) !== null) { keep = ignore404s.every(ignoreRule => { return msg.location().url.match(ignoreRule) === null; }); @@ -131,7 +131,7 @@ const extendedTest = test.extend({ // Assert against console errors during teardown if (failOnConsoleError) { - messages.forEach(async (msg) => { + messages.forEach((msg) => { // eslint-disable-next-line playwright/no-standalone-expect expect .soft(msg.type(), `Console error detected: ${_consoleMessageToString(msg)}`) diff --git a/e2e/tests/functional/search.e2e.spec.js b/e2e/tests/functional/search.e2e.spec.js index c81745b89f..09bd797255 100644 --- a/e2e/tests/functional/search.e2e.spec.js +++ b/e2e/tests/functional/search.e2e.spec.js @@ -193,9 +193,93 @@ test.describe('Grand Search', () => { await expect(searchResults).toContainText(folderName); }); + test.describe('Search will test for the presence of the object_names index, and', () => { + test('use index if available @couchdb @network', async ({ page }) => { + await createObjectsForSearch(page); + + let isObjectNamesViewAvailable = false; + let isObjectNamesUsedForSearch = false; + + page.on('request', async (request) => { + const isObjectNamesRequest = + request.url().endsWith('_view/object_names') + const isHeadRequest = request.method().toLowerCase() === 'head'; + + if (isObjectNamesRequest && isHeadRequest) { + const response = await request.response(); + isObjectNamesViewAvailable = response.status() === 200; + } + }); + + page.on('request', async (request) => { + const isObjectNamesRequest = + request.url().endsWith('_view/object_names'); + const isPostRequest = request.method().toLowerCase() === 'post'; + + if (isObjectNamesRequest && isPostRequest) { + isObjectNamesUsedForSearch = true; + } + }); + + + // Full search for object + await grandSearchInput.pressSequentially('Clock', { delay: 100 }); + + // Wait for search to finish + await waitForSearchCompletion(page); + + expect(isObjectNamesViewAvailable).toBe(true); + expect(isObjectNamesUsedForSearch).toBe(true); + + }); + + test('fall-back on base index if index not available @couchdb @network', async ({ page }) => { + await page.route('**/_view/object_names', (route) => { + route.fulfill({ + status: 404 + }); + }); + await createObjectsForSearch(page); + + let isObjectNamesViewAvailable = false; + let isFindUsedForSearch = false; + + page.on('request', async (request) => { + const isObjectNamesRequest = + request.url().endsWith('_view/object_names') + const isHeadRequest = request.method().toLowerCase() === 'head'; + + if (isObjectNamesRequest && isHeadRequest) { + const response = await request.response(); + isObjectNamesViewAvailable = response.status() === 200; + } + }); + + page.on('request', async (request) => { + const isFindRequest = + request.url().endsWith('_find'); + const isPostRequest = request.method().toLowerCase() === 'post'; + + if (isFindRequest && isPostRequest) { + isFindUsedForSearch = true; + } + }); + + + // Full search for object + await grandSearchInput.pressSequentially('Clock', { delay: 100 }); + + // Wait for search to finish + await waitForSearchCompletion(page); + console.info(`isObjectNamesViewAvailable: ${isObjectNamesViewAvailable} | isFindUsedForSearch: ${isFindUsedForSearch}`); + expect(isObjectNamesViewAvailable).toBe(false); + expect(isFindUsedForSearch).toBe(true); + }); + }) + test('Search results are debounced @couchdb @network', async ({ page }) => { - //Unfortunately 404s are always logged to the JavaScript console and can't be surpressed - //A 404 is now thrown when we test for the presence of the object names view used by search. + // Unfortunately 404s are always logged to the JavaScript console and can't be surpressed + // A 404 is now thrown when we test for the presence of the object names view used by search. test.info().annotations.push({ type: 'issue', description: 'https://github.com/nasa/openmct/issues/6179' @@ -209,9 +293,8 @@ test.describe('Grand Search', () => { request.url().endsWith('object_names') || request.url().endsWith('_find') || request.url().includes('by_keystring'); - const isFetchRequest = request.resourceType() === 'fetch'; - //CouchDB search results in a one-time head request to test for the presence of an index. + // CouchDB search results in a one-time head request to test for the presence of an index. const isHeadRequest = request.method().toLowerCase() === 'head'; if (isSearchRequest && isFetchRequest && !isHeadRequest) { diff --git a/src/api/composition/CompositionCollection.js b/src/api/composition/CompositionCollection.js index 77d869c947..3a32b1fd33 100644 --- a/src/api/composition/CompositionCollection.js +++ b/src/api/composition/CompositionCollection.js @@ -211,15 +211,15 @@ export default class CompositionCollection { this.#cleanUpMutables(); const children = await this.#provider.load(this.domainObject); const childObjects = await Promise.all( - children.map((c) => { - if (isIdentifier(c)) { - return this.#publicAPI.objects.get(c, abortSignal); + children.map((child) => { + if (isIdentifier(child)) { + return this.#publicAPI.objects.get(child, abortSignal); } else { - return Promise.resolve(c); + return Promise.resolve(child); } }) ); - childObjects.forEach((c) => this.add(c, true)); + childObjects.forEach((child) => this.add(child, true)); this.#emit('load'); return childObjects;