Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TESTID-116, TESTID-115, TESTID-61 - Tests for Saved Searches in Dashboard #9288

Merged
merged 7 commits into from
Jan 30, 2025
2 changes: 2 additions & 0 deletions changelogs/fragments/9288.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
- Add tests for saved searches in dashboards ([#9288](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9288))
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
DatasetTypes,
INDEX_PATTERN_WITH_TIME,
INDEX_WITH_TIME_1,
INDEX_WITH_TIME_2,
QueryLanguages,
SECONDARY_ENGINE,
START_TIME,
} from '../../../../../utils/constants';
import {
getRandomizedWorkspaceName,
getRandomizedDatasourceName,
setDatePickerDatesAndSearchIfRelevant,
} from '../../../../../utils/apps/query_enhancements/shared';
import {
postRequestSaveSearch,
generateSavedTestConfiguration,
getExpectedHitCount,
loadSavedSearchFromDashboards,
navigateToDashboardAndOpenSavedSearchPanel,
} from '../../../../../utils/apps/query_enhancements/saved';

const workspaceName = getRandomizedWorkspaceName();
const datasourceName = getRandomizedDatasourceName();

export const runSavedSearchTests = () => {
describe('saved search in dashboards', () => {
beforeEach(() => {
// Load test data
cy.setupTestData(
SECONDARY_ENGINE.url,
[
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_1}.mapping.json`,
`cypress/fixtures/query_enhancements/data_logs_2/${INDEX_WITH_TIME_2}.mapping.json`,
],
[
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_1}.data.ndjson`,
`cypress/fixtures/query_enhancements/data_logs_2/${INDEX_WITH_TIME_2}.data.ndjson`,
]
);
// Add data source
cy.addDataSource({
name: datasourceName,
url: SECONDARY_ENGINE.url,
authType: 'no_auth',
});

// Create workspace
cy.deleteWorkspaceByName(workspaceName);
cy.visit('/app/home');
cy.osd.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_PATTERN_WITH_TIME.replace('*', ''),
timefieldName: 'timestamp',
dataSource: datasourceName,
isEnhancement: true,
});
});

afterEach(() => {
cy.deleteWorkspaceByName(workspaceName);
// // TODO: Modify deleteIndex to handle an array of index and remove hard code
cy.deleteDataSourceByName(datasourceName);
cy.deleteIndex(INDEX_WITH_TIME_1);
cy.deleteIndex(INDEX_WITH_TIME_2);
});

it('Load a saved search', () => {
const config = generateSavedTestConfiguration(
INDEX_PATTERN_WITH_TIME,
DatasetTypes.INDEX_PATTERN.name,
QueryLanguages.DQL
);
// using a POST request to create a saved search to load
postRequestSaveSearch(config);

loadSavedSearchFromDashboards(config, workspaceName);

// verify that there are results
cy.getElementByTestId('docTableField').should('be.visible');

const expectedHitCount = getExpectedHitCount(config.datasetType, config.language);
cy.getElementByTestId('osdDocTablePagination').contains(new RegExp(`of ${expectedHitCount}`));
// verify that the proper fields are loaded as well as sorting is working as expected
config.sampleTableData.forEach(([index, value]) => {
cy.getElementByTestId('osdDocTableCellDataField').eq(index).contains(value);
});
});

it('Changing the time range updates the saved search elements in dashboards', () => {
const config = generateSavedTestConfiguration(
INDEX_PATTERN_WITH_TIME,
DatasetTypes.INDEX_PATTERN.name,
QueryLanguages.DQL
);
// using a POST request to create a saved search to load
postRequestSaveSearch(config);

loadSavedSearchFromDashboards(config, workspaceName);

// verify that there are results
const expectedHitCount = getExpectedHitCount(config.datasetType, config.language);
cy.getElementByTestId('osdDocTablePagination').contains(new RegExp(`of ${expectedHitCount}`));

// set a date where there should different number of results
setDatePickerDatesAndSearchIfRelevant(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets change to a valid time range where we have atleast some hits which is different from the expected hits in the config. That will ensure that changing time ranges actually updates the underlying search.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sounds good. i'm a bit concerned though about timezone differences between my env and the CI/CD (or does that matter)? Lets see though, i'll push out a change that works on my end

config.language,
START_TIME,
'Oct 1, 2022 @ 00:00:00.000'
);
cy.getElementByTestId('osdDocTablePagination').contains(/of 15/);
});

it('Show valid saved searches', () => {
const dqlConfig = generateSavedTestConfiguration(
INDEX_PATTERN_WITH_TIME,
DatasetTypes.INDEX_PATTERN.name,
QueryLanguages.DQL
);
const luceneConfig = generateSavedTestConfiguration(
INDEX_PATTERN_WITH_TIME,
DatasetTypes.INDEX_PATTERN.name,
QueryLanguages.Lucene
);
const sqlConfig = generateSavedTestConfiguration(
INDEX_PATTERN_WITH_TIME,
DatasetTypes.INDEX_PATTERN.name,
QueryLanguages.SQL
);
const pplConfig = generateSavedTestConfiguration(
INDEX_PATTERN_WITH_TIME,
DatasetTypes.INDEX_PATTERN.name,
QueryLanguages.PPL
);
// using a POST request to create a saved search to load
postRequestSaveSearch(dqlConfig);
postRequestSaveSearch(luceneConfig);
postRequestSaveSearch(sqlConfig);
postRequestSaveSearch(pplConfig);

navigateToDashboardAndOpenSavedSearchPanel(workspaceName);
cy.getElementByTestId(`savedObjectTitle${dqlConfig.saveName}`).should('exist');
cy.getElementByTestId(`savedObjectTitle${luceneConfig.saveName}`).should('exist');
cy.getElementByTestId(`savedObjectTitle${sqlConfig.saveName}`).should('not.exist');
cy.getElementByTestId(`savedObjectTitle${pplConfig.saveName}`).should('not.exist');
});
});
};

runSavedSearchTests();
30 changes: 30 additions & 0 deletions cypress/utils/apps/query_enhancements/saved.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,33 @@ export const updateSavedSearchAndSaveAndVerify = (
setDatePickerDatesAndSearchIfRelevant(newConfig.language);
verifyDiscoverPageState(newConfig);
};

/**
* Navigates to dashboard page, clicks new dashboard, and open up the saved search panel
* @param {string} workspaceName - name of workspace
*/
export const navigateToDashboardAndOpenSavedSearchPanel = (workspaceName) => {
cy.navigateToWorkSpaceSpecificPage({
workspaceName,
page: 'dashboards',
isEnhancement: true,
});
cy.getElementByTestId('newItemButton').click();
// using DQL as it supports date picker
setDatePickerDatesAndSearchIfRelevant(QueryLanguages.DQL.name);
cy.getElementByTestId('dashboardAddPanelButton').click();
cy.getElementByTestId('savedObjectFinderFilterButton').click();
cy.getElementByTestId('savedObjectFinderFilter-search').click();
};

/**
* Navigates to dashboard page and loads a saved search as a new dashboard
* @param {SavedTestConfig} config - the relevant config for the test case
* @param {string} workspaceName - name of workspace
*/
export const loadSavedSearchFromDashboards = (config, workspaceName) => {
navigateToDashboardAndOpenSavedSearchPanel(workspaceName);
cy.getElementByTestId(`savedObjectTitle${config.saveName}`).click();
cy.getElementByTestId('addObjectToContainerSuccess').should('be.visible');
cy.getElementByTestId('euiFlyoutCloseButton').click();
};
Loading