Skip to content

Commit

Permalink
Enable cypress tests to run datagrid table in Discover (#1074)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
ananzh authored Feb 7, 2024
1 parent b544a74 commit 34a2630
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('date_nanos', () => {
});
miscUtils.visitPage('app/data-explorer/discover#/');
cy.waitForLoader();
cy.switchDiscoverTable('new');

cy.setTopNavDate(fromTime, toTime);
cy.waitForSearch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('date_nanos_mixed', () => {
});
miscUtils.visitPage('app/data-explorer/discover#/');
cy.waitForLoader();
cy.switchDiscoverTable('new');

const fromTime = 'Jan 1, 2019 @ 00:00:00.000';
const toTime = 'Jan 1, 2019 @ 23:59:59.999';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('discover app', { scrollBehavior: false }, () => {
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);
cy.waitForLoader();
cy.switchDiscoverTable('new');
cy.waitForSearch();
});

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

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

before(() => {
cy.switchDiscoverTable('new');
cy.setTopNavDate(fromTime, toTime);
});

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

describe('refresh interval', function () {
beforeEach(() => {
cy.switchDiscoverTable('new');
});

it('should refetch when autofresh is enabled', () => {
cy.getElementByTestId('openInspectorButton').click();
cy.getElementByTestId('inspectorPanel')
Expand All @@ -276,12 +285,15 @@ describe('discover app', { scrollBehavior: false }, () => {
.should('be.visible')
.clear()
.type('2');

cy.makeDatePickerMenuOpen();
cy.getElementByTestId('superDatePickerToggleRefreshButton').click();

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

// Close the auto refresh
cy.makeDatePickerMenuOpen();
cy.getElementByTestId('superDatePickerToggleRefreshButton').click();

// Check the timestamp of the last request, it should be different than the first timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('doc link in discover', () => {
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);
cy.waitForLoader();
cy.switchDiscoverTable('new');
cy.waitForSearch();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('discover doc table', () => {
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);
cy.waitForLoader();
cy.switchDiscoverTable('new');
cy.waitForSearch();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ describe('discover tab', () => {
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);
cy.waitForLoader();
cy.switchDiscoverTable('new');
cy.waitForSearch();
});

after(() => {});

describe('field data', function () {
before(() => {
cy.switchDiscoverTable('new');
});

it('search php should show the correct hit count', function () {
const expectedHitCount = '445';
cy.setTopNavQuery('php');
Expand All @@ -65,12 +70,18 @@ describe('discover tab', () => {
});

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

it('doc view should show Time and _source columns', function () {
// add this line to address flakiness in Cypress:
// ensures stable switching to the new Discover table format.
cy.switchDiscoverTable('new');
cy.getElementByTestId('dataGridHeaderCell-@timestamp').should(
'be.visible'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('index pattern with encoded id', () => {

// Go to the Discover page
miscUtils.visitPage('app/data-explorer/discover#/');
cy.switchDiscoverTable('new');
cy.setTopNavDate(DE_DEFAULT_START_TIME, DE_DEFAULT_END_TIME);
cy.waitForLoader();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('index pattern without field spec', () => {
// Go to the Discover page
miscUtils.visitPage('app/data-explorer/discover#/');
cy.waitForLoader();
cy.switchDiscoverTable('new');
});

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

it('should display a timepicker after switching to an index pattern with timefield', () => {
const indexName = 'with-timefield';
cy.switchDiscoverTable('new');
cy.getElementByTestId('comboBoxToggleListButton')
.should('be.visible')
.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('test large strings', () => {
// Go to the Discover page
miscUtils.visitPage('app/data-explorer/discover#/');
cy.waitForLoader();
cy.switchDiscoverTable('new');

const ExpectedDoc = 'Project Gutenberg EBook of Hamlet';

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

describe('test large data', function () {
it('search Newsletter should show the correct hit count', function () {
it('search Newsletter should show the correct hit count in legacy table', function () {
cy.log('test Newsletter keyword is searched');
const expectedHitCount = '1';
const query = 'Newsletter';
cy.setTopNavQuery(query);
cy.verifyHitCount(expectedHitCount);
});

it('search Newsletter should show the correct hit count in datagrid table', function () {
cy.log('test Newsletter keyword is searched');
cy.switchDiscoverTable('new');
const expectedHitCount = '1';
const query = 'Newsletter';
cy.setTopNavQuery(query);
cy.verifyHitCount(expectedHitCount);
});

// flaky when looking for the highlighted mark
it.skip('the search term Newsletter should be highlighted in the field data', function () {
cy.log('Newsletter appears only once');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const indexSet = [
'logstash-2015.09.20',
];

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

// Go to the Discover page
miscUtils.visitPage('app/data-explorer/discover#/');
cy.waitForLoader();
cy.switchDiscoverTable('new');

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

describe('saved query management component functionality', function () {
beforeEach(() => {
cy.switchDiscoverTable('new');
});

it('should show the saved query management component when there are no saved queries', () => {
cy.getElementByTestId('saved-query-management-popover-button').click();
cy.getElementByTestId('saved-query-management-popover')
Expand Down
43 changes: 43 additions & 0 deletions cypress/utils/dashboards/data_explorer/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,46 @@ Cypress.Commands.add('deleteSaveQuery', (name) => {
});
cy.getElementByTestId('confirmModalConfirmButton').click();
});

Cypress.Commands.add('switchDiscoverTable', (name) => {
cy.getElementByTestId('datagridTableButton')
.then(($button) => {
const buttonText = $button.text();

if (name === 'new' && buttonText.includes('Try new Discover')) {
cy.wrap($button).click();
}
if (name === 'legacy' && buttonText.includes('Use legacy Discover')) {
cy.wrap($button).click();
}
cy.waitForLoader();
})
.then(() => {
checkForElementVisibility();
});
});

Cypress.Commands.add('makeDatePickerMenuOpen', () => {
cy.get(
'[class="euiFormControlLayout euiFormControlLayout--group euiSuperDatePicker"]'
).then(($popover) => {
// Check if the popover does not have the 'euiPopover-isOpen' class
if (!$popover.hasClass('euiPopover-isOpen')) {
// If not open, click the button to open the quick menu
cy.getElementByTestId('superDatePickerToggleQuickMenuButton').click();
}
});
});

function checkForElementVisibility() {
cy.getElementsByTestIds('queryInput')
.should('be.visible')
.then(($element) => {
if ($element.is(':visible')) {
return;
} else {
cy.wait(500); // Wait for half a second before checking again
checkForElementVisibility(); // Recursive call
}
});
}
4 changes: 3 additions & 1 deletion cypress/utils/dashboards/data_explorer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ declare namespace Cypress {
saveQuery(name: string, description: string): Chainable<any>;
loadSaveQuery(name: string): Chainable<any>;
clearSaveQuery(): Chainable<any>;
deleteSaveQuery(name: string):Chainable<any>;
deleteSaveQuery(name: string): Chainable<any>;
switchDiscoverTable(name: string): Chainable<any>;
makeDatePickerMenuOpen(): Chainable<any>;
}
}

0 comments on commit 34a2630

Please sign in to comment.