Skip to content

Commit 34a2630

Browse files
authored
Enable cypress tests to run datagrid table in Discover (#1074)
* allow switch table * make sure the DatePickerMenu is open * update switchDiscoverTable to accomadate changing from toggle to button * skip saved queries * fixed flaky tests and missing ones --------- Signed-off-by: Anan Zhuang <ananzh@amazon.com>
1 parent b544a74 commit 34a2630

12 files changed

+94
-3
lines changed

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('date_nanos', () => {
3434
});
3535
miscUtils.visitPage('app/data-explorer/discover#/');
3636
cy.waitForLoader();
37+
cy.switchDiscoverTable('new');
3738

3839
cy.setTopNavDate(fromTime, toTime);
3940
cy.waitForSearch();

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos_mixed.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('date_nanos_mixed', () => {
3131
});
3232
miscUtils.visitPage('app/data-explorer/discover#/');
3333
cy.waitForLoader();
34+
cy.switchDiscoverTable('new');
3435

3536
const fromTime = 'Jan 1, 2019 @ 00:00:00.000';
3637
const toTime = 'Jan 1, 2019 @ 23:59:59.999';

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/discover.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('discover app', { scrollBehavior: false }, () => {
6262
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
6363
);
6464
cy.waitForLoader();
65+
cy.switchDiscoverTable('new');
6566
cy.waitForSearch();
6667
});
6768

