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

test(e2e): add cy commands for storage-browser #6202

Closed
Closed
Show file tree
Hide file tree
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
48 changes: 8 additions & 40 deletions packages/e2e/cypress/integration/common/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,6 @@ let window = null;
let stub = null;
export const randomFileName = `fileName${Math.random() * 10000}`;

const doesDocumentContainText = (text: string) => {
cy.findByRole('document')
.contains(new RegExp(escapeRegExp(text), 'i'))
.should('exist');
};

const clickButtonWithText = (name: string) => {
cy.findByRole('button', {
name: new RegExp(`${escapeRegExp(name)}`, 'i'),
}).click();
};

const typeInInputHandler = (field: string, value: string) => {
cy.findInputField(field).type(value);
};

const fileInputUpload = (fileCount: number = 1, folderName?: string) => {
const folderFiles = [];
for (let i = 1; i <= fileCount; i++) {
const fileName = folderName
? `${folderName}/${randomFileName}-${i}`
: `${randomFileName}-${i}`;

folderFiles.push({
contents: Cypress.Buffer.from(`File ${i} content`),
fileName,
mimeType: 'text/plain',
});
}
cy.get('input[type="file"]').selectFile(folderFiles, { force: true });
};

const getRoute = (routeMatcher: { headers: { [key: string]: string } }) => {
return `${routeMatcher.headers?.['X-Amz-Target'] || 'route'}`;
};
Expand Down Expand Up @@ -272,10 +240,10 @@ When('I type a new {string}', (field: string) => {
cy.findInputField(field).typeAliasWithStatus(field, `${Date.now()}`);
});

When('I type a new {string} with value {string}', typeInInputHandler);
When('I type a new {string} with value {string}', cy.typeInInputHandler);

When('I type a new {string} with random value', (field: string) => {
typeInInputHandler(field, randomFileName);
cy.typeInInputHandler(field, randomFileName);
});

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

When('I click the button containing {string}', clickButtonWithText);
When('I click the button containing {string}', cy.clickButtonWithText);

When('I click the button containing random name', () => {
clickButtonWithText(randomFileName);
cy.clickButtonWithText(randomFileName);
});

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

Then('I see {string}', doesDocumentContainText);
Then('I see {string}', cy.doesDocumentContainText);

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

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

When('I upload {string} files with random names', (count: string) =>
fileInputUpload(parseInt(count))
cy.fileInputUpload(randomFileName, parseInt(count))
);

When(
'I upload a folder {string} with {string} files with random names',
(folderName: string, count: string) =>
fileInputUpload(parseInt(count), folderName)
cy.fileInputUpload(`${folderName}/${randomFileName}`, parseInt(count))
);
50 changes: 50 additions & 0 deletions packages/e2e/cypress/support/commands.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions packages/e2e/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,34 @@ Cypress.Commands.add('findInputField', (field: string) => {
Cypress.Commands.add('waitForIdleMap', () => {
cy.window().its('idleMap').should('be.true');
});

Cypress.Commands.add('clickButtonWithText', (name: string) => {
cy.findByRole('button', {
name: new RegExp(`${escapeRegExp(name)}`, 'i'),
}).click();
});

Cypress.Commands.add('doesDocumentContainText', (text: string) => {
cy.findByRole('document')
.contains(new RegExp(escapeRegExp(text), 'i'))
.should('exist');
});

Cypress.Commands.add('typeInInputHandler', (field: string, value: string) => {
cy.findInputField(field).type(value);
});

Cypress.Commands.add(
'fileInputUpload',
(fileName: string, fileCount: number = 1) => {
const folderFiles = [];
for (let i = 1; i <= fileCount; i++) {
folderFiles.push({
contents: Cypress.Buffer.from(`File ${i} content`),
fileName: `${fileName}-${i}`,
mimeType: 'text/plain',
});
}
cy.get('input[type="file"]').selectFile(folderFiles, { force: true });
}
);
ashwinkumar6 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ Feature: Create folder with Storage Browser
# upload file
Then I see the "Upload" menuitem
When I click the "Upload" menuitem
Then the "Upload" button is disabled
Then I upload a folder "e2eTemp" with "2" files with random names
Then I see "Not started"
Then I click the label containing text "Overwrite existing files"
When I click the "Upload" button
Then I see "100%"
Then I see "All files uploaded"
When I click the "Exit" button
# list uploaded file
Expand All @@ -135,7 +133,4 @@ Feature: Create folder with Storage Browser
Then I click the "Delete" menuitem
Then I click the "Delete" button
Then I see "All files deleted"
When I click the "Exit" button
# verify all files are deleted
Then I see "No files"
Comment on lines -138 to -140
Copy link
Member

Choose a reason for hiding this comment

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

Info: is there a test for deletion where this logic exists? It seems like it would make sense to have a confirmation that deleted files are then not listed

Copy link
Member Author

Choose a reason for hiding this comment

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

We're testing delete on upload, list, copy and delete a file using toggle menu test. It has a Then I see "All files deleted" step to verify the deletion