16719: Adds integration test for collection's old version searching.
[arvados-workbench2.git] / cypress / integration / search.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Search tests', function() {
6     let activeUser;
7     let adminUser;
8
9     before(function() {
10         // Only set up common users once. These aren't set up as aliases because
11         // aliases are cleaned up after every test. Also it doesn't make sense
12         // to set the same users on beforeEach() over and over again, so we
13         // separate a little from Cypress' 'Best Practices' here.
14         cy.getUser('admin', 'Admin', 'User', true, true)
15             .as('adminUser').then(function() {
16                 adminUser = this.adminUser;
17             }
18         );
19         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
20             .as('activeUser').then(function() {
21                 activeUser = this.activeUser;
22             }
23         );
24     })
25
26     beforeEach(function() {
27         cy.clearCookies()
28         cy.clearLocalStorage()
29     })
30
31     it('can search for old collection versions', function() {
32         const colName = `Versioned Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
33         let colUuid = '';
34         let oldVersionUuid = '';
35         // Make sure no other collections with this name exist
36         cy.doRequest('GET', '/arvados/v1/collections', null, {
37             filters: `[["name", "=", "${colName}"]]`,
38             include_old_versions: true
39         })
40         .its('body.items').as('collections')
41         .then(function() {
42             expect(this.collections).to.be.empty;
43         });
44         // Creates the collection using the admin token so we can set up
45         // a bogus manifest text without block signatures.
46         cy.createCollection(adminUser.token, {
47             name: colName,
48             owner_uuid: activeUser.user.uuid,
49             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
50         .as('originalVersion').then(function() {
51             // Change the file name to create a new version.
52             cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
53                 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
54             })
55             colUuid = this.originalVersion.uuid;
56         });
57         // Confirm that there are 2 versions of the collection
58         cy.doRequest('GET', '/arvados/v1/collections', null, {
59             filters: `[["name", "=", "${colName}"]]`,
60             include_old_versions: true
61         })
62         .its('body.items').as('collections')
63         .then(function() {
64             expect(this.collections).to.have.lengthOf(2);
65             this.collections.map(function(aCollection) {
66                 expect(aCollection.current_version_uuid).to.equal(colUuid);
67                 if (aCollection.uuid !== aCollection.current_version_uuid) {
68                     oldVersionUuid = aCollection.uuid;
69                 }
70             });
71             cy.loginAs(activeUser);
72             const searchQuery = `${colName} type:arvados#collection`;
73             // Search for only collection's current version
74             cy.visit(`/search-results?q=${encodeURIComponent(searchQuery)}`);
75             cy.get('[data-cy=search-results]').should('contain', 'current');
76             cy.get('[data-cy=search-results]').should('not.contain', 'old version');
77             // ...and then, include old versions.
78             cy.visit(`/search-results?q=${encodeURIComponent(searchQuery + ' is:pastVersion')}`);
79             cy.get('[data-cy=search-results]').should('contain', 'current');
80             cy.get('[data-cy=search-results]').should('contain', 'old version');
81         });
82     });
83 });