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

refactor some query-enhancement utility functions, add some missing typings #9074

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/9074.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
- Query-enhancements testing utility updates and additions ([#9074](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9074))
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('No Index Pattern Check Test', () => {
describe('empty state', () => {
it('no index pattern', function () {
// Go to the Discover page
cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.getElementByTestId('discoverNoIndexPatterns');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);

cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.getElementByTestId('discoverNoIndexPatterns');
});
});
Expand Down Expand Up @@ -52,7 +52,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
// Go to the Discover page
miscUtils.visitPage(`app/data-explorer/discover#/`);

cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
});

it('with SQL as default language', function () {
Expand All @@ -70,11 +70,11 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
cy.getElementByTestId(`advancedSelectorTimeFieldSelect`).select('timestamp');
cy.getElementByTestId('advancedSelectorConfirmButton').click();

cy.waitForLoaderNewHeader();
cy.waitForLoader(true);

// SQL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'OpenSearch SQL');
cy.waitForLoaderNewHeader();
cy.waitForLoader(true);

// SQL query should be executed and sending back result
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
Expand All @@ -85,7 +85,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
const toTime = 'Sep 21, 2019 @ 00:00:00.000';
cy.setTopNavDate(fromTime, toTime);

cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
});

Expand All @@ -105,7 +105,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
cy.getElementByTestId(`advancedSelectorTimeFieldSelect`).select('timestamp');
cy.getElementByTestId('advancedSelectorConfirmButton').click();

cy.waitForLoaderNewHeader();
cy.waitForLoader(true);

// PPL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'PPL');
Expand All @@ -114,7 +114,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
const toTime = 'Sep 21, 2019 @ 00:00:00.000';
cy.setTopNavDate(fromTime, toTime);

cy.waitForLoaderNewHeader();
cy.waitForLoader(true);

// Query should finish running with timestamp and finish time in the footer
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
Expand All @@ -123,7 +123,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
// Switch language to SQL
cy.setQueryLanguage('OpenSearch SQL');

cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should('contain', 'timestamp');
});
Expand All @@ -148,7 +148,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
cy.get(`[title="logstash-*"]`).click();
cy.getElementByTestId('datasetSelectorNext').click();

cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.waitForSearch();
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ describe.skip('query enhancement queries', { scrollBehavior: false }, () => {
cy.get(`[class~="datasetSelector__button"]`).click();
cy.get(`[data-test-subj="datasetOption-timestamp-*"]`).click();

cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.waitForSearch();
});

