From 3091c269a16a294cb8f19d5c325affdfc03c50f4 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Tue, 26 Jan 2021 11:23:43 -0300 Subject: [PATCH] 17266: Avoids reloading the app on cypress tests by using search. Instead of using visit(url), whenever possible we should use some method that makes the app do the routing. One way is to use the search bar with UUIDs, as it will use the route to the proper resource panel. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- cypress/integration/collection-panel.spec.js | 32 ++++--------------- .../integration/delete-multiple-files.spec.js | 10 ++---- cypress/integration/search.spec.js | 4 +-- cypress/integration/side-panel.spec.js | 8 ++--- cypress/support/commands.js | 8 +++-- .../search-bar/search-bar-view.tsx | 2 +- 6 files changed, 22 insertions(+), 42 deletions(-) diff --git a/cypress/integration/collection-panel.spec.js b/cypress/integration/collection-panel.spec.js index 424c2bad..0669b313 100644 --- a/cypress/integration/collection-panel.spec.js +++ b/cypress/integration/collection-panel.spec.js @@ -28,7 +28,7 @@ describe('Collection panel tests', function() { cy.clearLocalStorage(); }); - it.only('shows collection by URL', function() { + it('shows collection by URL', function() { cy.loginAs(activeUser); [true, false].map(function(isWritable) { cy.createGroup(adminUser.token, { @@ -50,10 +50,7 @@ describe('Collection panel tests', function() { head_uuid: this.sharedGroup.uuid, tail_uuid: activeUser.user.uuid }) - cy.visit(`/collections/${this.testCollection.uuid}`); - - cy.get('[data-cy=linear-progress]').should('exist'); - cy.get('[data-cy=linear-progress]').should('not.exist'); + cy.doSearch(`${this.testCollection.uuid}`); // Check that name & uuid are correct. cy.get('[data-cy=collection-info-panel]') @@ -143,10 +140,7 @@ describe('Collection panel tests', function() { manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"}) .as('testCollection').then(function() { cy.loginAs(activeUser); - cy.visit(`/collections/${this.testCollection.uuid}`); - - cy.get('[data-cy=linear-progress]').should('exist'); - cy.get('[data-cy=linear-progress]').should('not.exist'); + cy.doSearch(`${this.testCollection.uuid}`); const nameTransitions = [ ['bar', '&'], @@ -183,10 +177,7 @@ describe('Collection panel tests', function() { manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"}) .as('testCollection').then(function() { cy.loginAs(activeUser); - cy.visit(`/collections/${this.testCollection.uuid}`); - - cy.get('[data-cy=linear-progress]').should('exist'); - cy.get('[data-cy=linear-progress]').should('not.exist'); + cy.doSearch(`${this.testCollection.uuid}`); // Rename 'bar' to 'subdir/foo' cy.get('[data-cy=collection-files-panel]') @@ -234,10 +225,7 @@ describe('Collection panel tests', function() { manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"}) .as('testCollection').then(function() { cy.loginAs(activeUser); - cy.visit(`/collections/${this.testCollection.uuid}`); - - cy.get('[data-cy=linear-progress]').should('exist'); - cy.get('[data-cy=linear-progress]').should('not.exist'); + cy.doSearch(`${this.testCollection.uuid}`); const illegalNamesFromUI = [ ['.', "Name cannot be '.' or '..'"], @@ -312,10 +300,7 @@ describe('Collection panel tests', function() { }); // Check the old version displays as what it is. cy.loginAs(activeUser) - cy.visit(`/collections/${oldVersionUuid}`); - - cy.get('[data-cy=linear-progress]').should('exist'); - cy.get('[data-cy=linear-progress]').should('not.exist'); + cy.doSearch(`${oldVersionUuid}`); cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version'); cy.get('[data-cy=read-only-icon]').should('exist'); @@ -337,10 +322,7 @@ describe('Collection panel tests', function() { .as('collection').then(function() { // Visit collection, check basic information cy.loginAs(activeUser) - cy.visit(`/collections/${this.collection.uuid}`); - - cy.get('[data-cy=linear-progress]').should('exist'); - cy.get('[data-cy=linear-progress]').should('not.exist'); + cy.doSearch(`${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'); diff --git a/cypress/integration/delete-multiple-files.spec.js b/cypress/integration/delete-multiple-files.spec.js index 0955f56a..f9e87117 100644 --- a/cypress/integration/delete-multiple-files.spec.js +++ b/cypress/integration/delete-multiple-files.spec.js @@ -32,10 +32,7 @@ describe('Multi-file deletion tests', function () { }) .as('testCollection').then(function () { cy.loginAs(activeUser); - cy.visit(`/collections/${this.testCollection.uuid}`); - - cy.get('[data-cy=linear-progress]').should('exist'); - cy.get('[data-cy=linear-progress]').should('not.exist'); + cy.doSearch(`${this.testCollection.uuid}`); cy.get('[data-cy=collection-files-panel]').within(() => { cy.get('[type="checkbox"]').first().check(); @@ -58,10 +55,7 @@ describe('Multi-file deletion tests', function () { }) .as('testCollection').then(function () { cy.loginAs(activeUser); - cy.visit(`/collections/${this.testCollection.uuid}`); - - cy.get('[data-cy=linear-progress]').should('exist'); - cy.get('[data-cy=linear-progress]').should('not.exist'); + cy.doSearch(`${this.testCollection.uuid}`); cy.get('[data-cy=virtual-file-tree] > div > i').first().click(); cy.get('[data-cy=collection-files-panel]') diff --git a/cypress/integration/search.spec.js b/cypress/integration/search.spec.js index 06131a2e..8806d12d 100644 --- a/cypress/integration/search.spec.js +++ b/cypress/integration/search.spec.js @@ -72,11 +72,11 @@ describe('Search tests', function() { cy.loginAs(activeUser); const searchQuery = `${colName} type:arvados#collection`; // Search for only collection's current version - cy.visit(`/search-results?q=${encodeURIComponent(searchQuery)}`); + cy.doSearch(`${searchQuery}`); cy.get('[data-cy=search-results]').should('contain', 'head version'); cy.get('[data-cy=search-results]').should('not.contain', 'version 1'); // ...and then, include old versions. - cy.visit(`/search-results?q=${encodeURIComponent(searchQuery + ' is:pastVersion')}`); + cy.doSearch(`${searchQuery} is:pastVersion`); cy.get('[data-cy=search-results]').should('contain', 'head version'); cy.get('[data-cy=search-results]').should('contain', 'version 1'); }); diff --git a/cypress/integration/side-panel.spec.js b/cypress/integration/side-panel.spec.js index 40f39144..fe9d8400 100644 --- a/cypress/integration/side-panel.spec.js +++ b/cypress/integration/side-panel.spec.js @@ -30,7 +30,7 @@ describe('Side panel tests', function() { it('enables the +NEW side panel button on users home project', function() { cy.loginAs(activeUser); - cy.visit(`/projects/${activeUser.user.uuid}`); + cy.doSearch(`${activeUser.user.uuid}`); cy.get('[data-cy=side-panel-button]') .should('exist') .and('not.be.disabled'); @@ -49,7 +49,7 @@ describe('Side panel tests', function() { head_uuid: this.sharedGroup.uuid, tail_uuid: activeUser.user.uuid }) - cy.visit(`/projects/${this.sharedGroup.uuid}`); + cy.doSearch(`${this.sharedGroup.uuid}`); cy.get('[data-cy=side-panel-button]') .should('exist') .and(`${isWritable ? 'not.' : ''}be.disabled`); @@ -78,7 +78,7 @@ describe('Side panel tests', function() { it('creates new collection on home project', function() { cy.loginAs(activeUser); - cy.visit(`/projects/${activeUser.user.uuid}`); + cy.doSearch(`${activeUser.user.uuid}`); cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects'); cy.get('[data-cy=breadcrumb-last]').should('not.exist'); // Create new collection @@ -122,7 +122,7 @@ describe('Side panel tests', function() { } cy.loginAs(activeUser); - cy.visit(`/projects/${activeUser.user.uuid}`); + cy.doSearch(`${activeUser.user.uuid}`); cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects'); cy.get('[data-cy=breadcrumb-last]').should('not.exist'); // Create new project diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 216012c4..bba04ba8 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -176,10 +176,14 @@ Cypress.Commands.add( Cypress.Commands.add( "loginAs", (user) => { cy.visit(`/token/?api_token=${user.token}`); - cy.get('[data-cy=loading-spinner]').should('exist'); - cy.get('[data-cy=loading-spinner]').should('not.exist'); cy.url().should('contain', '/projects/'); cy.get('div#root').should('contain', 'Arvados Workbench (zzzzz)'); cy.get('div#root').should('not.contain', 'Your account is inactive'); } ) + +Cypress.Commands.add( + "doSearch", (searchTerm) => { + cy.get('[data-cy=searchbar-input-field]').type(`{selectall}${searchTerm}{enter}`); + } +) \ No newline at end of file diff --git a/src/views-components/search-bar/search-bar-view.tsx b/src/views-components/search-bar/search-bar-view.tsx index 20536fd7..073aae6e 100644 --- a/src/views-components/search-bar/search-bar-view.tsx +++ b/src/views-components/search-bar/search-bar-view.tsx @@ -177,7 +177,7 @@ export const SearchBarView = compose(connectVocabulary, withStyles(styles))(