Merge branch '17500-cypress-flakyness-fixes'
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 21 Apr 2021 20:08:16 +0000 (17:08 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 21 Apr 2021 20:08:16 +0000 (17:08 -0300)
Closes #17500

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

cypress/integration/collection.spec.js
cypress/integration/delete-multiple-files.spec.js
cypress/integration/favorites.spec.js
cypress/integration/page-not-found.spec.js
cypress/integration/project.spec.js
cypress/integration/side-panel.spec.js
cypress/support/commands.js
src/index.tsx
src/views/workbench/workbench.tsx

index 841197abcfdc5a0b130ce9759e7760bc93d48584..05cd097dcbdaaae34e7efa74edf61d11859f1acb 100644 (file)
@@ -36,7 +36,7 @@ describe('Collection panel tests', function () {
         })
             .as('testCollection').then(function () {
                 cy.loginAs(activeUser);
-                cy.doSearch(`${this.testCollection.uuid}`);
+                cy.goToPath(`/collections/${this.testCollection.uuid}`);
 
                 // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
                 cy.get('[data-cy=resource-properties-form]').within(() => {
@@ -89,7 +89,7 @@ describe('Collection panel tests', function () {
                             head_uuid: this.sharedGroup.uuid,
                             tail_uuid: activeUser.user.uuid
                         })
-                        cy.doSearch(`${this.testCollection.uuid}`);
+                        cy.goToPath(`/collections/${this.testCollection.uuid}`);
 
                         // Check that name & uuid are correct.
                         cy.get('[data-cy=collection-info-panel]')
@@ -185,7 +185,7 @@ describe('Collection panel tests', function () {
         })
             .as('testCollection').then(function () {
                 cy.loginAs(activeUser);
-                cy.doSearch(`${this.testCollection.uuid}`);
+                cy.goToPath(`/collections/${this.testCollection.uuid}`);
 
                 const names = [
                     'bar', // initial name already set
@@ -238,7 +238,7 @@ describe('Collection panel tests', function () {
         })
             .as('testCollection').then(function () {
                 cy.loginAs(activeUser);
-                cy.doSearch(`${this.testCollection.uuid}`);
+                cy.goToPath(`/collections/${this.testCollection.uuid}`);
 
                 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
                     cy.get('[data-cy=collection-files-panel]')
@@ -295,7 +295,7 @@ describe('Collection panel tests', function () {
         })
             .as('testCollection').then(function () {
                 cy.loginAs(activeUser);
-                cy.doSearch(`${this.testCollection.uuid}`);
+                cy.goToPath(`/collections/${this.testCollection.uuid}`);
 
                 const illegalNamesFromUI = [
                     ['.', "Name cannot be '.' or '..'"],
@@ -371,7 +371,7 @@ describe('Collection panel tests', function () {
                 });
                 // Check the old version displays as what it is.
                 cy.loginAs(activeUser)
-                cy.doSearch(`${oldVersionUuid}`);
+                cy.goToPath(`/collections/${oldVersionUuid}`);
 
                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
                 cy.get('[data-cy=read-only-icon]').should('exist');
@@ -394,7 +394,7 @@ describe('Collection panel tests', function () {
             .as('collection').then(function () {
                 // Visit collection, check basic information
                 cy.loginAs(activeUser)
-                cy.doSearch(`${this.collection.uuid}`);
+                cy.goToPath(`/collections/${this.collection.uuid}`);
 
                 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
                 cy.get('[data-cy=read-only-icon]').should('not.exist');
@@ -510,7 +510,7 @@ describe('Collection panel tests', function () {
 
     it('creates new collection on home project', function () {
         cy.loginAs(activeUser);
-        cy.doSearch(`${activeUser.user.uuid}`);
+        cy.goToPath(`/projects/${activeUser.user.uuid}`);
         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
         // Create new collection
index f9e87117d804e42837dad267d85ccc41f55a36b4..deb56f66e72a0bc69a8e137fb7efc2b635d8eff2 100644 (file)
@@ -32,7 +32,7 @@ describe('Multi-file deletion tests', function () {
         })
             .as('testCollection').then(function () {
                 cy.loginAs(activeUser);
-                cy.doSearch(`${this.testCollection.uuid}`);
+                cy.goToPath(`/collections/${this.testCollection.uuid}`);
 
                 cy.get('[data-cy=collection-files-panel]').within(() => {
                     cy.get('[type="checkbox"]').first().check();
@@ -55,7 +55,7 @@ describe('Multi-file deletion tests', function () {
         })
             .as('testCollection').then(function () {
                 cy.loginAs(activeUser);
-                cy.doSearch(`${this.testCollection.uuid}`);
+                cy.goToPath(`/collections/${this.testCollection.uuid}`);
 
                 cy.get('[data-cy=virtual-file-tree] > div > i').first().click();
                 cy.get('[data-cy=collection-files-panel]')
index c745e267174050a4c901d323d37ac0bf90921f90..22514beb1e73f0b56694942653196b07bb729fb3 100644 (file)
@@ -14,14 +14,12 @@ describe('Favorites tests', function () {
         cy.getUser('admin', 'Admin', 'User', true, true)
             .as('adminUser').then(function () {
                 adminUser = this.adminUser;
-            }
-            );
+            });
         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
             .as('activeUser').then(function () {
                 activeUser = this.activeUser;
-            }
-            );
-    })
+            });
+    });
 
     beforeEach(function () {
         cy.clearCookies()
@@ -47,54 +45,37 @@ describe('Favorites tests', function () {
     });
 
     it('can copy selected into the collection', () => {
-        cy.loginAs(adminUser);
-
         cy.createCollection(adminUser.token, {
             name: `Test source collection ${Math.floor(Math.random() * 999999)}`,
             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
-        })
-            .as('testSourceCollection').then(function (testSourceCollection) {
-                cy.shareWith(adminUser.token, activeUser.user.uuid, testSourceCollection.uuid, 'can_read');
-            });
-
+        }).as('testSourceCollection').then(function (testSourceCollection) {
+            cy.shareWith(adminUser.token, activeUser.user.uuid, testSourceCollection.uuid, 'can_read');
+        });
         cy.createCollection(adminUser.token, {
             name: `Test target collection ${Math.floor(Math.random() * 999999)}`,
-        })
-            .as('testTargetCollection').then(function (testTargetCollection) {
-                cy.shareWith(adminUser.token, activeUser.user.uuid, testTargetCollection.uuid, 'can_write');
-            });
+        }).as('testTargetCollection').then(function (testTargetCollection) {
+            cy.shareWith(adminUser.token, activeUser.user.uuid, testTargetCollection.uuid, 'can_write');
+            cy.addToFavorites(activeUser.token, activeUser.user.uuid, testTargetCollection.uuid);
+        });
 
         cy.getAll('@testSourceCollection', '@testTargetCollection')
             .then(function ([testSourceCollection, testTargetCollection]) {
                 cy.loginAs(activeUser);
-
-                cy.get('.layout-pane-primary')
-                    .contains('Projects').click();
-
-                cy.addToFavorites(activeUser.token, activeUser.user.uuid, testTargetCollection.uuid);
-
-                cy.get('main').contains(testSourceCollection.name).click();
+                cy.goToPath(`/collections/${testSourceCollection.uuid}`);
                 cy.get('[data-cy=collection-files-panel]').contains('bar');
                 cy.get('[data-cy=collection-files-panel]').find('input[type=checkbox]').click({ force: true });
                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
                 cy.get('[data-cy=context-menu]')
                     .contains('Copy selected into the collection').click();
-
                 cy.get('[data-cy=projects-tree-favourites-tree-picker]')
                     .find('i')
                     .click();
-
                 cy.get('[data-cy=projects-tree-favourites-tree-picker]')
                     .contains(testTargetCollection.name)
                     .click();
-
                 cy.get('[data-cy=form-submit-btn]').click();
-
-                cy.get('.layout-pane-primary')
-                    .contains('Projects').click();
-
-                cy.get('main').contains(testTargetCollection.name).click();
-
+                cy.get('.layout-pane-primary').contains('Projects').click();
+                cy.goToPath(`/collections/${testTargetCollection.uuid}`);
                 cy.get('[data-cy=collection-files-panel]').contains('bar');
             });
     });
@@ -131,8 +112,6 @@ describe('Favorites tests', function () {
             .then(function ([mySharedWritableProject, mySharedReadonlyProject, myProject1, testCollection]) {
                 cy.loginAs(activeUser);
 
-                cy.doSearch(`${activeUser.user.uuid}`);
-
                 cy.contains(testCollection.name).rightclick();
                 cy.get('[data-cy=context-menu]').within(() => {
                     cy.contains('Move to').click();
@@ -148,7 +127,7 @@ describe('Favorites tests', function () {
                     cy.get('[data-cy=form-submit-btn]').click();
                 });
 
-                cy.doSearch(`${mySharedWritableProject.uuid}`);
+                cy.goToPath(`/projects/${mySharedWritableProject.uuid}`);
                 cy.get('main').contains(testCollection.name);
             });
     });
@@ -176,8 +155,6 @@ describe('Favorites tests', function () {
 
         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject', '@myProject1')
             .then(function ([mySharedWritableProject, mySharedReadonlyProject, myProject1]) {
-                cy.loginAs(activeUser);
-
                 cy.createWorkflow(adminUser.token, {
                     name: `TestWorkflow${Math.floor(Math.random() * 999999)}.cwl`,
                     definition: "{\n    \"$graph\": [\n        {\n            \"class\": \"Workflow\",\n            \"doc\": \"Reverse the lines in a document, then sort those lines.\",\n            \"hints\": [\n                {\n                    \"acrContainerImage\": \"99b0201f4cade456b4c9d343769a3b70+261\",\n                    \"class\": \"http://arvados.org/cwl#WorkflowRunnerResources\"\n                }\n            ],\n            \"id\": \"#main\",\n            \"inputs\": [\n                {\n                    \"default\": null,\n                    \"doc\": \"The input file to be processed.\",\n                    \"id\": \"#main/input\",\n                    \"type\": \"File\"\n                },\n                {\n                    \"default\": true,\n                    \"doc\": \"If true, reverse (decending) sort\",\n                    \"id\": \"#main/reverse_sort\",\n                    \"type\": \"boolean\"\n                }\n            ],\n            \"outputs\": [\n                {\n                    \"doc\": \"The output with the lines reversed and sorted.\",\n                    \"id\": \"#main/output\",\n                    \"outputSource\": \"#main/sorted/output\",\n                    \"type\": \"File\"\n                }\n            ],\n            \"steps\": [\n                {\n                    \"id\": \"#main/rev\",\n                    \"in\": [\n                        {\n                            \"id\": \"#main/rev/input\",\n                            \"source\": \"#main/input\"\n                        }\n                    ],\n                    \"out\": [\n                        \"#main/rev/output\"\n                    ],\n                    \"run\": \"#revtool.cwl\"\n                },\n                {\n                    \"id\": \"#main/sorted\",\n                    \"in\": [\n                        {\n                            \"id\": \"#main/sorted/input\",\n                            \"source\": \"#main/rev/output\"\n                        },\n                        {\n                            \"id\": \"#main/sorted/reverse\",\n                            \"source\": \"#main/reverse_sort\"\n                        }\n                    ],\n                    \"out\": [\n                        \"#main/sorted/output\"\n                    ],\n                    \"run\": \"#sorttool.cwl\"\n                }\n            ]\n        },\n        {\n            \"baseCommand\": \"rev\",\n            \"class\": \"CommandLineTool\",\n            \"doc\": \"Reverse each line using the `rev` command\",\n            \"hints\": [\n                {\n                    \"class\": \"ResourceRequirement\",\n                    \"ramMin\": 8\n                }\n            ],\n            \"id\": \"#revtool.cwl\",\n            \"inputs\": [\n                {\n                    \"id\": \"#revtool.cwl/input\",\n                    \"inputBinding\": {},\n                    \"type\": \"File\"\n                }\n            ],\n            \"outputs\": [\n                {\n                    \"id\": \"#revtool.cwl/output\",\n                    \"outputBinding\": {\n                        \"glob\": \"output.txt\"\n                    },\n                    \"type\": \"File\"\n                }\n            ],\n            \"stdout\": \"output.txt\"\n        },\n        {\n            \"baseCommand\": \"sort\",\n            \"class\": \"CommandLineTool\",\n            \"doc\": \"Sort lines using the `sort` command\",\n            \"hints\": [\n                {\n                    \"class\": \"ResourceRequirement\",\n                    \"ramMin\": 8\n                }\n            ],\n            \"id\": \"#sorttool.cwl\",\n            \"inputs\": [\n                {\n                    \"id\": \"#sorttool.cwl/reverse\",\n                    \"inputBinding\": {\n                        \"position\": 1,\n                        \"prefix\": \"-r\"\n                    },\n                    \"type\": \"boolean\"\n                },\n                {\n                    \"id\": \"#sorttool.cwl/input\",\n                    \"inputBinding\": {\n                        \"position\": 2\n                    },\n                    \"type\": \"File\"\n                }\n            ],\n            \"outputs\": [\n                {\n                    \"id\": \"#sorttool.cwl/output\",\n                    \"outputBinding\": {\n                        \"glob\": \"output.txt\"\n                    },\n                    \"type\": \"File\"\n                }\n            ],\n            \"stdout\": \"output.txt\"\n        }\n    ],\n    \"cwlVersion\": \"v1.0\"\n}",
@@ -192,9 +169,7 @@ describe('Favorites tests', function () {
                 })
                     .as('testWorkflow2');
 
-                cy.contains('Shared with me').click();
-
-                cy.doSearch(`${activeUser.user.uuid}`);
+                cy.loginAs(activeUser);
 
                 cy.get('main').contains(myProject1.name).click();
 
index 3dd15a67970668fdb2772352185b170138d0e36c..5d6a26b7d654ee0d2adc7c8f8fbdbccca9dc344b 100644 (file)
@@ -19,12 +19,9 @@ describe('Page not found tests', function() {
     });
 
     it('shows not found page', function() {
-        // given
-        const invalidUUID = '1212r12r12r12r12r12r21r'
-
         // when
         cy.loginAs(adminUser);
-        cy.visit(`/collections/${invalidUUID}`);
+        cy.goToPath(`/this/is/an/invalid/route`);
 
         // then
         cy.get('[data-cy=not-found-page]').should('exist');
@@ -38,10 +35,10 @@ describe('Page not found tests', function() {
 
         // when
         cy.loginAs(adminUser);
-        cy.visit(`/projects/${notExistingUUID}`);
+        cy.goToPath(`/projects/${notExistingUUID}`);
 
         // then
-        cy.get('[data-cy=not-found-page]').should('not.exist');
         cy.get('[data-cy=not-found-content]').should('exist');
+        cy.get('[data-cy=not-found-page]').should('not.exist');
     });
 })
\ No newline at end of file
index 69809b260e9be53a892fa6acc616fa0b33e8f449..76a6d0fff6373bfd09044742b03856d8b22ab340 100644 (file)
@@ -88,7 +88,7 @@ describe('Project tests', function() {
         }
 
         cy.loginAs(activeUser);
-        cy.doSearch(`${activeUser.user.uuid}`);
+        cy.goToPath(`/projects/${activeUser.user.uuid}`);
         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
         // Create new project
index 8100a0e48135be15563a2a9e5f6d2eef6b26633b..8882494bf81c69e501d3a50092b558c502d2c5ac 100644 (file)
@@ -30,7 +30,6 @@ describe('Side panel tests', function() {
 
     it('enables the +NEW side panel button on users home project', function() {
         cy.loginAs(activeUser);
-        cy.doSearch(`${activeUser.user.uuid}`);
         cy.get('[data-cy=side-panel-button]')
             .should('exist')
             .and('not.be.disabled');
@@ -49,7 +48,7 @@ describe('Side panel tests', function() {
                     head_uuid: this.sharedGroup.uuid,
                     tail_uuid: activeUser.user.uuid
                 })
-                cy.doSearch(`${this.sharedGroup.uuid}`);
+                cy.goToPath(`/projects/${this.sharedGroup.uuid}`);
                 cy.get('[data-cy=side-panel-button]')
                     .should('exist')
                     .and(`${isWritable ? 'not.' : ''}be.disabled`);
@@ -67,7 +66,7 @@ describe('Side panel tests', function() {
             {url: '/all_processes', label: 'All Processes'},
             {url: '/trash', label: 'Trash'},
         ].map(function(section) {
-            cy.visit(section.url);
+            cy.goToPath(section.url);
             cy.get('[data-cy=breadcrumb-first]')
                 .should('contain', section.label);
             cy.get('[data-cy=side-panel-button]')
@@ -84,7 +83,7 @@ describe('Side panel tests', function() {
             properties: {filters: []},
         }).as('myFavoriteFilterGroup').then(function (myFavoriteFilterGroup) {
             cy.contains('Refresh').click();
-            cy.doSearch(`${myFavoriteFilterGroup.uuid}`);
+            cy.goToPath(`/projects/${myFavoriteFilterGroup.uuid}`);
             cy.get('[data-cy=breadcrumb-last]').should('contain', 'my-favorite-filter-group');
 
             cy.get('[data-cy=side-panel-button]')
index 8dc003fee1288f8b10cd76ec8bee7d27f1a17fc8..dbb9cd0b1f9a82b33118d8cad630d8c87789128b 100644 (file)
 
 const controllerURL = Cypress.env('controller_url');
 const systemToken = Cypress.env('system_token');
+let createdResources = [];
+
+// Clean up on a 'before' hook to allow post-mortem analysis on individual tests.
+beforeEach(function () {
+    if (createdResources.length === 0) {
+        return;
+    }
+    cy.log(`Cleaning ${createdResources.length} previously created resource(s)`);
+    createdResources.forEach(function({suffix, uuid}) {
+        // Don't fail when a resource isn't already there, some objects may have
+        // been removed, directly or indirectly, from the test that created them.
+        cy.deleteResource(systemToken, suffix, uuid, false);
+    });
+    createdResources = [];
+});
 
 Cypress.Commands.add(
     "doRequest", (method = 'GET', path = '', data = null, qs = null,
-        token = systemToken, auth = false, followRedirect = true) => {
+        token = systemToken, auth = false, followRedirect = true, failOnStatusCode = true) => {
     return cy.request({
         method: method,
-        url: `${controllerURL}/${path}`,
+        url: `${controllerURL.replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`,
         body: data,
         qs: auth ? qs : Object.assign({ api_token: token }, qs),
         auth: auth ? { bearer: `${token}` } : undefined,
-        followRedirect: followRedirect
-    })
-}
-)
-
-// This resets the DB removing all content and seeding it with the fixtures.
-// TODO: Maybe we can add an optional param to avoid the loading part?
-Cypress.Commands.add(
-    "resetDB", () => {
-        cy.request('POST', `${controllerURL}/database/reset?api_token=${systemToken}`);
-    }
-)
+        followRedirect: followRedirect,
+        failOnStatusCode: failOnStatusCode
+    });
+});
 
 Cypress.Commands.add(
     "getUser", (username, first_name = '', last_name = '', is_admin = false, is_active = true) => {
@@ -148,14 +155,15 @@ Cypress.Commands.add(
         return cy.doRequest('POST', '/arvados/v1/' + suffix, data, null, token, true)
             .its('body').as('resource')
             .then(function () {
+                createdResources.push({suffix, uuid: this.resource.uuid});
                 return this.resource;
             })
     }
 )
 
 Cypress.Commands.add(
-    "deleteResource", (token, suffix, uuid) => {
-        return cy.doRequest('DELETE', '/arvados/v1/' + suffix + '/' + uuid)
+    "deleteResource", (token, suffix, uuid, failOnStatusCode = true) => {
+        return cy.doRequest('DELETE', '/arvados/v1/' + suffix + '/' + uuid, null, null, token, false, true, failOnStatusCode)
             .its('body').as('resource')
             .then(function () {
                 return this.resource;
@@ -175,8 +183,10 @@ Cypress.Commands.add(
 
 Cypress.Commands.add(
     "loginAs", (user) => {
+        cy.clearCookies()
+        cy.clearLocalStorage()
         cy.visit(`/token/?api_token=${user.token}`);
-        cy.url().should('contain', '/projects/');
+        cy.url({timeout: 10000}).should('contain', '/projects/');
         cy.get('div#root').should('contain', 'Arvados Workbench (zzzzz)');
         cy.get('div#root').should('not.contain', 'Your account is inactive');
     }
@@ -188,6 +198,12 @@ Cypress.Commands.add(
     }
 )
 
+Cypress.Commands.add(
+    "goToPath", (path) => {
+        return cy.window().its('appHistory').invoke('push', path);
+    }
+)
+
 Cypress.Commands.add('getAll', (...elements) => {
     const promise = cy.wrap([], { log: false })
 
@@ -207,13 +223,13 @@ Cypress.Commands.add('shareWith', (srcUserToken, targetUserUUID, itemUUID, permi
     });
 })
 
-Cypress.Commands.add('addToFavorites', (activeUserToken, activeUserUUID, itemUUID) => {
-    cy.createLink(activeUserToken, {
+Cypress.Commands.add('addToFavorites', (userToken, userUUID, itemUUID) => {
+    cy.createLink(userToken, {
         head_uuid: itemUUID,
         link_class: 'star',
         name: '',
-        owner_uuid: activeUserUUID,
-        tail_uuid: activeUserUUID,
+        owner_uuid: userUUID,
+        tail_uuid: userUUID,
     });
 })
 
index 43cfb5fb03e31513e7689561760a4246ec3a35d6..e691c5d2433d8ee4f9ec40a0783a7b8943ede938 100644 (file)
@@ -104,6 +104,13 @@ storeRedirects();
 fetchConfig()
     .then(({ config, apiHost }) => {
         const history = createBrowserHistory();
+
+        // Provide browser's history access to Cypress to allow programmatic
+        // navigation.
+        if ((window as any).Cypress) {
+            (window as any).appHistory = history;
+        }
+
         const services = createServices(config, {
             progressFn: (id, working) => {
                 store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
index 78ec3c87cb24bce04e5a7387963409d94db074df..dc02bdd6364a73693c0293eb9e7fdf29341a7ea2 100644 (file)
@@ -205,7 +205,7 @@ export const WorkbenchPanel =
                         </Grid>
                         <Grid item xs className={props.classes.content}>
                             <Switch>
-                                {routes}
+                                {routes.props.children}
                                 <Route path={Routes.NO_MATCH} component={NotFoundPanel} />
                             </Switch>
                         </Grid>