Skip to content

Commit 8f24bfd

Browse files
authored
[Workspace]Add workspace import sample data cases (#1357)
* Add workspace import sample data cases Signed-off-by: Lin Wang <[email protected]> * Add back data source title Signed-off-by: Lin Wang <[email protected]> --------- Signed-off-by: Lin Wang <[email protected]>
1 parent 6f6ab1f commit 8f24bfd

File tree

2 files changed

+145
-1
lines changed

2 files changed

+145
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
const MDSEnabled = Cypress.env('DATASOURCE_MANAGEMENT_ENABLED');
7+
8+
if (Cypress.env('WORKSPACE_ENABLED')) {
9+
describe('import sample data to workspace', () => {
10+
let workspaceId;
11+
let dataSourceId;
12+
let dataSourceTitle;
13+
const workspaceName = `workspace-${new Date().getTime()}`;
14+
15+
const getTitleWithDataSource = (title) => {
16+
if (!dataSourceTitle) {
17+
return title;
18+
}
19+
return `${title}_${dataSourceTitle}`;
20+
};
21+
22+
before(() => {
23+
if (MDSEnabled) {
24+
cy.createDataSourceNoAuth().then((result) => {
25+
dataSourceId = result[0];
26+
dataSourceTitle = result[1];
27+
});
28+
}
29+
cy.createWorkspace({ name: workspaceName }).then((id) => {
30+
workspaceId = id;
31+
});
32+
});
33+
34+
after(() => {
35+
if (workspaceId) {
36+
cy.deleteWorkspaceById(workspaceId);
37+
}
38+
if (dataSourceId) {
39+
cy.deleteDataSource(dataSourceId);
40+
}
41+
});
42+
43+
beforeEach(() => {
44+
cy.visit(`/w/${workspaceId}/app/import_sample_data`);
45+
cy.waitForLoader();
46+
if (MDSEnabled) {
47+
cy.selectFromDataSourceSelector(dataSourceTitle, dataSourceId);
48+
}
49+
});
50+
51+
it('should show Add data buttons if sample data not installed', () => {
52+
cy.getElementByTestId('addSampleDataSetecommerce').should('be.visible');
53+
cy.getElementByTestId('addSampleDataSetflights').should('be.visible');
54+
cy.getElementByTestId('addSampleDataSetlogs').should('be.visible');
55+
});
56+
57+
it('should show remove buttons after sample data installed', () => {
58+
cy.getElementByTestId('addSampleDataSetecommerce').click();
59+
cy.getElementByTestId('addSampleDataSetflights').click();
60+
cy.getElementByTestId('addSampleDataSetlogs').click();
61+
62+
cy.getElementByTestId('removeSampleDataSetecommerce').should(
63+
'be.visible'
64+
);
65+
cy.getElementByTestId('removeSampleDataSetflights').should('be.visible');
66+
cy.getElementByTestId('removeSampleDataSetlogs').should('be.visible');
67+
68+
cy.getElementByTestId('removeSampleDataSetecommerce').click();
69+
cy.getElementByTestId('removeSampleDataSetflights').click();
70+
cy.getElementByTestId('removeSampleDataSetlogs').click();
71+
});
72+
73+
it('should be able to visit ecommerce dashboard', () => {
74+
cy.getElementByTestId('addSampleDataSetecommerce').click();
75+
76+
cy.getElementByTestId('launchSampleDataSetecommerce')
77+
.should('be.visible')
78+
.click();
79+
80+
cy.location('href').should('include', `/w/${workspaceId}/app/dashboards`);
81+
cy.getElementByTestId('breadcrumb last')
82+
.contains(getTitleWithDataSource('[eCommerce] Revenue Dashboard'))
83+
.should('be.visible');
84+
cy.get(
85+
`[data-title="${getTitleWithDataSource('[eCommerce] Total Revenue')}"]`
86+
).should('not.contain', 'No results found');
87+
cy.visit(`/w/${workspaceId}/app/import_sample_data`);
88+
89+
if (MDSEnabled) {
90+
cy.selectFromDataSourceSelector(dataSourceTitle, dataSourceId);
91+
}
92+
cy.getElementByTestId('removeSampleDataSetecommerce').click();
93+
});
94+
95+
it('should be able to visit flights dashboards', () => {
96+
cy.getElementByTestId('addSampleDataSetflights').click();
97+
98+
cy.getElementByTestId('launchSampleDataSetflights')
99+
.should('be.visible')
100+
.click();
101+
102+
cy.location('href').should('include', `/w/${workspaceId}/app/dashboards`);
103+
cy.getElementByTestId('breadcrumb last').contains(
104+
getTitleWithDataSource('[Flights] Global Flight Dashboard')
105+
);
106+
cy.get(
107+
`[data-title="${getTitleWithDataSource('[Flights] Flight Delays')}"]`
108+
).should('not.contain', 'No results found');
109+
cy.visit(`/w/${workspaceId}/app/import_sample_data`);
110+
111+
if (MDSEnabled) {
112+
cy.selectFromDataSourceSelector(dataSourceTitle, dataSourceId);
113+
}
114+
cy.getElementByTestId('removeSampleDataSetflights').click();
115+
});
116+
117+
it('should be able to visit logs dashboards', () => {
118+
cy.getElementByTestId('addSampleDataSetlogs').click();
119+
120+
cy.getElementByTestId('launchSampleDataSetlogs')
121+
.should('be.visible')
122+
.click();
123+
124+
cy.location('href').should('include', `/w/${workspaceId}/app/dashboards`);
125+
cy.getElementByTestId('breadcrumb last').contains(
126+
getTitleWithDataSource('[Logs] Web Traffic')
127+
);
128+
cy.get(
129+
`[data-title="${getTitleWithDataSource(
130+
'[Logs] Unique Visitors vs. Average Bytes'
131+
)}"]`
132+
).should('not.contain', 'No results found');
133+
cy.visit(`/w/${workspaceId}/app/import_sample_data`);
134+
135+
if (MDSEnabled) {
136+
cy.selectFromDataSourceSelector(dataSourceTitle, dataSourceId);
137+
}
138+
cy.getElementByTestId('removeSampleDataSetlogs').click();
139+
});
140+
});
141+
}

cypress/utils/commands.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,12 @@ Cypress.Commands.add(
613613
});
614614
cy.getElementByTestId('dataSourceSelectorComboBox')
615615
.find('input')
616-
.clear('{backspace}')
616+
.clear('{backspace}');
617+
cy.getElementByTestId('dataSourceSelectorComboBox')
618+
.find('input')
617619
.type(dataSourceTitle);
618620
cy.wait(1000);
621+
619622
let dataSourceElement;
620623
if (dataSourceId) {
621624
dataSourceElement = cy.get(`#${dataSourceId}`);

0 commit comments

Comments
 (0)