describe('send queries', () => {
it('with DQL', function () {
const query = `_id:1`;
cy.setSingleLineQueryEditor(query);
cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.waitForSearch();
cy.verifyHitCount(1);

Expand All @@ -54,7 +54,7 @@ describe.skip('query enhancement queries', { scrollBehavior: false }, () => {

const query = `_id:1`;
cy.setSingleLineQueryEditor(query);
cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.waitForSearch();
cy.verifyHitCount(1);

Expand All @@ -67,7 +67,7 @@ describe.skip('query enhancement queries', { scrollBehavior: false }, () => {
cy.setQueryLanguage('OpenSearch SQL');

// default SQL query should be set
cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.getElementByTestId(`osdQueryEditor__multiLine`).contains(
`SELECT * FROM timestamp-* LIMIT 10`
);
Expand All @@ -87,7 +87,7 @@ describe.skip('query enhancement queries', { scrollBehavior: false }, () => {
cy.setQueryLanguage('PPL');

// default PPL query should be set
cy.waitForLoaderNewHeader();
cy.waitForLoader(true);
cy.getElementByTestId(`osdQueryEditor__multiLine`).contains(`source = timestamp-*`);
cy.waitForSearch();
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');
Expand Down
19 changes: 5 additions & 14 deletions cypress/utils/apps/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,19 @@
import './data_explorer/commands';
import './query_enhancements/commands';

Cypress.Commands.add('waitForLoader', () => {
Cypress.Commands.add('waitForLoader', (isEnhancement = false) => {
const opts = { log: false };

Cypress.log({
name: 'waitForPageLoad',
displayName: 'wait',
message: 'page load',
});
cy.wait(Cypress.env('WAIT_FOR_LOADER_BUFFER_MS'));
cy.getElementByTestId('homeIcon', opts); // Update to `homeLoader` once useExpandedHeader is enabled
});

Cypress.Commands.add('waitForLoaderNewHeader', () => {
const opts = { log: false };

Cypress.log({
name: 'waitForPageLoad',
displayName: 'wait',
message: 'page load',
});
cy.wait(Cypress.env('WAIT_FOR_LOADER_BUFFER_MS'));
cy.getElementByTestId('recentItemsSectionButton', opts);
// Use recentItemsSectionButton for query enhancement, otherwise use homeIcon
cy.getElementByTestId(isEnhancement ? 'recentItemsSectionButton' : 'homeIcon', opts).should(
'be.visible'
);
});

Cypress.Commands.add('setTopNavQuery', (value, submit = true) => {
Expand Down
9 changes: 1 addition & 8 deletions cypress/utils/apps/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ declare namespace Cypress {
* @example
* cy.waitForLoader()
*/
waitForLoader(): Chainable<any>;

/**
* Wait for Dashboards page to load with new header
* @example
* cy.waitForLoaderNewHeader()
*/
waitForLoaderNewHeader(): Chainable<any>;
waitForLoader(isEnhancement?: boolean): Chainable<any>;

/**
* Set the top nav query value
Expand Down
4 changes: 2 additions & 2 deletions cypress/utils/apps/query_enhancements/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Cypress.Commands.add('addDataSource', (options) => {
cy.get('[name="password"]').type(credentials.password);
}

// Submit form
cy.getElementByTestId('createDataSourceButton').click();
// Submit form. Adding 'force' as sometimes a popover hides the button
cy.getElementByTestId('createDataSourceButton').click({ force: true });

// Wait for successful creation
cy.wait('@createDataSourceRequest').then((interception) => {
Expand Down
18 changes: 18 additions & 0 deletions cypress/utils/apps/query_enhancements/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

declare namespace Cypress {
interface Chainable<Subject> {
setSingleLineQueryEditor(value: string, submit?: boolean): Chainable<any>;
setQueryLanguage(value: 'DQL' | 'Lucene' | 'OpenSearch SQL' | 'PPL'): Chainable<any>;
addDataSource(opts: {
name: string;
url: string;
auth_type?: string;
credentials?: { username: string; password: string };
}): Chainable<any>;
deleteDataSourceByName(dataSourceName: string): Chainable<any>;
}
}
95 changes: 77 additions & 18 deletions cypress/utils/dashboards/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,48 +59,107 @@ Cypress.Commands.add(
Cypress.Commands.add(
//navigate to workspace specific pages
'navigateToWorkSpaceSpecificPage',
(url, workspaceName, page) => {
(opts) => {
const { url, workspaceName, page, isEnhancement = false } = opts;

// Navigating to the WorkSpace Home Page
cy.navigateToWorkSpaceHomePage(url, workspaceName);

// Opening the side panel
cy.getElementByTestId('toggleNavButton').then((ele) => {
if (ele.length > 0) {
ele.first().click();
}
});
cy.getElementByTestId('toggleNavButton')
.should('be.visible')
.then((ele) => {
if (ele.length > 0) {
ele.first().click();
}
});

cy.getElementByTestId(`collapsibleNavAppLink-${page}`).click();
cy.getElementByTestId(`collapsibleNavAppLink-${page}`).should('be.visible').click();

cy.waitForLoader();
// wait until page loads and close side panel
cy.waitForLoader(isEnhancement);

// close the nav menu
if (isEnhancement) {
cy.getElementByTestId('collapsibleNavShrinkButton').should('be.visible').click();
}
}
);

Cypress.Commands.add(
// creates an index pattern within the workspace
// Don't use * in the indexPattern it adds it by default at the end of name
'createWorkspaceIndexPatterns',
(url, workspaceName, indexPattern, dataSource, timefieldName = '') => {
(opts) => {
const {
url,
workspaceName,
indexPattern,
timefieldName,
indexPatternHasTimefield = true,
dataSource,
isEnhancement = false,
} = opts;

// Navigate to Workspace Specific IndexPattern Page
cy.navigateToWorkSpaceSpecificPage(url, workspaceName, 'indexPatterns');
cy.navigateToWorkSpaceSpecificPage({
url,
workspaceName,
page: 'indexPatterns',
isEnhancement,
});
cy.getElementByTestId('createIndexPatternButton').click();

cy.getElementByTestId('createIndexPatternButton').click({ force: true });
if (dataSource) {
cy.get('[type="data-source"]').contains(dataSource).click();
}

cy.get('[type="data-source"]').contains(dataSource).click();
cy.getElementByTestId('createIndexPatternStepDataSourceNextStepButton').click();

cy.wait(1000); // Intentional Wait

cy.getElementByTestId('createIndexPatternNameInput').clear().type(indexPattern);
cy.getElementByTestId('createIndexPatternNameInput')
.should('be.visible')
.clear()
.type(indexPattern);
cy.getElementByTestId('createIndexPatternGoToStep2Button').click();

if (timefieldName !== '') {
// wait for the select input if it exists
if (indexPatternHasTimefield || timefieldName) {
cy.getElementByTestId('createIndexPatternTimeFieldSelect').should('be.visible');
}

if (indexPatternHasTimefield && !!timefieldName) {
cy.getElementByTestId('createIndexPatternTimeFieldSelect').select(timefieldName);
} else {
} else if (indexPatternHasTimefield && !timefieldName) {
cy.getElementByTestId('createIndexPatternTimeFieldSelect').select(
"I don't want to use the time filter"
);
}
cy.getElementByTestId('createIndexPatternButton').click();

cy.getElementByTestId('createIndexPatternButton').should('be.visible').click();
cy.getElementByTestId('headerApplicationTitle').contains(indexPattern);
}
);

Cypress.Commands.add(
// deletes an index pattern within the workspace
// Don't use * in the indexPattern it adds it by default at the end of name
'deleteWorkspaceIndexPatterns',
(opts) => {
const { url, workspaceName, indexPattern, isEnhancement = false } = opts;

// Navigate to Workspace Specific IndexPattern Page
cy.navigateToWorkSpaceSpecificPage({
url,
workspaceName,
page: 'indexPatterns',
isEnhancement,
});

cy.contains('a', indexPattern).click();
cy.getElementByTestId('deleteIndexPatternButton').should('be.visible').click();
cy.getElementByTestId('confirmModalConfirmButton').should('be.visible').click();

// wait until delete is done
cy.getElementByTestId('headerApplicationTitle').should('be.visible');
}
);
31 changes: 31 additions & 0 deletions cypress/utils/dashboards/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

declare namespace Cypress {
Copy link
Member

Choose a reason for hiding this comment

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

I like this. We should add ts support to all the utilities, which can allow proper autocomplete and type check. I think we used to have in ftr repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i saw them more frequently in the ftr repo. I didn't add every single one here, i was mainly adding the ones that I was using just for my development benefit (IDE auto-complete) and decided to commit it to this PR. it would be great if later we can have full TS support for all of our utilities

interface Chainable<Subject> {
navigateToWorkSpaceHomePage(url: string, workspaceName: string): Chainable<any>;
navigateToWorkSpaceSpecificPage(opts: {
url: string;
workspaceName: string;
page: string;
isEnhancement?: boolean;
}): Chainable<any>;
createWorkspaceIndexPatterns(opts: {
url: string;
workspaceName: string;
indexPattern: string;
timefieldName?: string;
indexPatternHasTimefield?: boolean;
dataSource?: string;
isEnhancement?: boolean;
}): Chainable<any>;
deleteWorkspaceIndexPatterns(opts: {
url: string;
workspaceName: string;
indexPattern: string;
isEnhancement?: boolean;
}): Chainable<any>;
}
}
Loading