Skip to content

Commit ba1cda5

Browse files
authored
test(e2e): add cy commands for storage-browser (#6208)
* test(e2e): add cy commands for storage-browser * update fileuploader e2e to use cy.fileInputUpload
1 parent d827f03 commit ba1cda5

File tree

5 files changed

+92
-74
lines changed

5 files changed

+92
-74
lines changed

packages/e2e/cypress/integration/common/fileuploader.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,14 @@
11
import { When } from '@badeball/cypress-cucumber-preprocessor';
22

33
When('I select a file with file name {string}', (fileName: string) => {
4-
cy.get('input[type=file]').selectFile(
5-
{
6-
contents: Cypress.Buffer.from('file contents'),
7-
fileName,
8-
lastModified: Date.now(),
9-
},
10-
/**
11-
* Since the input is hidden, this will need to be forced through Cypress
12-
*/
13-
{ force: true }
14-
);
4+
cy.fileInputUpload(fileName);
155
});
166

177
When(
188
'I select a file with file name {string} and another file with file name {string}',
199
(fileName: string, fileName2: string) => {
20-
cy.get('input[type=file]').selectFile(
21-
[
22-
{
23-
contents: Cypress.Buffer.from('file contents'),
24-
fileName,
25-
lastModified: Date.now(),
26-
},
27-
{
28-
contents: Cypress.Buffer.from('file contents'),
29-
fileName: fileName2,
30-
lastModified: Date.now(),
31-
},
32-
],
33-
/**
34-
* Since the input is hidden, this will need to be forced through Cypress
35-
*/
36-
{ force: true }
37-
);
10+
cy.fileInputUpload(fileName);
11+
cy.fileInputUpload(fileName2);
3812
}
3913
);
4014

packages/e2e/cypress/integration/common/shared.ts

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,6 @@ let window = null;
1010
let stub = null;
1111
export const randomFileName = `fileName${Math.random() * 10000}`;
1212

13-
const doesDocumentContainText = (text: string) => {
14-
cy.findByRole('document')
15-
.contains(new RegExp(escapeRegExp(text), 'i'))
16-
.should('exist');
17-
};
18-
19-
const clickButtonWithText = (name: string) => {
20-
cy.findByRole('button', {
21-
name: new RegExp(`${escapeRegExp(name)}`, 'i'),
22-
}).click();
23-
};
24-
25-
const typeInInputHandler = (field: string, value: string) => {
26-
cy.findInputField(field).type(value);
27-
};
28-
29-
const fileInputUpload = (fileCount: number = 1, folderName?: string) => {
30-
const folderFiles = [];
31-
for (let i = 1; i <= fileCount; i++) {
32-
const fileName = folderName
33-
? `${folderName}/${randomFileName}-${i}`
34-
: `${randomFileName}-${i}`;
35-
36-
folderFiles.push({
37-
contents: Cypress.Buffer.from(`File ${i} content`),
38-
fileName,
39-
mimeType: 'text/plain',
40-
});
41-
}
42-
cy.get('input[type="file"]').selectFile(folderFiles, { force: true });
43-
};
44-
4513
const getRoute = (routeMatcher: { headers: { [key: string]: string } }) => {
4614
return `${routeMatcher.headers?.['X-Amz-Target'] || 'route'}`;
4715
};
@@ -272,10 +240,10 @@ When('I type a new {string}', (field: string) => {
272240
cy.findInputField(field).typeAliasWithStatus(field, `${Date.now()}`);
273241
});
274242

275-
When('I type a new {string} with value {string}', typeInInputHandler);
243+
When('I type a new {string} with value {string}', cy.typeInInputHandler);
276244

277245
When('I type a new {string} with random value', (field: string) => {
278-
typeInInputHandler(field, randomFileName);
246+
cy.typeInInputHandler(field, randomFileName);
279247
});
280248

281249
When('I lose focus on {string} input', (field: string) => {
@@ -306,10 +274,10 @@ Then('I press the {string} key', (key: string) => {
306274
cy.get('body').type(key);
307275
});
308276

309-
When('I click the button containing {string}', clickButtonWithText);
277+
When('I click the button containing {string}', cy.clickButtonWithText);
310278

311279
When('I click the button containing random name', () => {
312-
clickButtonWithText(randomFileName);
280+
cy.clickButtonWithText(randomFileName);
313281
});
314282

315283
When('I click the first button containing {string}', (name: string) => {
@@ -388,11 +356,11 @@ Then('I see tab {string}', (search: string) => {
388356
cy.findAllByRole('tab').first().should('be.visible').contains(search);
389357
});
390358

391-
Then('I see {string}', doesDocumentContainText);
359+
Then('I see {string}', cy.doesDocumentContainText);
392360

393361
Then('I see {string} files with random names', (count: string) => {
394362
for (let i = 1; i <= parseInt(count); i++) {
395-
doesDocumentContainText(`${randomFileName}-${i}`);
363+
cy.doesDocumentContainText(`${randomFileName}-${i}`);
396364
}
397365
});
398366

@@ -679,11 +647,11 @@ Then('I see the {string} radio button checked', (label: string) => {
679647
});
680648

681649
When('I upload {string} files with random names', (count: string) =>
682-
fileInputUpload(parseInt(count))
650+
cy.fileInputUpload(randomFileName, parseInt(count))
683651
);
684652

685653
When(
686654
'I upload a folder {string} with {string} files with random names',
687655
(folderName: string, count: string) =>
688-
fileInputUpload(parseInt(count), folderName)
656+
cy.fileInputUpload(`${folderName}/${randomFileName}`, parseInt(count))
689657
);

packages/e2e/cypress/support/commands.d.ts

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/e2e/cypress/support/commands.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,34 @@ Cypress.Commands.add('findInputField', (field: string) => {
7575
Cypress.Commands.add('waitForIdleMap', () => {
7676
cy.window().its('idleMap').should('be.true');
7777
});
78+
79+
Cypress.Commands.add('clickButtonWithText', (name: string) => {
80+
cy.findByRole('button', {
81+
name: new RegExp(`${escapeRegExp(name)}`, 'i'),
82+
}).click();
83+
});
84+
85+
Cypress.Commands.add('doesDocumentContainText', (text: string) => {
86+
cy.findByRole('document')
87+
.contains(new RegExp(escapeRegExp(text), 'i'))
88+
.should('exist');
89+
});
90+
91+
Cypress.Commands.add('typeInInputHandler', (field: string, value: string) => {
92+
cy.findInputField(field).type(value);
93+
});
94+
95+
Cypress.Commands.add(
96+
'fileInputUpload',
97+
(fileName: string, fileCount: number = 1) => {
98+
const folderFiles = [];
99+
for (let i = 1; i <= fileCount; i++) {
100+
folderFiles.push({
101+
contents: Cypress.Buffer.from(`File ${i} content`),
102+
fileName: `${fileName}-${i}`,
103+
mimeType: 'text/plain',
104+
});
105+
}
106+
cy.get('input[type="file"]').selectFile(folderFiles, { force: true });
107+
}
108+
);

packages/e2e/features/ui/components/storage/storage-browser/action-menu.feature

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,10 @@ Feature: Create folder with Storage Browser
118118
# upload file
119119
Then I see the "Upload" menuitem
120120
When I click the "Upload" menuitem
121-
Then the "Upload" button is disabled
122121
Then I upload a folder "e2eTemp" with "2" files with random names
123122
Then I see "Not started"
124123
Then I click the label containing text "Overwrite existing files"
125124
When I click the "Upload" button
126-
Then I see "100%"
127125
Then I see "All files uploaded"
128126
When I click the "Exit" button
129127
# list uploaded file
@@ -135,7 +133,4 @@ Feature: Create folder with Storage Browser
135133
Then I click the "Delete" menuitem
136134
Then I click the "Delete" button
137135
Then I see "All files deleted"
138-
When I click the "Exit" button
139-
# verify all files are deleted
140-
Then I see "No files"
141136

0 commit comments

Comments
 (0)