16719: Adds integration test for collection's old version searching.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 15 Oct 2020 18:25:17 +0000 (15:25 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 15 Oct 2020 18:25:17 +0000 (15:25 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

cypress/integration/search.spec.js [new file with mode: 0644]
src/views-components/search-bar/search-bar-view.tsx
src/views/search-results-panel/search-results-panel-view.tsx

diff --git a/cypress/integration/search.spec.js b/cypress/integration/search.spec.js
new file mode 100644 (file)
index 0000000..0fba64c
--- /dev/null
@@ -0,0 +1,83 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+describe('Search tests', function() {
+    let activeUser;
+    let adminUser;
+
+    before(function() {
+        // Only set up common users once. These aren't set up as aliases because
+        // aliases are cleaned up after every test. Also it doesn't make sense
+        // to set the same users on beforeEach() over and over again, so we
+        // separate a little from Cypress' 'Best Practices' here.
+        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()
+        cy.clearLocalStorage()
+    })
+
+    it('can search for old collection versions', function() {
+        const colName = `Versioned Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
+        let colUuid = '';
+        let oldVersionUuid = '';
+        // Make sure no other collections with this name exist
+        cy.doRequest('GET', '/arvados/v1/collections', null, {
+            filters: `[["name", "=", "${colName}"]]`,
+            include_old_versions: true
+        })
+        .its('body.items').as('collections')
+        .then(function() {
+            expect(this.collections).to.be.empty;
+        });
+        // Creates the collection using the admin token so we can set up
+        // a bogus manifest text without block signatures.
+        cy.createCollection(adminUser.token, {
+            name: colName,
+            owner_uuid: activeUser.user.uuid,
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
+        .as('originalVersion').then(function() {
+            // Change the file name to create a new version.
+            cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
+                manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
+            })
+            colUuid = this.originalVersion.uuid;
+        });
+        // Confirm that there are 2 versions of the collection
+        cy.doRequest('GET', '/arvados/v1/collections', null, {
+            filters: `[["name", "=", "${colName}"]]`,
+            include_old_versions: true
+        })
+        .its('body.items').as('collections')
+        .then(function() {
+            expect(this.collections).to.have.lengthOf(2);
+            this.collections.map(function(aCollection) {
+                expect(aCollection.current_version_uuid).to.equal(colUuid);
+                if (aCollection.uuid !== aCollection.current_version_uuid) {
+                    oldVersionUuid = aCollection.uuid;
+                }
+            });
+            cy.loginAs(activeUser);
+            const searchQuery = `${colName} type:arvados#collection`;
+            // Search for only collection's current version
+            cy.visit(`/search-results?q=${encodeURIComponent(searchQuery)}`);
+            cy.get('[data-cy=search-results]').should('contain', 'current');
+            cy.get('[data-cy=search-results]').should('not.contain', 'old version');
+            // ...and then, include old versions.
+            cy.visit(`/search-results?q=${encodeURIComponent(searchQuery + ' is:pastVersion')}`);
+            cy.get('[data-cy=search-results]').should('contain', 'current');
+            cy.get('[data-cy=search-results]').should('contain', 'old version');
+        });
+    });
+});
\ No newline at end of file
index 49a8ba6235e5183c2a528287572c2f7081d11dca..20536fd7e1422d2e3771829deb33e897eafed8d2 100644 (file)
@@ -177,6 +177,7 @@ export const SearchBarView = compose(connectVocabulary, withStyles(styles))(
                     <Paper className={isPopoverOpen ? classes.containerSearchViewOpened : classes.container} >
                         <form onSubmit={this.handleSubmit}>
                             <Input
+                                data-cy='search-input-field'
                                 className={classes.input}
                                 onChange={this.handleChange}
                                 placeholder="Search"
index fbaba210e29b94cec6d32def6256c6eba116d342..dae91bd0e5fcb15427857a63e541034dab2d527b 100644 (file)
@@ -108,7 +108,7 @@ export const SearchResultsPanelView = withStyles(styles, { withTheme: true })(
     (props: SearchResultsPanelProps & WithStyles<CssRules, true>) => {
         const homeCluster = props.user.uuid.substr(0, 5);
         const loggedIn = props.sessions.filter((ss) => ss.loggedIn && ss.userIsActive);
-        return <DataExplorer
+        return <span data-cy='search-results'><DataExplorer
             id={SEARCH_RESULTS_PANEL_ID}
             onRowClick={props.onItemClick}
             onRowDoubleClick={props.onItemDoubleClick}
@@ -127,5 +127,5 @@ export const SearchResultsPanelView = withStyles(styles, { withTheme: true })(
                         : <span style={{ marginLeft: "2em" }}>Use <Link to={Routes.SITE_MANAGER} >Site Manager</Link> to manage which clusters will be searched.</span>}
                 </div >
             }
-        />;
+        /></span>;
     });