Skip to content

Commit a0b55c1

Browse files
Improve the test utils for Explore/Enhancements (#11138)
* Improve the test utils for Explore Signed-off-by: Suchit Sahoo <suchsah@amazon.com> * Fix Enhancements Test Signed-off-by: Suchit Sahoo <suchsah@amazon.com> * Address bugs in the test Signed-off-by: Suchit Sahoo <suchsah@amazon.com> * Address the Comments Signed-off-by: Suchit Sahoo <suchsah@amazon.com> * Changeset file for PR #11138 created/updated --------- Signed-off-by: Suchit Sahoo <suchsah@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent 775605f commit a0b55c1

File tree

83 files changed

+2802
-1527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2802
-1527
lines changed

changelogs/fragments/11138.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test:
2+
- Improve the Integration Utils ([#11138](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/11138))

cypress/integration/core_opensearch_dashboards/opensearch_dashboards/apps/explore/01/a_check.spec.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { INDEX_WITH_TIME_1 } from '../../../../../../utils/constants';
6+
import { DATASOURCE_NAME } from '../../../../../../utils/constants';
77
import { getRandomizedWorkspaceName } from '../../../../../../utils/apps/explore/shared';
88
import { prepareTestSuite } from '../../../../../../utils/helpers';
99

@@ -12,11 +12,21 @@ const workspaceName = getRandomizedWorkspaceName();
1212
const noIndexPatternTestSuite = () => {
1313
describe('No Index Pattern Check Test', () => {
1414
before(() => {
15-
cy.osd.setupWorkspaceAndDataSourceWithIndices(workspaceName, [INDEX_WITH_TIME_1]);
15+
cy.osd.setupEnvAndGetDataSource(DATASOURCE_NAME);
16+
17+
cy.get('@DATASOURCE_ID').then((datasourceId) => {
18+
cy.osd.createWorkspaceWithDataSourceId(
19+
datasourceId,
20+
workspaceName,
21+
['use-case-observability'],
22+
`${workspaceName}:WORKSPACE_ID`
23+
);
24+
cy.wait(2000);
25+
});
1626
});
1727

1828
after(() => {
19-
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspaceName, [INDEX_WITH_TIME_1]);
29+
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspaceName);
2030
});
2131

2232
describe('empty state', () => {

cypress/integration/core_opensearch_dashboards/opensearch_dashboards/apps/explore/01/ai_editor.spec.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,45 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import {
7-
INDEX_WITH_TIME_1,
8-
INDEX_WITH_TIME_2,
9-
DATASOURCE_NAME,
10-
INDEX_PATTERN_WITH_TIME,
11-
} from '../../../../../../utils/constants';
6+
import { DATASOURCE_NAME, INDEX_PATTERN_WITH_TIME } from '../../../../../../utils/constants';
127
import {
138
generateAllTestConfigurations,
149
generateBaseConfiguration,
1510
getRandomizedWorkspaceName,
11+
getRandomizedDatasetId,
1612
setDatePickerDatesIfRelevant,
1713
} from '../../../../../../utils/apps/explore/shared';
18-
import { prepareTestSuite } from '../../../../../../utils/helpers';
14+
import {
15+
prepareTestSuite,
16+
createWorkspaceAndDatasetUsingEndpoint,
17+
} from '../../../../../../utils/helpers';
1918
import { DatasetTypes } from '../../../../../../utils/apps/explore/constants';
2019

2120
const workspaceName = getRandomizedWorkspaceName();
21+
const datasetId = getRandomizedDatasetId();
2222

2323
const runAiEditorTests = () => {
2424
const generatedQuery = 'source=data_logs_small_time_* | where bytes_transferred > 9000';
2525

2626
describe('AI Editor', () => {
2727
before(() => {
28-
cy.osd.setupWorkspaceAndDataSourceWithIndices(workspaceName, [
29-
INDEX_WITH_TIME_1,
30-
INDEX_WITH_TIME_2,
31-
]);
32-
cy.explore.createWorkspaceDataSets({
33-
workspaceName: workspaceName,
34-
indexPattern: INDEX_PATTERN_WITH_TIME.replace('*', ''),
35-
timefieldName: 'timestamp',
36-
dataSource: DATASOURCE_NAME,
37-
isEnhancement: true,
38-
});
28+
cy.osd.setupEnvAndGetDataSource(DATASOURCE_NAME);
29+
30+
// Create workspace and dataset using our new helper function
31+
createWorkspaceAndDatasetUsingEndpoint(
32+
DATASOURCE_NAME,
33+
workspaceName,
34+
datasetId,
35+
INDEX_PATTERN_WITH_TIME, // Uses 'data_logs_small_time_*'
36+
'timestamp', // timestampField
37+
'logs', // signalType
38+
['use-case-observability'] // features
39+
);
3940
});
4041

4142
after(() => {
42-
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspaceName, [
43-
INDEX_WITH_TIME_1,
44-
INDEX_WITH_TIME_2,
45-
]);
43+
// Cleanup workspace and associated resources
44+
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspaceName);
4645
});
4746

4847
beforeEach(() => {
@@ -110,6 +109,7 @@ const runAiEditorTests = () => {
110109
setDatePickerDatesIfRelevant(config.language.name);
111110
// fire query so that we have data to add filter on
112111
cy.explore.updateTopNav({ log: false });
112+
113113
cy.getElementByTestId('exploreTabs').should('exist');
114114

115115
cy.explore.setQueryEditor(' ');

cypress/integration/core_opensearch_dashboards/opensearch_dashboards/apps/explore/01/queries.spec.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,32 @@ import {
1313
getRandomizedWorkspaceName,
1414
generateAllTestConfigurations,
1515
generateBaseConfiguration,
16+
getRandomizedDatasetId,
1617
} from '../../../../../../utils/apps/explore/shared';
17-
import { prepareTestSuite } from '../../../../../../utils/helpers';
18+
import {
19+
prepareTestSuite,
20+
createWorkspaceAndDatasetUsingEndpoint,
21+
} from '../../../../../../utils/helpers';
1822
import { verifyDiscoverPageState } from '../../../../../../utils/apps/explore/saved';
1923

2024
const workspace = getRandomizedWorkspaceName();
25+
const datasetId = getRandomizedDatasetId();
2126

2227
const queriesTestSuite = () => {
2328
describe('query enhancement queries', { scrollBehavior: false }, () => {
2429
before(() => {
25-
cy.osd.setupWorkspaceAndDataSourceWithIndices(workspace, [INDEX_WITH_TIME_1]);
26-
// Create and select index pattern for ${INDEX_WITH_TIME_1}*
27-
cy.explore.createWorkspaceDataSets({
28-
workspaceName: workspace,
29-
indexPattern: INDEX_WITH_TIME_1,
30-
timefieldName: 'timestamp',
31-
indexPatternHasTimefield: true,
32-
dataSource: DATASOURCE_NAME,
33-
isEnhancement: true,
34-
});
30+
cy.osd.setupEnvAndGetDataSource(DATASOURCE_NAME);
31+
32+
// Create workspace and dataset using our new helper function
33+
createWorkspaceAndDatasetUsingEndpoint(
34+
DATASOURCE_NAME,
35+
workspace,
36+
datasetId,
37+
`${INDEX_WITH_TIME_1}*`,
38+
'timestamp', // timestampField
39+
'logs', // signalType
40+
['use-case-observability'] // features
41+
);
3542
});
3643

3744
beforeEach(() => {
@@ -44,6 +51,7 @@ const queriesTestSuite = () => {
4451
});
4552

4653
after(() => {
54+
// Cleanup workspace and associated resources
4755
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspace, [INDEX_WITH_TIME_1]);
4856
});
4957

@@ -59,35 +67,22 @@ const queriesTestSuite = () => {
5967
// Default PPL query should be set
6068
cy.osd.waitForLoader(true);
6169

62-
// Use the more robust verifyDiscoverPageState function to check editor content
63-
// This handles Monaco editor's special whitespace characters better
64-
verifyDiscoverPageState({
65-
dataset: config.dataset,
66-
queryString: '',
67-
language: 'PPL',
68-
hitCount: '10,000',
69-
});
70-
cy.getElementByTestId(`discoverQueryElapsedMs`).should('be.visible');
71-
cy.osd.verifyResultsCount(10000);
70+
const emptyQuery = ' ';
71+
72+
cy.explore.setQueryEditor(emptyQuery);
7273

73-
// Query should persist across refresh
74-
cy.reload();
75-
cy.osd.waitForLoader(true);
76-
// Wait for dataset to be fully loaded after reload
77-
cy.getElementByTestId('datasetSelectButton', { timeout: 30000 })
78-
.should('be.visible')
79-
.should('not.be.disabled');
80-
// Wait for page to fully stabilize and query to execute
8174
cy.osd.waitForLoader(true);
82-
cy.getElementByTestId(`discoverQueryElapsedMs`, { timeout: 30000 }).should('be.visible');
8375

84-
// Verify the state again after reload
76+
// Use the more robust verifyDiscoverPageState function to check editor content
77+
// This handles Monaco editor's special whitespace characters better
8578
verifyDiscoverPageState({
8679
dataset: config.dataset,
8780
queryString: '',
8881
language: 'PPL',
8982
hitCount: '10,000',
9083
});
84+
cy.getElementByTestId(`discoverQueryElapsedMs`, { timeout: 60000 }).should('be.visible'); // Requires more time
85+
cy.osd.verifyResultsCount(10000);
9186
});
9287

9388
it(`with PPL query not starting with source for ${config.testName}`, () => {
@@ -154,8 +149,7 @@ const queriesTestSuite = () => {
154149
cy.get('button[role="tab"]').contains('Logs').click();
155150
cy.get('button[role="tab"][aria-selected="true"]').contains('Logs').should('be.visible');
156151

157-
// Change date range to trigger query re-execution (use valid range)
158-
cy.explore.setTopNavDate('Jan 1, 2020 @ 00:00:00.000', 'Jan 2, 2020 @ 00:00:00.000');
152+
cy.explore.setTopNavDate(START_TIME, START_TIME);
159153

160154
cy.getElementByTestId('exploreQueryExecutionButton').click();
161155
cy.osd.waitForLoader(true);

cypress/integration/core_opensearch_dashboards/opensearch_dashboards/apps/explore/01/saved_explore.spec.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,38 @@
55

66
import {
77
INDEX_PATTERN_WITH_TIME,
8-
INDEX_WITH_TIME_1,
9-
INDEX_WITH_TIME_2,
108
DATASOURCE_NAME,
119
END_TIME,
1210
START_TIME,
1311
} from '../../../../../../utils/apps/explore/constants';
14-
import { getRandomizedWorkspaceName } from '../../../../../../utils/apps/explore/shared';
15-
import { prepareTestSuite } from '../../../../../../utils/helpers';
12+
import {
13+
getRandomizedWorkspaceName,
14+
getRandomizedDatasetId,
15+
} from '../../../../../../utils/apps/explore/shared';
16+
import {
17+
prepareTestSuite,
18+
createWorkspaceAndDatasetUsingEndpoint,
19+
} from '../../../../../../utils/helpers';
1620
import { verifyMonacoEditorContent } from '../../../../../../utils/apps/explore/autocomplete';
1721

1822
const workspaceName = getRandomizedWorkspaceName();
23+
const datasetId = getRandomizedDatasetId();
1924

2025
const runSavedExploreTests = () => {
2126
describe('saved explore', () => {
2227
before(() => {
23-
cy.osd.setupWorkspaceAndDataSourceWithIndices(workspaceName, [
24-
INDEX_WITH_TIME_1,
25-
INDEX_WITH_TIME_2,
26-
]);
27-
cy.explore.createWorkspaceDataSets({
28-
workspaceName: workspaceName,
29-
indexPattern: INDEX_PATTERN_WITH_TIME.replace('*', ''),
30-
timefieldName: 'timestamp',
31-
dataSource: DATASOURCE_NAME,
32-
isEnhancement: true,
33-
});
28+
cy.osd.setupEnvAndGetDataSource(DATASOURCE_NAME);
29+
30+
createWorkspaceAndDatasetUsingEndpoint(
31+
DATASOURCE_NAME,
32+
workspaceName,
33+
datasetId,
34+
INDEX_PATTERN_WITH_TIME,
35+
'timestamp', // timestampField
36+
'logs', // signalType
37+
['use-case-observability'] // features
38+
);
39+
3440
cy.osd.navigateToWorkSpaceSpecificPage({
3541
workspaceName: workspaceName,
3642
page: 'explore/logs',
@@ -44,10 +50,7 @@ const runSavedExploreTests = () => {
4450
});
4551

4652
after(() => {
47-
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspaceName, [
48-
INDEX_WITH_TIME_1,
49-
INDEX_WITH_TIME_2,
50-
]);
53+
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspaceName);
5154
});
5255

5356
beforeEach(() => {

cypress/integration/core_opensearch_dashboards/opensearch_dashboards/apps/explore/01/saved_search.spec.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,41 @@ import { INDEX_WITH_TIME_1, DATASOURCE_NAME } from '../../../../../../utils/cons
77
import {
88
generateAllTestConfigurations,
99
getRandomizedWorkspaceName,
10+
getRandomizedDatasetId,
1011
} from '../../../../../../utils/apps/query_enhancements/shared';
1112
import {
1213
generateSavedTestConfiguration,
1314
postRequestSaveSearch,
1415
} from '../../../../../../utils/apps/query_enhancements/saved';
15-
import { prepareTestSuite } from '../../../../../../utils/helpers';
16+
import {
17+
prepareTestSuite,
18+
createWorkspaceAndDatasetUsingEndpoint,
19+
} from '../../../../../../utils/helpers';
1620
import { QueryLanguages } from '../../../../../../utils/apps/explore/constants';
1721
import { verifyMonacoEditorContent } from '../../../../../../utils/apps/query_enhancements/autocomplete';
1822

1923
const workspaceName = getRandomizedWorkspaceName();
24+
const datasetId = getRandomizedDatasetId();
2025

2126
const runSavedSearchTests = () => {
2227
describe('saved search', () => {
2328
before(() => {
24-
cy.osd.setupWorkspaceAndDataSourceWithIndices(workspaceName, [INDEX_WITH_TIME_1]);
25-
cy.explore.createWorkspaceDataSets({
26-
workspaceName: workspaceName,
27-
indexPattern: INDEX_WITH_TIME_1,
28-
timefieldName: 'timestamp',
29-
dataSource: DATASOURCE_NAME,
30-
isEnhancement: true,
31-
});
32-
// Extarct the workspace id from URl
33-
cy.url().then((url) => {
34-
const workspaceId = url.match(/\/w\/([^\/]+)\//)[1];
35-
cy.wrap(workspaceId).as('workspaceId');
36-
});
29+
cy.osd.setupEnvAndGetDataSource(DATASOURCE_NAME);
30+
31+
// Create workspace and dataset using our new helper function
32+
createWorkspaceAndDatasetUsingEndpoint(
33+
DATASOURCE_NAME,
34+
workspaceName,
35+
datasetId,
36+
`${INDEX_WITH_TIME_1}*`, // Create index pattern from base index
37+
'timestamp', // timestampField
38+
'logs', // signalType
39+
['use-case-observability'] // features
40+
);
3741
});
3842

3943
after(() => {
44+
// Cleanup workspace and associated resources
4045
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspaceName, [INDEX_WITH_TIME_1]);
4146
});
4247

@@ -51,15 +56,17 @@ const runSavedSearchTests = () => {
5156
}).forEach((config) => {
5257
it(`should redirect to older discover page when we load an older saved search ${config.testName}`, () => {
5358
// Use workspace id to navigate to discover page
54-
cy.get('@workspaceId').then((workspaceId) => {
55-
cy.visit(`/w/${workspaceId}/app/data-explorer/discover`);
59+
cy.osd.navigateToWorkSpaceSpecificPage({
60+
workspaceName,
61+
page: 'data-explorer/discover',
62+
isEnhancement: true,
5663
});
5764

58-
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
65+
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType, true);
5966
cy.osd.grabIdsFromDiscoverPageUrl();
6067

6168
// using a POST request to create a saved search to load
62-
postRequestSaveSearch(config);
69+
postRequestSaveSearch(config, workspaceName);
6370

6471
// Navigating to explore page
6572
cy.osd.navigateToWorkSpaceSpecificPage({

0 commit comments

Comments
 (0)