@@ -193,9 +193,93 @@ test.describe('Grand Search', () => {
193
193
await expect ( searchResults ) . toContainText ( folderName ) ;
194
194
} ) ;
195
195
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 =
205
+ request . url ( ) . endsWith ( '_view/object_names' )
206
+ const isHeadRequest = request . method ( ) . toLowerCase ( ) === 'head' ;
207
+
208
+ if ( isObjectNamesRequest && isHeadRequest ) {
209
+ const response = await request . response ( ) ;
210
+ isObjectNamesViewAvailable = response . status ( ) === 200 ;
211
+ }
212
+ } ) ;
213
+
214
+ page . on ( 'request' , async ( request ) => {
215
+ const isObjectNamesRequest =
216
+ request . url ( ) . endsWith ( '_view/object_names' ) ;
217
+ const isPostRequest = request . method ( ) . toLowerCase ( ) === 'post' ;
218
+
219
+ if ( isObjectNamesRequest && isPostRequest ) {
220
+ isObjectNamesUsedForSearch = true ;
221
+ }
222
+ } ) ;
223
+
224
+
225
+ // Full search for object
226
+ await grandSearchInput . pressSequentially ( 'Clock' , { delay : 100 } ) ;
227
+
228
+ // Wait for search to finish
229
+ await waitForSearchCompletion ( page ) ;
230
+
231
+ expect ( isObjectNamesViewAvailable ) . toBe ( true ) ;
232
+ expect ( isObjectNamesUsedForSearch ) . toBe ( true ) ;
233
+
234
+ } ) ;
235
+
236
+ test ( 'fall-back on base index if index not available @couchdb @network' , async ( { page } ) => {
237
+ await page . route ( '**/_view/object_names' , ( route ) => {
238
+ route . fulfill ( {
239
+ status : 404
240
+ } ) ;
241
+ } ) ;
242
+ await createObjectsForSearch ( page ) ;
243
+
244
+ let isObjectNamesViewAvailable = false ;
245
+ let isFindUsedForSearch = false ;
246
+
247
+ page . on ( 'request' , async ( request ) => {
248
+ const isObjectNamesRequest =
249
+ request . url ( ) . endsWith ( '_view/object_names' )
250
+ const isHeadRequest = request . method ( ) . toLowerCase ( ) === 'head' ;
251
+
252
+ if ( isObjectNamesRequest && isHeadRequest ) {
253
+ const response = await request . response ( ) ;
254
+ isObjectNamesViewAvailable = response . status ( ) === 200 ;
255
+ }
256
+ } ) ;
257
+
258
+ page . on ( 'request' , async ( request ) => {
259
+ const isFindRequest =
260
+ request . url ( ) . endsWith ( '_find' ) ;
261
+ const isPostRequest = request . method ( ) . toLowerCase ( ) === 'post' ;
262
+
263
+ if ( isFindRequest && isPostRequest ) {
264
+ isFindUsedForSearch = true ;
265
+ }
266
+ } ) ;
267
+
268
+
269
+ // Full search for object
270
+ await grandSearchInput . pressSequentially ( 'Clock' , { delay : 100 } ) ;
271
+
272
+ // Wait for search to finish
273
+ await waitForSearchCompletion ( page ) ;
274
+ console . info ( `isObjectNamesViewAvailable: ${ isObjectNamesViewAvailable } | isFindUsedForSearch: ${ isFindUsedForSearch } ` ) ;
275
+ expect ( isObjectNamesViewAvailable ) . toBe ( false ) ;
276
+ expect ( isFindUsedForSearch ) . toBe ( true ) ;
277
+ } ) ;
278
+ } )
279
+
196
280
test ( 'Search results are debounced @couchdb @network' , async ( { page } ) => {
197
- //Unfortunately 404s are always logged to the JavaScript console and can't be surpressed
198
- //A 404 is now thrown when we test for the presence of the object names view used by search.
281
+ // Unfortunately 404s are always logged to the JavaScript console and can't be surpressed
282
+ // A 404 is now thrown when we test for the presence of the object names view used by search.
199
283
test . info ( ) . annotations . push ( {
200
284
type : 'issue' ,
201
285
description : 'https://github.com/nasa/openmct/issues/6179'
@@ -209,9 +293,8 @@ test.describe('Grand Search', () => {
209
293
request . url ( ) . endsWith ( 'object_names' ) ||
210
294
request . url ( ) . endsWith ( '_find' ) ||
211
295
request . url ( ) . includes ( 'by_keystring' ) ;
212
-
213
296
const isFetchRequest = request . resourceType ( ) === 'fetch' ;
214
- //CouchDB search results in a one-time head request to test for the presence of an index.
297
+ // CouchDB search results in a one-time head request to test for the presence of an index.
215
298
const isHeadRequest = request . method ( ) . toLowerCase ( ) === 'head' ;
216
299
217
300
if ( isSearchRequest && isFetchRequest && ! isHeadRequest ) {
0 commit comments