From 6b79fd27030f24d6c08303619631f4af06a09d78 Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Mon, 25 Sep 2023 16:14:21 +0000 Subject: [PATCH] [Data Explorer][Discover][Function Test] Fix ciGroup4 * add data-render-complete and data-shared-item for test convenience * change docTableFieldCount to dataGridTableCellCount to fetch data grid cell * add methods in data grid service to reuse current massive selenium tests * update tests Issue Resolve https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5098 https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5058 Signed-off-by: Anan Zhuang --- package.json | 2 +- .../components/data_grid/data_grid_table.tsx | 6 ++-- .../search_embeddable_component.tsx | 7 ++++- .../apps/dashboard/dashboard_state.js | 25 +++++++++------- .../apps/dashboard/dashboard_time_picker.js | 5 ++-- test/functional/page_objects/discover_page.ts | 8 ++--- .../services/dashboard/expectations.ts | 6 ++-- test/functional/services/data_grid.ts | 30 +++++++++++++++++++ 8 files changed, 66 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index eb2206dfcf21..9a4aae4dcec6 100644 --- a/package.json +++ b/package.json @@ -466,4 +466,4 @@ "node": ">=14.20.1 <19", "yarn": "^1.22.10" } -} \ No newline at end of file +} diff --git a/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx b/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx index 596e0b97ae07..701b3e296c0f 100644 --- a/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx +++ b/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx @@ -32,6 +32,7 @@ export interface DataGridTableProps { services: DiscoverServices; isToolbarVisible?: boolean; isContextView?: boolean; + isLoading?: boolean; } export const DataGridTable = ({ @@ -47,6 +48,7 @@ export const DataGridTable = ({ displayTimeColumn, isToolbarVisible = true, isContextView = false, + isLoading = false, }: DataGridTableProps) => { const [inspectedHit, setInspectedHit] = useState(); const rowCount = useMemo(() => (rows ? rows.length : 0), [rows]); @@ -166,7 +168,7 @@ export const DataGridTable = ({ indexPattern, }} > - <> +
{table} @@ -183,7 +185,7 @@ export const DataGridTable = ({ onClose={() => setInspectedHit(undefined)} /> )} - +
); }; diff --git a/src/plugins/discover/public/embeddable/search_embeddable_component.tsx b/src/plugins/discover/public/embeddable/search_embeddable_component.tsx index c9a08844e9a0..f019d75db116 100644 --- a/src/plugins/discover/public/embeddable/search_embeddable_component.tsx +++ b/src/plugins/discover/public/embeddable/search_embeddable_component.tsx @@ -42,7 +42,12 @@ export function SearchEmbeddableComponent({ searchProps }: SearchEmbeddableProps return ( - + {discoverEmbeddableProps.totalHitCount !== 0 ? ( diff --git a/test/functional/apps/dashboard/dashboard_state.js b/test/functional/apps/dashboard/dashboard_state.js index ed39d5e42680..edb2002624f5 100644 --- a/test/functional/apps/dashboard/dashboard_state.js +++ b/test/functional/apps/dashboard/dashboard_state.js @@ -90,8 +90,11 @@ export default function ({ getService, getPageObjects }) { expect(colorChoiceRetained).to.be(true); }); - // the following three tests are skipped because of save search save window bug: - // https://github.com/opensearch-project/OpenSearch-Dashboards/issues/4698 + // TODO: Revert the following changes on the following 3 saved search tests + // once issue https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5071 is resolved. + // The issue causes the previously saved object to not load automatically when navigating back to discover from the dashboard. + // Currently, we need to re-open the saved search in discover. + // The expected behavior is for the saved object to persist and load as it did in previous versions of discover. it('Saved search with no changes will update when the saved object changes', async () => { await PageObjects.dashboard.gotoDashboardLandingPage(); @@ -111,11 +114,12 @@ export default function ({ getService, getPageObjects }) { expect(inViewMode).to.be(true); await PageObjects.header.clickDiscover(); - // Add load save search here since discover link won't take it to the save search link for - // the legacy discover plugin + // add load save search here since discover link won't take it to the save search link await PageObjects.discover.loadSavedSearch('my search'); + await PageObjects.timePicker.setHistoricalDataRange(); + await PageObjects.discover.clickFieldListItemAdd('agent'); - await PageObjects.discover.saveSearch('my search'); + await PageObjects.discover.saveSearch('my search', false); await PageObjects.header.waitUntilLoadingHasFinished(); await PageObjects.header.clickDashboard(); @@ -133,9 +137,9 @@ export default function ({ getService, getPageObjects }) { await PageObjects.dashboard.saveDashboard('Has local edits'); await PageObjects.header.clickDiscover(); - // Add load save search here since discover link won't take it to the save search link for - // the legacy discover plugin + // add load save search here since discover link won't take it to the save search link await PageObjects.discover.loadSavedSearch('my search'); + await PageObjects.timePicker.setHistoricalDataRange(); await PageObjects.discover.clickFieldListItemAdd('clientip'); await PageObjects.discover.saveSearch('my search'); await PageObjects.header.waitUntilLoadingHasFinished(); @@ -152,9 +156,10 @@ export default function ({ getService, getPageObjects }) { const currentQuery = await queryBar.getQueryString(); expect(currentQuery).to.equal(''); const currentUrl = await browser.getCurrentUrl(); - const newUrl = currentUrl.replace('query:%27%27', 'query:%27abc12345678910%27'); - // Don't add the timestamp to the url or it will cause a hard refresh and we want to test a - // soft refresh. + + // due to previous re-open saved search, history is changed. + // query is in both _g and _a. We need to change query in _a. + const newUrl = currentUrl.replace(/query:%27%27/g, 'query:%27abc12345678910%27'); await browser.get(newUrl.toString(), false); await PageObjects.header.waitUntilLoadingHasFinished(); diff --git a/test/functional/apps/dashboard/dashboard_time_picker.js b/test/functional/apps/dashboard/dashboard_time_picker.js index 5c97872cdb7e..b1e57fbe8e5e 100644 --- a/test/functional/apps/dashboard/dashboard_time_picker.js +++ b/test/functional/apps/dashboard/dashboard_time_picker.js @@ -67,14 +67,15 @@ export default function ({ getService, getPageObjects }) { name: 'saved search', fields: ['bytes', 'agent'], }); - await dashboardExpect.docTableFieldCount(150); + // Current data grid loads 100 rows per page by default with inspect button and time range + await dashboardExpect.dataGridTableCellCount(400); // Set to time range with no data await PageObjects.timePicker.setAbsoluteRange( 'Jan 1, 2000 @ 00:00:00.000', 'Jan 1, 2000 @ 01:00:00.000' ); - await dashboardExpect.docTableFieldCount(0); + await dashboardExpect.dataGridTableCellCount(0); }); it('Timepicker start, end, interval values are set by url', async () => { diff --git a/test/functional/page_objects/discover_page.ts b/test/functional/page_objects/discover_page.ts index 395980d6c742..aa8635dc8289 100644 --- a/test/functional/page_objects/discover_page.ts +++ b/test/functional/page_objects/discover_page.ts @@ -42,6 +42,7 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider const defaultFindTimeout = config.get('timeouts.find'); const opensearchChart = getService('opensearchChart'); const docTable = getService('docTable'); + const dataGridTable = getService('dataGrid'); /* * This page is left unchanged since some of the other selenium tests, ex. dashboard tests, visualization tests @@ -104,7 +105,7 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider } public async getColumnHeaders() { - return await docTable.getHeaderFields('embeddedSavedSearchDocTable'); + return await dataGridTable.getHeaderFields(); } public async openLoadSavedSearchPanel() { @@ -353,9 +354,8 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider await header.waitUntilLoadingHasFinished(); } - public async removeHeaderColumn(name: string) { - await testSubjects.moveMouseTo(`docTableHeader-${name}`); - await testSubjects.click(`docTableRemoveHeader-${name}`); + public async removeHeaderColumn(columnName: string) { + await dataGridTable.clickRemoveColumn(columnName); } public async openSidebarFieldFilter() { diff --git a/test/functional/services/dashboard/expectations.ts b/test/functional/services/dashboard/expectations.ts index ab6eaed8a9bc..4bdf355eb049 100644 --- a/test/functional/services/dashboard/expectations.ts +++ b/test/functional/services/dashboard/expectations.ts @@ -69,10 +69,10 @@ export function DashboardExpectProvider({ getService, getPageObjects }: FtrProvi }); } - async docTableFieldCount(expectedCount: number) { - log.debug(`DashboardExpect.docTableFieldCount(${expectedCount})`); + async dataGridTableCellCount(expectedCount: number) { + log.debug(`DashboardExpect.dataGridTableCellCount(${expectedCount})`); await retry.try(async () => { - const docTableCells = await testSubjects.findAll('docTableField', findTimeout); + const docTableCells = await testSubjects.findAll('dataGridRowCell', findTimeout); expect(docTableCells.length).to.be(expectedCount); }); } diff --git a/test/functional/services/data_grid.ts b/test/functional/services/data_grid.ts index e5f66fbc67c4..c41733a1481f 100644 --- a/test/functional/services/data_grid.ts +++ b/test/functional/services/data_grid.ts @@ -37,6 +37,7 @@ interface TabbedGridData { export function DataGridProvider({ getService }: FtrProviderContext) { const find = getService('find'); + const testSubjects = getService('testSubjects'); class DataGrid { async getDataGridTableData(): Promise { @@ -66,6 +67,35 @@ export function DataGridProvider({ getService }: FtrProviderContext) { rows, }; } + + /** + * Retrieves the header fields of the data grid. + * + * @returns {Promise} An array containing names of the header fields. + */ + async getHeaderFields(): Promise { + const headerNames = []; + // Locate header cells, ignoring the inspect document button column + const headerCells = await find.allByCssSelector( + '.euiDataGridHeaderCell__button > .euiDataGridHeaderCell__content' + ); + + for (const cell of headerCells) { + const headerName = await cell.getAttribute('textContent'); + headerNames.push(headerName.trim()); + } + return Promise.resolve(headerNames); + } + + /** + * Clicks to remove a specified column from the data grid. + * + * @param {string} columnName - The name of the column to be removed. + */ + async clickRemoveColumn(columnName: string) { + await testSubjects.click(`dataGridHeaderCell-${columnName}`); + await find.clickByButtonText('Remove column'); + } } return new DataGrid();