Files
openmct/e2e/tests/functional/search.e2e.spec.js
John Hill 0413e77d8a test(e2e): Major refactor and stabilization of e2e tests (#7581)
* fix: update broken locator

* update eslint package

* first pass of lint fixes

* update package

* change ruleset

* update component tests to match linting rules

* driveby

* start to factor out bad locators

* update gauge component

* update notebook snapshot drop area

* Update plot aria

* add draggable true to tree items

* update package

* driveby to remove dead code

* unneeded

* unneeded

* tells a screenreader that this is a row and a cell

* adds an id for dragondrops

* this should be a button

* first pass at fixing tooltip selectors

* review comments

* Updating more tests

* update to remove expect expect given our use of check functions

* add expand component

* move role around

* update more locators

* force

* new local storage

* remove choochoo steps

* test: do `lint:fix` and also add back accidentally removed code

* test: add back more removed code

* test: remove `unstable` annotation from tests which are not unstable

* test: remove invalid test-- the "new" time conductor doesn't allow for millisecond changes in fixed time

* test: fix unstable gauge test

* test: remove useless asserts-- this was secretly non-functional. now that we've fixed it, it makes no sense and just fails

* test: add back accidentally removed changes

* test: revert changes that break test

* test: more fixes

* Remove all notion of the unstable/stable e2e tests

* test: eviscerate the flake with FACTS and LOGIC

* test: fix anotha one

* lint fixes

* test: no need to wait for save dialog

* test: fix more tests

* lint: fix more warnings

* test: fix anotha one

* test: use `toHaveLength` instead of `.length).toBe()`

* test: stabilize tabs view example imagery test

* fix: more tests be fixed

* test: more `toHaveCount()`s please

* test: revert more accidentally removed fixes

* test: fix selector

* test: fix anotha one

* update lint rules to clean up bad locators in shared fixtures

* update and remove bad appActions

* test: fix some restricted notebook tests

* test: mass find/replace to enforce `toHaveCount()` instead of `.count()).toBe()`

* Remove some bad appActions and update text

* test: fix da tree tests

* test: await not await await

* test: fix upload plan appAction and add a11y

* Updating externalFixtures with best practice locators and add missing appAction framework tests

* test: fix test

* test: fix appAction test for plans

* test: yum yum fix'em up and get rid of some dragon drops

* fix: alas, a `.only()` got my hopes up that i was done fixing tests

* test: add `setTimeConductorMode` test "suite" which covers most TC related appActions

* test: fix arg

* test(couchdb): fix some network tests via expect polling

* Stabalize visual test

* getCanasPixels

* test: stabilize tooltip telemetry table test, better a11y for tooltips

* chore: update to use `docker compose` instead of `docker-compose`

* New rules, new tests, new me

* fix sort order

* test: add `waitForPlotsToRender` framework test, passthru timeout override

* test: remove `clockOptions` test as we have `page.clock` now

* test: refactor out `overrideClock`

* test: use `clock.install` instead

* test: use `clock.install` instead

* time clock fix

* test: fix timer tests

* remove ever reference to old base fixture

* test: stabilize restricted notebook test

* lint fixes

* test: use clock.install

* update timelist

* test: update visual tests to use `page.clock()`, update snapshots

* test: stabilize tree renaming/reordering test

* a11y: add aria-label and role=region to object view

* refactor: use `dragTo`

* refactor: use `dragTo`, other small fixes

* test: use `page.clock()` to stabilize tooltip telemetry table test

* test: use web-first assertion to stabilize staleness test

* test: knock out a few more `page.click`s

* test: destroy all `page.click()`s

* refactor: consistently use `'Ok'` instead of `'OK'` and `'Ok'` mixed

* test: remove gauge aria label

* test: more test fixes

* test: more fixes and refactors

* docs: add comment

* test: refactor all instances of `dragAndDrop`

* test: remove redundant test (covered in previous test steps)

* test: stabilize imagery operations tests for display layout

* chore: remove bad unicorn rule

* chore(lint): remove unused disable directives

---------

Co-authored-by: Jesse Mazzella <jesse.d.mazzella@nasa.gov>
2024-08-07 21:36:14 +00:00

370 lines
13 KiB
JavaScript

/*****************************************************************************
* Open MCT, Copyright (c) 2014-2024, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/**
* This test suite is dedicated to tests which verify search functionalities.
*/
import { v4 as uuid } from 'uuid';
import { createDomainObjectWithDefaults } from '../../appActions.js';
import { expect, test } from '../../pluginFixtures.js';
test.describe('Grand Search', () => {
let grandSearchInput;
test.beforeEach(async ({ page }) => {
grandSearchInput = page
.getByLabel('OpenMCT Search')
.getByRole('searchbox', { name: 'Search Input' });
// Go to baseURL
await page.goto('./', { waitUntil: 'domcontentloaded' });
});
test('Can search for objects, and subsequent search dropdown behaves properly', async ({
page,
openmctConfig
}) => {
const { myItemsFolderName } = openmctConfig;
const createdObjects = await createObjectsForSearch(page);
// Go back into edit mode for the display layout
await page.getByRole('button', { name: 'Edit Object' }).click();
await grandSearchInput.click();
await grandSearchInput.fill('Cl');
await expect(page.getByLabel('Object Search Result').first()).toContainText(
`Clock A ${myItemsFolderName} Red Folder Blue Folder`
);
await expect(page.getByLabel('Object Search Result').nth(1)).toContainText(
`Clock B ${myItemsFolderName} Red Folder Blue Folder`
);
await expect(page.getByLabel('Object Search Result').nth(2)).toContainText(
`Clock C ${myItemsFolderName} Red Folder Blue Folder`
);
await expect(page.getByLabel('Object Search Result').nth(3)).toContainText(
`Clock D ${myItemsFolderName} Red Folder Blue Folder`
);
// Click the Elements pool to dismiss the search menu
await page.getByRole('tab', { name: 'Elements' }).click();
await expect(page.getByLabel('Object Search Result').first()).toBeHidden();
await grandSearchInput.click();
await page.getByLabel('OpenMCT Search').getByText('Clock A').click();
await expect(page.getByRole('dialog', { name: 'Preview Container' })).toBeVisible();
// Close the Preview window
await page.getByRole('button', { name: 'Close' }).click();
await expect(page.getByLabel('Object Search Result').first()).toBeVisible();
await expect(page.getByLabel('Object Search Result').first()).toContainText(
`Clock A ${myItemsFolderName} Red Folder Blue Folder`
);
await page.getByLabel('Object Search Result').first().click();
await expect(page.getByLabel('Object Search Result').first()).toBeHidden();
await grandSearchInput.fill('foo');
await expect(page.getByLabel('Object Search Result').first()).toBeHidden();
// Click text=Snapshot Save and Finish Editing Save and Continue Editing >> button >> nth=1
await page.getByRole('button', { name: 'Save' }).click();
await page.getByRole('listitem', { name: 'Save and Finish Editing' }).click();
// Click [aria-label="OpenMCT Search"] [aria-label="Search Input"]
await grandSearchInput.click();
// Fill [aria-label="OpenMCT Search"] [aria-label="Search Input"]
await grandSearchInput.fill('Cl');
await Promise.all([
page.waitForNavigation(),
page.getByLabel('OpenMCT Search').getByText('Clock A').click()
]);
await expect(page.getByRole('status', { name: 'Clock', exact: true })).toBeVisible();
await grandSearchInput.fill('Disp');
await expect(page.getByLabel('Object Search Result').first()).toContainText(
createdObjects.displayLayout.name
);
await expect(page.getByLabel('Object Search Result').first()).not.toContainText('Folder');
await grandSearchInput.fill('Clock C');
await expect(page.getByLabel('Object Search Result').first()).toContainText(
`Clock C ${myItemsFolderName} Red Folder Blue Folder`
);
await grandSearchInput.fill('Cloc');
await expect(page.getByLabel('Object Search Result').first()).toContainText(
`Clock A ${myItemsFolderName} Red Folder Blue Folder`
);
await expect(page.getByLabel('Object Search Result').nth(1)).toContainText(
`Clock B ${myItemsFolderName} Red Folder Blue Folder`
);
await expect(page.getByLabel('Object Search Result').nth(2)).toContainText(
`Clock C ${myItemsFolderName} Red Folder Blue Folder`
);
await expect(page.getByLabel('Object Search Result').nth(3)).toContainText(
`Clock D ${myItemsFolderName} Red Folder Blue Folder`
);
await grandSearchInput.click();
await grandSearchInput.fill('Sine');
});
test('Clicking on a search result changes the URL even if the same type is already selected', async ({
page
}) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/nasa/openmct/issues/7303'
});
const { sineWaveGeneratorAlpha, sineWaveGeneratorBeta } = await createObjectsForSearch(page);
await grandSearchInput.click();
await grandSearchInput.fill('Sine');
await waitForSearchCompletion(page);
await page.getByLabel('OpenMCT Search').getByText('Sine Wave Generator Alpha').click();
const alphaPattern = new RegExp(sineWaveGeneratorAlpha.url.substring(1));
await expect(page).toHaveURL(alphaPattern);
await grandSearchInput.click();
await page.getByLabel('OpenMCT Search').getByText('Sine Wave Generator Beta').click();
const betaPattern = new RegExp(sineWaveGeneratorBeta.url.substring(1));
await expect(page).toHaveURL(betaPattern);
});
test('Validate empty search result', async ({ page }) => {
// Invalid search for objects
await grandSearchInput.fill('not found');
// Wait for search to complete
await waitForSearchCompletion(page);
// Get the search results
const searchResults = page.getByRole('listitem', { name: 'Object Search Result' });
// Verify that no results are found
await expect(searchResults).toHaveCount(0);
// Verify proper message appears
await expect(page.getByText('No results found')).toBeVisible();
});
test('Validate single object in search result @couchdb', async ({ page }) => {
// Create a folder object
const folderName = uuid();
await createDomainObjectWithDefaults(page, {
type: 'folder',
name: folderName
});
// Full search for object
await grandSearchInput.fill(folderName);
// Wait for search to complete
await waitForSearchCompletion(page);
// Get the search results
const searchResults = page.getByLabel('Object Search Result');
// Verify that one result is found
await expect(searchResults).toBeVisible();
await expect(searchResults).toHaveCount(1);
await expect(searchResults).toContainText(folderName);
});
test('Search results are debounced @couchdb', async ({ page }) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/nasa/openmct/issues/6179'
});
await createObjectsForSearch(page);
let networkRequests = [];
page.on('request', (request) => {
const searchRequest =
request.url().endsWith('_find') || request.url().includes('by_keystring');
const fetchRequest = request.resourceType() === 'fetch';
if (searchRequest && fetchRequest) {
networkRequests.push(request);
}
});
// Full search for object
await grandSearchInput.pressSequentially('Clock', { delay: 100 });
// Wait for search to finish
await waitForSearchCompletion(page);
// Network requests for the composite telemetry with multiple items should be:
// 1. batched request for latest telemetry using the bulk API
await expect.poll(() => networkRequests, { timeout: 10000 }).toHaveLength(1);
await expect(page.getByRole('list', { name: 'Object Results' })).toContainText('Clock A');
});
test('Slowly typing after search debounce will abort requests @couchdb', async ({ page }) => {
let requestWasAborted = false;
await createObjectsForSearch(page);
page.on('requestfailed', (request) => {
// check if the request was aborted
if (request.failure().errorText === 'net::ERR_ABORTED') {
requestWasAborted = true;
}
});
// Intercept and delay request
const delayInMs = 100;
await page.route('**', async (route, request) => {
await new Promise((resolve) => setTimeout(resolve, delayInMs));
route.continue();
});
// Slowly type after search delay
const searchInput = page.getByRole('searchbox', { name: 'Search Input' });
await searchInput.pressSequentially('Clock', { delay: 200 });
await expect(page.getByText('Clock B').first()).toBeVisible();
expect(requestWasAborted).toBe(true);
});
test('Validate multiple objects in search results return partial matches', async ({ page }) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/nasa/openmct/issues/4667'
});
// Create folder objects
const folderName1 = 'e928a26e-e924-4ea0';
const folderName2 = 'e928a26e-e924-4001';
await createDomainObjectWithDefaults(page, {
type: 'Folder',
name: folderName1
});
await createDomainObjectWithDefaults(page, {
type: 'Folder',
name: folderName2
});
// Partial search for objects
await grandSearchInput.fill('e928a26e');
// Wait for search to finish
await waitForSearchCompletion(page);
const searchResultDropDown = page.getByRole('dialog', { name: 'Search Results' });
// Verify that the search result/s correctly match the search query
await expect(searchResultDropDown).toContainText(folderName1);
await expect(searchResultDropDown).toContainText(folderName2);
// Get the search results
const objectSearchResults = page.getByLabel('Object Search Result');
// Verify that two results are found
await expect(objectSearchResults).toHaveCount(2);
});
});
/**
* Wait for search to complete
*
* @param {import('@playwright/test').Page} page
*/
async function waitForSearchCompletion(page) {
// Wait loading spinner to disappear
await expect(
page
.getByRole('list', { name: 'Object Results' })
.or(
page
.getByRole('list', { name: 'Annotation Results' })
.or(page.getByText('No results found'))
)
).toBeVisible();
}
/**
* Creates some domain objects for searching
* @param {import('@playwright/test').Page} page
*/
async function createObjectsForSearch(page) {
const redFolder = await createDomainObjectWithDefaults(page, {
type: 'Folder',
name: 'Red Folder'
});
const blueFolder = await createDomainObjectWithDefaults(page, {
type: 'Folder',
name: 'Blue Folder',
parent: redFolder.uuid
});
const clockA = await createDomainObjectWithDefaults(page, {
type: 'Clock',
name: 'Clock A',
parent: blueFolder.uuid
});
const clockB = await createDomainObjectWithDefaults(page, {
type: 'Clock',
name: 'Clock B',
parent: blueFolder.uuid
});
const clockC = await createDomainObjectWithDefaults(page, {
type: 'Clock',
name: 'Clock C',
parent: blueFolder.uuid
});
const clockD = await createDomainObjectWithDefaults(page, {
type: 'Clock',
name: 'Clock D',
parent: blueFolder.uuid
});
const sineWaveGeneratorAlpha = await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
name: 'Sine Wave Generator Alpha'
});
const sineWaveGeneratorBeta = await createDomainObjectWithDefaults(page, {
type: 'Sine Wave Generator',
name: 'Sine Wave Generator Beta'
});
const displayLayout = await createDomainObjectWithDefaults(page, {
type: 'Display Layout'
});
return {
redFolder,
blueFolder,
clockA,
clockB,
clockC,
clockD,
displayLayout,
sineWaveGeneratorAlpha,
sineWaveGeneratorBeta
};
}