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

Add cypress test for workspace overview page #1633

Merged
merged 6 commits into from
Nov 13, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';

const miscUtils = new MiscUtils(cy);
const workspaceName = `test_workspace_analytics_${Math.random()
.toString(36)
.substring(7)}`;
let workspaceDescription = 'This is a analytics workspace description.';
let workspaceId;
let datasourceId;
let workspaceFeatures = ['use-case-all'];

const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED');

if (Cypress.env('WORKSPACE_ENABLED')) {
const createWorkspace = (dsId) => {
cy.createWorkspace({
name: workspaceName,
description: workspaceDescription,
features: workspaceFeatures,
settings: {
permissions: {
library_write: { users: ['%me%'] },
write: { users: ['%me%'] },
},
...(dsId ? { dataSources: [dsId] } : {}),
},
}).then((value) => {
workspaceId = value;
// load sample data
cy.loadSampleDataForWorkspace('ecommerce', value, dsId);
});
};

describe('Analytics workspace overview', () => {
before(() => {
cy.deleteWorkspaceByName(workspaceName);
if (MDSEnabled) {
cy.deleteAllDataSources();
cy.createDataSourceNoAuth().then((result) => {
datasourceId = result[0];
expect(datasourceId).to.be.a('string').that.is.not.empty;
createWorkspace(datasourceId);
});
} else {
createWorkspace();
}
});

after(() => {
if (workspaceId) {
cy.removeSampleDataForWorkspace('ecommerce', workspaceId, datasourceId);
cy.deleteWorkspaceById(workspaceId);
}
cy.deleteAllDataSources();
});

beforeEach(() => {
// Visit workspace update page
miscUtils.visitPage(`w/${workspaceId}/app/all_overview`);
// wait for page load
cy.contains('h1', 'Overview');
});

it('should display get started sections', () => {
cy.get('.euiCard__footer').contains('Observability').should('be.visible');
// this is depends on observability plugin been installed
// cy.url().should('include', 'app/observability-overview');

cy.get('.euiCard__footer')
.contains('Security Analytics')
.should('be.visible');
// this is depends on security analytics plugin been installed
// cy.url().should('include', 'app/sa_overview');

cy.get('.euiCard__footer')
.contains('Search')
.should('be.visible')
.click();
cy.url().should('include', 'app/search_overview');
});

it('should display asset section correctly', () => {
// no recently view assets
cy.contains('No assets to display');

// recentlyCard
cy.contains('Recently updated').should('be.visible').click();
// should have 6 elements
cy.getElementByTestId('recentlyCard').should('have.length', 6);

// filter by dashboard
cy.getElementByTestId('comboBoxInput').click();
cy.get('span.euiComboBoxOption__content').contains('dashboard').click();

// click dashboard card
cy.getElementByTestId('recentlyCard').first().click();

// verify url has /app/dashboards
cy.url().should('include', 'app/dashboards');

cy.go('back');

// view all
cy.contains('View all').click();
// verify url has /app/objects
cy.url().should('include', 'app/objects');
});

// Alerts and threat Alerts cards are depends on plugins

it('should display OpenSearch Documentation panel', () => {
cy.contains('OpenSearch Documentation').should('be.visible');
cy.get('.euiLink')
.contains('Quickstart guide')
.should('be.visible')
.and(
'have.attr',
'href',
'https://opensearch.org/docs/latest/dashboards/quickstart/'
);
cy.get('.euiLink')
.contains('Building data visualizations')
.should('be.visible')
.and(
'have.attr',
'href',
'https://opensearch.org/docs/latest/dashboards/visualize/viz-index/'
);
cy.get('.euiLink')
.contains('Creating dashboards')
.should('be.visible')
.and(
'have.attr',
'href',
'https://opensearch.org/docs/latest/dashboards/dashboard/index/'
);
cy.contains('Learn more in Documentation')
.should('be.visible')
.and(
'have.attr',
'href',
'https://opensearch.org/docs/latest/dashboards/index/'
);
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';

const miscUtils = new MiscUtils(cy);
const workspaceName = `test_workspace_${Math.random()
.toString(36)
.substring(7)}`;
let workspaceDescription = 'This is a workspace description.';
let workspaceId;
let datasourceId;
let workspaceFeatures = ['use-case-essentials'];

const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED');

if (Cypress.env('WORKSPACE_ENABLED')) {
const createWorkspace = (datasourceId) => {
cy.createWorkspace({
name: workspaceName,
description: workspaceDescription,
features: workspaceFeatures,
settings: {
permissions: {
library_write: { users: ['%me%'] },
write: { users: ['%me%'] },
},
...(datasourceId ? { dataSources: [datasourceId] } : {}),
},
}).then((value) => {
workspaceId = value;
// load sample data
cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId);
});
};

describe('Essential workspace overview', () => {
before(() => {
cy.deleteWorkspaceByName(workspaceName);
if (MDSEnabled) {
cy.deleteAllDataSources();
cy.createDataSourceNoAuth().then((result) => {
datasourceId = result[0];
expect(datasourceId).to.be.a('string').that.is.not.empty;
createWorkspace(datasourceId);
});
} else {
createWorkspace();
}
});

after(() => {
if (workspaceId) {
cy.removeSampleDataForWorkspace('ecommerce', workspaceId, datasourceId);
cy.deleteWorkspaceById(workspaceId);
}
cy.deleteAllDataSources();
});

beforeEach(() => {
// Visit workspace update page
miscUtils.visitPage(`w/${workspaceId}/app/essentials_overview`);
// wait for page load
cy.contains('h1', 'Overview');
});

it('Get started cards display correctly', () => {
// verify four get started cards exist
cy.contains('Install sample data to experiment with OpenSearch.').click();
// verify url has app/import_sample_data
cy.url().should('include', 'app/import_sample_data');

// browser back
cy.go('back');
cy.contains('Explore data to uncover and discover insights.').click();
// verify url has app/data-explorer/discover
cy.url().should('include', 'app/data-explorer/discover');

// browser back
cy.go('back');
cy.contains(
'Gain deeper insights by visualizing and aggregating your data.'
).click();
// verify url has app/visualize
cy.url().should('include', 'app/visualize');

cy.go('back');
cy.contains(
'Monitor and explore your data using dynamic data visualization tools.'
).click();
// verify url has app/dashboards
cy.url().should('include', 'app/dashboards');
});

it('Assets cards display correctly', () => {
// no recently view assets
cy.contains('No assets to display');

// recentlyCard
cy.contains('Recently updated').should('be.visible').click();
// should have 6 elements
cy.getElementByTestId('recentlyCard').should('have.length', 6);

// filter by dashboard
cy.getElementByTestId('comboBoxInput').click();
cy.get('span.euiComboBoxOption__content').contains('dashboard').click();

// click dashboard card
cy.getElementByTestId('recentlyCard').first().click();

// verify url has /app/dashboards
cy.url().should('include', 'app/dashboards');

cy.go('back');

// view all
cy.contains('View all').click();
// verify url has /app/objects
cy.url().should('include', 'app/objects');
});

it('Opensearch documentation cards display correctly', () => {
cy.contains('OpenSearch Documentation');

// get a link with text as Quickstart guide
cy.get('a')
.contains('Quickstart guide')
.should(
'have.attr',
'href',
'https://opensearch.org/docs/latest/dashboards/quickstart/'
);

cy.get('a')
.contains('Building data visualizations')
.should(
'have.attr',
'href',
'https://opensearch.org/docs/latest/dashboards/visualize/viz-index/'
);

cy.get('a')
.contains('Creating dashboards')
.should(
'have.attr',
'href',
'https://opensearch.org/docs/latest/dashboards/dashboard/index/'
);
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';

const miscUtils = new MiscUtils(cy);
const workspaceName = `test_workspace_search_${Math.random()
.toString(36)
.substring(7)}`;
let workspaceDescription = 'This is a search workspace description.';
let workspaceId;
let datasourceId;
let workspaceFeatures = ['use-case-search'];

const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED');

if (Cypress.env('WORKSPACE_ENABLED')) {
const createWorkspace = (datasourceId) => {
cy.createWorkspace({
name: workspaceName,
description: workspaceDescription,
features: workspaceFeatures,
settings: {
permissions: {
library_write: { users: ['%me%'] },
write: { users: ['%me%'] },
},
...(datasourceId ? { dataSources: [datasourceId] } : {}),
},
}).then((value) => {
workspaceId = value;
});
};
Comment on lines +20 to +35
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const createWorkspace = (datasourceId) => {
cy.createWorkspace({
name: workspaceName,
description: workspaceDescription,
features: workspaceFeatures,
settings: {
permissions: {
library_write: { users: ['%me%'] },
write: { users: ['%me%'] },
},
...(datasourceId ? { dataSources: [datasourceId] } : {}),
},
}).then((value) => {
workspaceId = value;
});
};
const createWorkspace = (datasourceId) => {
cy.createWorkspace({
name: workspaceName,
description: workspaceDescription,
features: workspaceFeatures,
settings: {
permissions: {
library_write: { users: ['%me%'] },
write: { users: ['%me%'] },
},
...(datasourceId ? { dataSources: [datasourceId] } : {}),
},
}).then((value) => {
workspaceId = value;
});
};

We can move the function to a util function maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cy.createWorkspace already been a util function, and this createWorkspace function just utilized the cy.createWorkspace to create workspace with and without datasource. To move it to a common place as util function may not benefits other test cases.


describe('Search workspace overview', () => {
before(() => {
cy.deleteWorkspaceByName(workspaceName);
if (MDSEnabled) {
cy.deleteAllDataSources();
cy.createDataSourceNoAuth().then((result) => {
datasourceId = result[0];
expect(datasourceId).to.be.a('string').that.is.not.empty;
createWorkspace(datasourceId);
});
} else {
createWorkspace();
}
});

after(() => {
if (workspaceId) {
cy.deleteWorkspaceById(workspaceId);
}
cy.deleteAllDataSources();
});

beforeEach(() => {
// Visit workspace update page
miscUtils.visitPage(`w/${workspaceId}/app/search_overview`);
// wait for page load
cy.contains('h1', 'Overview');
});

it('Set up search cards display correctly', () => {
cy.contains(
'Explore search capabilities and functionality of OpenSearch.'
);
cy.contains(
'Create a document collection (an index) to query your data.'
);

cy.contains('Explore data to uncover and discover insights.').click();
// verify url has app/data-explorer/discover
cy.url().should('include', 'app/data-explorer/discover');
});

it('Different search techniques section display correctly', () => {
cy.contains('h3', 'Text search').should('be.visible');
cy.contains('h3', 'Analyzers').should('be.visible');
cy.contains('h3', 'Semantic vector search').should('be.visible');
cy.contains('h3', 'Neural sparse search').should('be.visible');
cy.contains('h3', 'Hybrid search').should('be.visible');
});

it('Configure and evaluate search cards display correctly', () => {
cy.contains('Compare search results').should('be.visible').click();
cy.url().should('contains', 'app/searchRelevance');
});
});
}
Loading
Loading