Skip to content

Commit ddca1d9

Browse files
committed
optimize the code
Signed-off-by: yubonluo <yubonluo@amazon.com>
1 parent 23b9563 commit ddca1d9

File tree

1 file changed

+49
-31
lines changed

1 file changed

+49
-31
lines changed

cypress/utils/dashboards/workspace-plugin/test-cases/mds_workspace_copy.cases.js

+49-31
Original file line numberDiff line numberDiff line change
@@ -96,40 +96,52 @@ export const WorkspaceCopyTestCases = () => {
9696

9797
if (Cypress.env('WORKSPACE_ENABLED')) {
9898
before(() => {
99-
cy.deleteWorkspaceByName(sourceWorkspaceName);
100-
cy.deleteWorkspaceByName(targetWorkspaceName);
99+
cy.deleteAllWorkspaces();
101100
cy.createDataSourceNoAuth({ title: dataSourceTitle1 }).then((result) => {
102101
dataSourceId1 = result[0];
103-
cy.createWorkspace({
104-
name: sourceWorkspaceName,
105-
features: ['use-case-observability'],
106-
settings: {
107-
permissions: {
108-
library_write: { users: ['%me%'] },
109-
write: { users: ['%me%'] },
110-
},
111-
dataSources: [dataSourceId1],
112-
},
113-
}).then((value) => {
114-
sourceWorkspaceId = value;
115-
// Import ecommerce sample data to source workspace.
116-
cy.loadSampleDataForWorkspace(
117-
'ecommerce',
118-
sourceWorkspaceId,
119-
dataSourceId1
120-
);
121-
});
122102
});
123103
cy.createDataSourceNoAuth({ title: dataSourceTitle2 }).then((result) => {
124104
dataSourceId2 = result[0];
125105
});
106+
107+
cy.wrap(null)
108+
.should(() => {
109+
expect(dataSourceId1).to.not.be.undefined;
110+
expect(dataSourceId2).to.not.be.undefined;
111+
})
112+
.then(() => {
113+
cy.createWorkspace({
114+
name: sourceWorkspaceName,
115+
features: ['use-case-observability'],
116+
settings: {
117+
permissions: {
118+
library_write: { users: ['%me%'] },
119+
write: { users: ['%me%'] },
120+
},
121+
dataSources: [dataSourceId1, dataSourceId2],
122+
},
123+
}).then((value) => {
124+
sourceWorkspaceId = value;
125+
// Import ecommerce sample data to dataSourceId1 of source workspace.
126+
cy.loadSampleDataForWorkspace(
127+
'ecommerce',
128+
sourceWorkspaceId,
129+
dataSourceId1
130+
);
131+
});
132+
});
126133
});
127134

128135
after(() => {
129-
cy.deleteDataSource(dataSourceId1);
130-
cy.deleteDataSource(dataSourceId2);
131-
cy.deleteWorkspaceByName(sourceWorkspaceName);
132-
cy.deleteWorkspaceByName(targetWorkspaceName);
136+
cy.wrap(null).then(() => {
137+
if (dataSourceId1) {
138+
cy.deleteDataSource(dataSourceId1);
139+
}
140+
if (dataSourceId2) {
141+
cy.deleteDataSource(dataSourceId2);
142+
}
143+
});
144+
cy.deleteAllWorkspaces();
133145
});
134146

135147
beforeEach(() => {
@@ -199,6 +211,12 @@ export const WorkspaceCopyTestCases = () => {
199211

200212
describe('Partial copy assets', () => {
201213
before(() => {
214+
// Import ecommerce sample data to dataSourceId2 of source workspace.
215+
cy.loadSampleDataForWorkspace(
216+
'ecommerce',
217+
sourceWorkspaceId,
218+
dataSourceId2
219+
);
202220
createTargetWorkspace(dataSourceId2);
203221
miscUtils.visitPage(`w/${sourceWorkspaceId}/app/objects`);
204222
});
@@ -221,7 +239,7 @@ export const WorkspaceCopyTestCases = () => {
221239
cy.wait('@copyAssetsRequest').then((interception) => {
222240
expect(interception.response.statusCode).to.equal(200);
223241
expect(interception.response.body.success).to.equal(false);
224-
expect(interception.response.body.successCount).to.equal(1);
242+
expect(interception.response.body.successCount).to.equal(15);
225243
});
226244

227245
cy.get('.euiFlyout')
@@ -232,21 +250,21 @@ export const WorkspaceCopyTestCases = () => {
232250
cy.contains(
233251
`The following assets can not be copied, some of the data sources they use are not associated with ${targetWorkspaceName}`
234252
);
235-
cy.contains('Copy remaining 1 asset').should('exist').click();
253+
cy.contains('Copy remaining 15 asset').should('exist').click();
236254
});
237255

238256
// should successfully copy remaining assets from source workspace to target workspace
239257
cy.wait('@copyAssetsRequest').then((interception) => {
240258
expect(interception.response.statusCode).to.equal(200);
241259
expect(interception.response.body.success).to.equal(true);
242-
expect(interception.response.body.successCount).to.equal(1);
260+
expect(interception.response.body.successCount).to.equal(15);
243261
});
244262
cy.get('.euiFlyout')
245263
.should('be.visible')
246264
.within(() => {
247265
cy.contains('Copy assets to ' + targetWorkspaceName);
248-
cy.contains('1 asset copied');
249-
cy.contains('1 Successful');
266+
cy.contains('15 assets copied');
267+
cy.contains('15 Successful');
250268
});
251269
miscUtils.visitPage(`w/${targetWorkspaceId}/app/objects`);
252270

@@ -255,7 +273,7 @@ export const WorkspaceCopyTestCases = () => {
255273
cy.getElementByTestId('savedObjectsTable')
256274
.find('tbody')
257275
.get('.euiTableRow')
258-
.should('have.length', 1);
276+
.should('have.length', 15);
259277
});
260278
});
261279
}

0 commit comments

Comments
 (0)