Skip to content

Commit c90d88c

Browse files
authored
test(react-storage): add upload copy and delete e2e tests (#6147)
* test(react-storage): add upload copy and delete e2e tests * make testing multiple files a variable
1 parent 36e1ee7 commit c90d88c

File tree

4 files changed

+210
-68
lines changed

4 files changed

+210
-68
lines changed

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

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import { get, escapeRegExp } from 'lodash';
88
let language = 'en-US';
99
let window = null;
1010
let stub = null;
11-
const randomFileName = `fileName${Math.random() * 10000}`;
11+
export const randomFileName = `fileName${Math.random() * 10000}`;
12+
13+
const doesDocumentContainText = (text: string) => {
14+
cy.findByRole('document')
15+
.contains(new RegExp(escapeRegExp(text), 'i'))
16+
.should('exist');
17+
};
1218

1319
const clickButtonWithText = (name: string) => {
1420
cy.findByRole('button', {
@@ -20,6 +26,22 @@ const typeInInputHandler = (field: string, value: string) => {
2026
cy.findInputField(field).type(value);
2127
};
2228

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+
2345
const getRoute = (routeMatcher: { headers: { [key: string]: string } }) => {
2446
return `${routeMatcher.headers?.['X-Amz-Target'] || 'route'}`;
2547
};
@@ -270,6 +292,10 @@ When('I click the {string}', (id: string) => {
270292
cy.findByTestId(id).click();
271293
});
272294

295+
When('I click the element with id attribute {string}', (id: string) => {
296+
cy.get(`#${id}`).click({ force: true });
297+
});
298+
273299
When('I click the {string} button', (name: string) => {
274300
cy.findByRole('button', {
275301
name: new RegExp(`^${escapeRegExp(name)}$`, 'i'),
@@ -362,10 +388,12 @@ Then('I see tab {string}', (search: string) => {
362388
cy.findAllByRole('tab').first().should('be.visible').contains(search);
363389
});
364390

365-
Then('I see {string}', (message: string) => {
366-
cy.findByRole('document')
367-
.contains(new RegExp(escapeRegExp(message), 'i'))
368-
.should('exist');
391+
Then('I see {string}', doesDocumentContainText);
392+
393+
Then('I see {string} files with random names', (count: string) => {
394+
for (let i = 1; i <= parseInt(count); i++) {
395+
doesDocumentContainText(`${randomFileName}-${i}`);
396+
}
369397
});
370398

371399
Then('I do not see {string}', (message: string) => {
@@ -581,6 +609,10 @@ Then('I click the submit button', () => {
581609
}).click();
582610
});
583611

612+
Then('I click the label containing text {string}', (labelText: string) => {
613+
cy.contains('label', labelText).should('be.visible').click({ force: true });
614+
});
615+
584616
Then('I confirm {string} error is accessible in password field', () => {
585617
// input field should be invalid
586618
cy.findInputField('Password')
@@ -645,3 +677,13 @@ Then('I see the {string} radio button checked', (label: string) => {
645677
'be.checked'
646678
);
647679
});
680+
681+
When('I upload {string} files with random names', (count: string) =>
682+
fileInputUpload(parseInt(count))
683+
);
684+
685+
When(
686+
'I upload a folder {string} with {string} files with random names',
687+
(folderName: string, count: string) =>
688+
fileInputUpload(parseInt(count), folderName)
689+
);

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
import { When, Then } from '@badeball/cypress-cucumber-preprocessor';
2+
import { randomFileName } from './shared';
3+
4+
const selectTableRowCheckBox = (name: string) => {
5+
cy.contains('table tbody td:nth-child(2)', new RegExp('^' + name + '$'))
6+
.siblings()
7+
.first()
8+
.within(() => {
9+
cy.get('label').click({ force: true });
10+
});
11+
};
212

313
When(
414
'I drag and drop a file into the storage browser with file name {string}',
@@ -65,3 +75,15 @@ Then('I click and see download succeed for {string}', (name: string) => {
6575
});
6676
});
6777
});
78+
79+
Then('I click checkbox for file {string}', selectTableRowCheckBox);
80+
81+
Then(
82+
'I click checkbox for with {string} files with random names',
83+
(count: string) => {
84+
const fileCount = parseInt(count);
85+
for (let i = 1; i <= fileCount; i++) {
86+
selectTableRowCheckBox(`${randomFileName}-${i}`);
87+
}
88+
}
89+
);
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
Feature: Create folder with Storage Browser
2+
3+
Background:
4+
Given I'm running the example "ui/components/storage/storage-browser/default-auth"
5+
6+
@react
7+
Scenario: Create folder successfully creates a new empty folder
8+
When I type my "email" with status "CONFIRMED"
9+
Then I type my password
10+
Then I click the "Sign in" button
11+
When I click the first button containing "public"
12+
When I click the first button containing "DoNotDeleteThisFolder_CanDeleteAllChildren"
13+
Then I see the "Menu Toggle" button
14+
When I click the "Menu Toggle" button
15+
Then I see the "Create Folder" menuitem
16+
When I click the "Create Folder" menuitem
17+
Then I see "Folder name"
18+
Then I see the "Create Folder" button
19+
Then the "Create Folder" button is disabled
20+
When I type a new "Folder name" with random value
21+
Then I see the "Create Folder" button
22+
When I click the "Create Folder" button
23+
Then I see "Folder created"
24+
# verify folder creation
25+
When I click the "Exit" button
26+
Then I click the button containing random name
27+
Then I see "No files"
28+
# TODO: delete created folder
29+
30+
@react
31+
Scenario: Create folder fails on overwrite of existing folder name
32+
When I type my "email" with status "CONFIRMED"
33+
Then I type my password
34+
Then I click the "Sign in" button
35+
When I click the first button containing "public"
36+
Then I see the "Menu Toggle" button
37+
When I click the "Menu Toggle" button
38+
Then I see the "Create Folder" menuitem
39+
When I click the "Create Folder" menuitem
40+
Then I see "Folder name"
41+
Then I see the "Create Folder" button
42+
Then the "Create Folder" button is disabled
43+
When I type a new "Folder name" with value "Blackberry"
44+
Then I see the "Create Folder" button
45+
When I click the "Create Folder" button
46+
Then I see "A folder already exists with the provided name"
47+
48+
@react
49+
Scenario: Create folder input shows error message when folder name contains "/"
50+
When I type my "email" with status "CONFIRMED"
51+
Then I type my password
52+
Then I click the "Sign in" button
53+
When I click the first button containing "public"
54+
Then I see the "Menu Toggle" button
55+
When I click the "Menu Toggle" button
56+
Then I see the "Create Folder" menuitem
57+
When I click the "Create Folder" menuitem
58+
Then I see "Folder name"
59+
Then I see the "Create Folder" button
60+
Then the "Create Folder" button is disabled
61+
When I type a new "Folder name" with value "Blackberry/"
62+
When I lose focus on "Folder name" input
63+
Then I see 'Folder name cannot contain \"/\", nor end or start with \".\"'
64+
65+
@react
66+
Scenario: upload, list, copy and delete a file using toggle menu
67+
When I type my "email" with status "CONFIRMED"
68+
Then I type my password
69+
Then I click the "Sign in" button
70+
When I click the first button containing "public"
71+
Then I see the "Menu Toggle" button
72+
When I click the "Menu Toggle" button
73+
# upload file
74+
Then I see the "Upload" menuitem
75+
When I click the "Upload" menuitem
76+
Then the "Upload" button is disabled
77+
Then I upload "1" files with random names
78+
Then I see "Not started"
79+
Then I click the label containing text "Overwrite existing files"
80+
When I click the "Upload" button
81+
Then I see "100%"
82+
Then I see "All files uploaded"
83+
When I click the "Exit" button
84+
# list uploaded file
85+
Then I see "1" files with random names
86+
# copy file
87+
Then I click checkbox for with "1" files with random names
88+
When I click the "Menu Toggle" button
89+
When I click the "Copy" menuitem
90+
Then I see "Copy destination"
91+
Then I click the "DoNotDeleteThisFolder_CanDeleteAllChildren/" button
92+
Then I click the "Copy" button
93+
Then I see "All files copied"
94+
When I click the "Exit" button
95+
# delete file
96+
Then I click checkbox for with "1" files with random names
97+
When I click the "Menu Toggle" button
98+
Then I click the "Delete" menuitem
99+
Then I click the "Delete" button
100+
Then I see "All files deleted"
101+
When I click the "Exit" button
102+
# delete file copy
103+
When I click the first button containing "DoNotDeleteThisFolder_CanDeleteAllChildren"
104+
Then I click checkbox for with "1" files with random names
105+
When I click the "Menu Toggle" button
106+
Then I click the "Delete" menuitem
107+
Then I click the "Delete" button
108+
Then I see "All files deleted"
109+
110+
@react
111+
Scenario: upload a folder
112+
When I type my "email" with status "CONFIRMED"
113+
Then I type my password
114+
Then I click the "Sign in" button
115+
When I click the first button containing "public"
116+
Then I see the "Menu Toggle" button
117+
When I click the "Menu Toggle" button
118+
# upload file
119+
Then I see the "Upload" menuitem
120+
When I click the "Upload" menuitem
121+
Then the "Upload" button is disabled
122+
Then I upload a folder "e2eTemp" with "2" files with random names
123+
Then I see "Not started"
124+
Then I click the label containing text "Overwrite existing files"
125+
When I click the "Upload" button
126+
Then I see "100%"
127+
Then I see "All files uploaded"
128+
When I click the "Exit" button
129+
# list uploaded file
130+
When I click the first button containing "e2eTemp"
131+
Then I see "2" files with random names
132+
# delete created file
133+
Then I click the element with id attribute "header-checkbox"
134+
When I click the "Menu Toggle" button
135+
Then I click the "Delete" menuitem
136+
Then I click the "Delete" button
137+
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"
141+

packages/e2e/features/ui/components/storage/storage-browser/create-folder.feature

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)