@@ -70,6 +71,9 @@ describe('discover app', { scrollBehavior: false }, () => {
7071
describe('save search', () => {
7172
const saveSearch1 = 'Save Search # 1';
7273
const saveSearch2 = 'Modified Save Search # 1';
74+
beforeEach(() => {
75+
cy.switchDiscoverTable('new');
76+
});
7377

7478
it('should show correct time range string by timepicker', function () {
7579
cy.verifyTimeConfig(DE_DEFAULT_START_TIME, DE_DEFAULT_END_TIME);
@@ -146,6 +150,7 @@ describe('discover app', { scrollBehavior: false }, () => {
146150
const toTime = 'Jun 12, 1999 @ 11:21:04.000';
147151

148152
before(() => {
153+
cy.switchDiscoverTable('new');
149154
cy.setTopNavDate(fromTime, toTime);
150155
});
151156

@@ -259,6 +264,10 @@ describe('discover app', { scrollBehavior: false }, () => {
259264
});
260265

261266
describe('refresh interval', function () {
267+
beforeEach(() => {
268+
cy.switchDiscoverTable('new');
269+
});
270+
262271
it('should refetch when autofresh is enabled', () => {
263272
cy.getElementByTestId('openInspectorButton').click();
264273
cy.getElementByTestId('inspectorPanel')
@@ -276,12 +285,15 @@ describe('discover app', { scrollBehavior: false }, () => {
276285
.should('be.visible')
277286
.clear()
278287
.type('2');
288+
289+
cy.makeDatePickerMenuOpen();
279290
cy.getElementByTestId('superDatePickerToggleRefreshButton').click();
280291

281292
// Let auto refresh run
282293
cy.wait(100);
283294

284295
// Close the auto refresh
296+
cy.makeDatePickerMenuOpen();
285297
cy.getElementByTestId('superDatePickerToggleRefreshButton').click();
286298

287299
// Check the timestamp of the last request, it should be different than the first timestamp

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_navigation.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('doc link in discover', () => {
4646
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
4747
);
4848
cy.waitForLoader();
49+
cy.switchDiscoverTable('new');
4950
cy.waitForSearch();
5051
});
5152

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_table.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('discover doc table', () => {
4646
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
4747
);
4848
cy.waitForLoader();
49+
cy.switchDiscoverTable('new');
4950
cy.waitForSearch();
5051
});
5152

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/field_data.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,17 @@ describe('discover tab', () => {
4646
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
4747
);
4848
cy.waitForLoader();
49+
cy.switchDiscoverTable('new');
4950
cy.waitForSearch();
5051
});
5152

5253
after(() => {});
5354

5455
describe('field data', function () {
56+
before(() => {
57+
cy.switchDiscoverTable('new');
58+
});
59+
5560
it('search php should show the correct hit count', function () {
5661
const expectedHitCount = '445';
5762
cy.setTopNavQuery('php');
@@ -65,12 +70,18 @@ describe('discover tab', () => {
6570
});
6671

6772
it('search type:apache should show the correct hit count', () => {
73+
// add this line to address flakiness in Cypress:
74+
// ensures stable switching to the new Discover table format.
75+
cy.switchDiscoverTable('new');
6876
const expectedHitCount = '11,156';
6977
cy.setTopNavQuery('type:apache');
7078
cy.verifyHitCount(expectedHitCount);
7179
});
7280

7381
it('doc view should show Time and _source columns', function () {
82+
// add this line to address flakiness in Cypress:
83+
// ensures stable switching to the new Discover table format.
84+
cy.switchDiscoverTable('new');
7485
cy.getElementByTestId('dataGridHeaderCell-@timestamp').should(
7586
'be.visible'
7687
);

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_with_encoded_id.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('index pattern with encoded id', () => {
3636

3737
// Go to the Discover page
3838
miscUtils.visitPage('app/data-explorer/discover#/');
39+
cy.switchDiscoverTable('new');
3940
cy.setTopNavDate(DE_DEFAULT_START_TIME, DE_DEFAULT_END_TIME);
4041
cy.waitForLoader();
4142
});

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_without_field.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('index pattern without field spec', () => {
3333
// Go to the Discover page
3434
miscUtils.visitPage('app/data-explorer/discover#/');
3535
cy.waitForLoader();
36+
cy.switchDiscoverTable('new');
3637
});
3738

3839
after(() => {
@@ -49,6 +50,7 @@ describe('index pattern without field spec', () => {
4950

5051
it('should display a timepicker after switching to an index pattern with timefield', () => {
5152
const indexName = 'with-timefield';
53+
cy.switchDiscoverTable('new');
5254
cy.getElementByTestId('comboBoxToggleListButton')
5355
.should('be.visible')
5456
.click();

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/large_string.spec.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('test large strings', () => {
4444
// Go to the Discover page
4545
miscUtils.visitPage('app/data-explorer/discover#/');
4646
cy.waitForLoader();
47+
cy.switchDiscoverTable('new');
4748

4849
const ExpectedDoc = 'Project Gutenberg EBook of Hamlet';
4950

@@ -56,14 +57,23 @@ describe('test large strings', () => {
5657
});
5758

5859
describe('test large data', function () {
59-
it('search Newsletter should show the correct hit count', function () {
60+
it('search Newsletter should show the correct hit count in legacy table', function () {
6061
cy.log('test Newsletter keyword is searched');
6162
const expectedHitCount = '1';
6263
const query = 'Newsletter';
6364
cy.setTopNavQuery(query);
6465
cy.verifyHitCount(expectedHitCount);
6566
});
6667

68+
it('search Newsletter should show the correct hit count in datagrid table', function () {
69+
cy.log('test Newsletter keyword is searched');
70+
cy.switchDiscoverTable('new');
71+
const expectedHitCount = '1';
72+
const query = 'Newsletter';
73+
cy.setTopNavQuery(query);
74+
cy.verifyHitCount(expectedHitCount);
75+
});
76+
6777
// flaky when looking for the highlighted mark
6878
it.skip('the search term Newsletter should be highlighted in the field data', function () {
6979
cy.log('Newsletter appears only once');

cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/saved_queries.spec.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const indexSet = [
2424
'logstash-2015.09.20',
2525
];
2626

27-
describe('saved queries saved objects', () => {
27+
describe.skip('saved queries saved objects', () => {
2828
const fromTime = 'Sep 20, 2015 @ 08:00:00.000';
2929
const toTime = 'Sep 21, 2015 @ 08:00:00.000';
3030
before(() => {
@@ -50,6 +50,8 @@ describe('saved queries saved objects', () => {
5050

5151
// Go to the Discover page
5252
miscUtils.visitPage('app/data-explorer/discover#/');
53+
cy.waitForLoader();
54+
cy.switchDiscoverTable('new');
5355

5456
// Set time filter
5557
cy.setTopNavDate(fromTime, toTime);
@@ -62,6 +64,10 @@ describe('saved queries saved objects', () => {
6264
});
6365

6466
describe('saved query management component functionality', function () {
67+
beforeEach(() => {
68+
cy.switchDiscoverTable('new');
69+
});
70+
6571
it('should show the saved query management component when there are no saved queries', () => {
6672
cy.getElementByTestId('saved-query-management-popover-button').click();
6773
cy.getElementByTestId('saved-query-management-popover')

cypress/utils/dashboards/data_explorer/commands.js

+43
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,46 @@ Cypress.Commands.add('deleteSaveQuery', (name) => {
133133
});
134134
cy.getElementByTestId('confirmModalConfirmButton').click();
135135
});
136+
137+
Cypress.Commands.add('switchDiscoverTable', (name) => {
138+
cy.getElementByTestId('datagridTableButton')
139+
.then(($button) => {
140+
const buttonText = $button.text();
141+
142+
if (name === 'new' && buttonText.includes('Try new Discover')) {
143+
cy.wrap($button).click();
144+
}
145+
if (name === 'legacy' && buttonText.includes('Use legacy Discover')) {
146+
cy.wrap($button).click();
147+
}
148+
cy.waitForLoader();
149+
})
150+
.then(() => {
151+
checkForElementVisibility();
152+
});
153+
});
154+
155+
Cypress.Commands.add('makeDatePickerMenuOpen', () => {
156+
cy.get(
157+
'[class="euiFormControlLayout euiFormControlLayout--group euiSuperDatePicker"]'
158+
).then(($popover) => {
159+
// Check if the popover does not have the 'euiPopover-isOpen' class
160+
if (!$popover.hasClass('euiPopover-isOpen')) {
161+
// If not open, click the button to open the quick menu
162+
cy.getElementByTestId('superDatePickerToggleQuickMenuButton').click();
163+
}
164+
});
165+
});
166+
167+
function checkForElementVisibility() {
168+
cy.getElementsByTestIds('queryInput')
169+
.should('be.visible')
170+
.then(($element) => {
171+
if ($element.is(':visible')) {
172+
return;
173+
} else {
174+
cy.wait(500); // Wait for half a second before checking again
175+
checkForElementVisibility(); // Recursive call
176+
}
177+
});
178+
}

cypress/utils/dashboards/data_explorer/index.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ declare namespace Cypress {
1515
saveQuery(name: string, description: string): Chainable<any>;
1616
loadSaveQuery(name: string): Chainable<any>;
1717
clearSaveQuery(): Chainable<any>;
18-
deleteSaveQuery(name: string):Chainable<any>;
18+
deleteSaveQuery(name: string): Chainable<any>;
19+
switchDiscoverTable(name: string): Chainable<any>;
20+
makeDatePickerMenuOpen(): Chainable<any>;
1921
}
2022
}

0 commit comments

Comments
 (0)