@@ -31,6 +31,8 @@ import { expect, test } from '../../pluginFixtures.js';
3131test . describe ( 'Grand Search' , ( ) => {
3232 let grandSearchInput ;
3333
34+ test . use ( { ignore404s : [ / _ d e s i g n \/ o b j e c t _ n a m e s \/ _ v i e w \/ o b j e c t _ n a m e s $ / ] } ) ;
35+
3436 test . beforeEach ( async ( { page } ) => {
3537 grandSearchInput = page
3638 . getByLabel ( 'OpenMCT Search' )
@@ -191,19 +193,106 @@ test.describe('Grand Search', () => {
191193 await expect ( searchResults ) . toContainText ( folderName ) ;
192194 } ) ;
193195
196+ test . describe ( 'Search will test for the presence of the object_names index, and' , ( ) => {
197+ test ( 'use index if available @couchdb @network' , async ( { page } ) => {
198+ await createObjectsForSearch ( page ) ;
199+
200+ let isObjectNamesViewAvailable = false ;
201+ let isObjectNamesUsedForSearch = false ;
202+
203+ page . on ( 'request' , async ( request ) => {
204+ const isObjectNamesRequest = request . url ( ) . endsWith ( '_view/object_names' ) ;
205+ const isHeadRequest = request . method ( ) . toLowerCase ( ) === 'head' ;
206+
207+ if ( isObjectNamesRequest && isHeadRequest ) {
208+ const response = await request . response ( ) ;
209+ isObjectNamesViewAvailable = response . status ( ) === 200 ;
210+ }
211+ } ) ;
212+
213+ page . on ( 'request' , ( request ) => {
214+ const isObjectNamesRequest = request . url ( ) . endsWith ( '_view/object_names' ) ;
215+ const isPostRequest = request . method ( ) . toLowerCase ( ) === 'post' ;
216+
217+ if ( isObjectNamesRequest && isPostRequest ) {
218+ isObjectNamesUsedForSearch = true ;
219+ }
220+ } ) ;
221+
222+ // Full search for object
223+ await grandSearchInput . pressSequentially ( 'Clock' , { delay : 100 } ) ;
224+
225+ // Wait for search to finish
226+ await waitForSearchCompletion ( page ) ;
227+
228+ expect ( isObjectNamesViewAvailable ) . toBe ( true ) ;
229+ expect ( isObjectNamesUsedForSearch ) . toBe ( true ) ;
230+ } ) ;
231+
232+ test ( 'fall-back on base index if index not available @couchdb @network' , async ( { page } ) => {
233+ await page . route ( '**/_view/object_names' , ( route ) => {
234+ route . fulfill ( {
235+ status : 404
236+ } ) ;
237+ } ) ;
238+ await createObjectsForSearch ( page ) ;
239+
240+ let isObjectNamesViewAvailable = false ;
241+ let isFindUsedForSearch = false ;
242+
243+ page . on ( 'request' , async ( request ) => {
244+ const isObjectNamesRequest = request . url ( ) . endsWith ( '_view/object_names' ) ;
245+ const isHeadRequest = request . method ( ) . toLowerCase ( ) === 'head' ;
246+
247+ if ( isObjectNamesRequest && isHeadRequest ) {
248+ const response = await request . response ( ) ;
249+ isObjectNamesViewAvailable = response . status ( ) === 200 ;
250+ }
251+ } ) ;
252+
253+ page . on ( 'request' , ( request ) => {
254+ const isFindRequest = request . url ( ) . endsWith ( '_find' ) ;
255+ const isPostRequest = request . method ( ) . toLowerCase ( ) === 'post' ;
256+
257+ if ( isFindRequest && isPostRequest ) {
258+ isFindUsedForSearch = true ;
259+ }
260+ } ) ;
261+
262+ // Full search for object
263+ await grandSearchInput . pressSequentially ( 'Clock' , { delay : 100 } ) ;
264+
265+ // Wait for search to finish
266+ await waitForSearchCompletion ( page ) ;
267+ console . info (
268+ `isObjectNamesViewAvailable: ${ isObjectNamesViewAvailable } | isFindUsedForSearch: ${ isFindUsedForSearch } `
269+ ) ;
270+ expect ( isObjectNamesViewAvailable ) . toBe ( false ) ;
271+ expect ( isFindUsedForSearch ) . toBe ( true ) ;
272+ } ) ;
273+ } ) ;
274+
194275 test ( 'Search results are debounced @couchdb @network' , async ( { page } ) => {
276+ // Unfortunately 404s are always logged to the JavaScript console and can't be suppressed
277+ // A 404 is now thrown when we test for the presence of the object names view used by search.
195278 test . info ( ) . annotations . push ( {
196279 type : 'issue' ,
197280 description : 'https://github.com/nasa/openmct/issues/6179'
198281 } ) ;
199282 await createObjectsForSearch ( page ) ;
200283
201284 let networkRequests = [ ] ;
285+
202286 page . on ( 'request' , ( request ) => {
203- const searchRequest =
204- request . url ( ) . endsWith ( '_find' ) || request . url ( ) . includes ( 'by_keystring' ) ;
205- const fetchRequest = request . resourceType ( ) === 'fetch' ;
206- if ( searchRequest && fetchRequest ) {
287+ const isSearchRequest =
288+ request . url ( ) . endsWith ( 'object_names' ) ||
289+ request . url ( ) . endsWith ( '_find' ) ||
290+ request . url ( ) . includes ( 'by_keystring' ) ;
291+ const isFetchRequest = request . resourceType ( ) === 'fetch' ;
292+ // CouchDB search results in a one-time head request to test for the presence of an index.
293+ const isHeadRequest = request . method ( ) . toLowerCase ( ) === 'head' ;
294+
295+ if ( isSearchRequest && isFetchRequest && ! isHeadRequest ) {
207296 networkRequests . push ( request ) ;
208297 }
209298 } ) ;
0 commit comments