1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe('Search tests', 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;
19 cy.getUser('collectionuser1', 'Collection', 'User', false, true)
20 .as('activeUser').then(function() {
21 activeUser = this.activeUser;
26 beforeEach(function() {
28 cy.clearLocalStorage()
31 it('can search for old collection versions', function() {
32 const colName = `Versioned Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
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
40 .its('body.items').as('collections')
42 expect(this.collections).to.be.empty;
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, {
48 owner_uuid: activeUser.user.uuid,
49 preserve_version: true,
50 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
51 .as('originalVersion').then(function() {
52 // Change the file name to create a new version.
53 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
54 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
56 colUuid = this.originalVersion.uuid;
58 // Confirm that there are 2 versions of the collection
59 cy.doRequest('GET', '/arvados/v1/collections', null, {
60 filters: `[["name", "=", "${colName}"]]`,
61 include_old_versions: true
63 .its('body.items').as('collections')
65 expect(this.collections).to.have.lengthOf(2);
66 this.collections.map(function(aCollection) {
67 expect(aCollection.current_version_uuid).to.equal(colUuid);
68 if (aCollection.uuid !== aCollection.current_version_uuid) {
69 oldVersionUuid = aCollection.uuid;
72 cy.loginAs(activeUser);
73 const searchQuery = `${colName} type:arvados#collection`;
74 // Search for only collection's current version
75 cy.doSearch(`${searchQuery}`);
76 cy.get('[data-cy=search-results]').should('contain', 'head version');
77 cy.get('[data-cy=search-results]').should('not.contain', 'version 1');
78 // ...and then, include old versions.
79 cy.doSearch(`${searchQuery} is:pastVersion`);
80 cy.get('[data-cy=search-results]').should('contain', 'head version');
81 cy.get('[data-cy=search-results]').should('contain', 'version 1');
85 it('can display path of the selected item', function() {
86 const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
88 // Creates the collection using the admin token so we can set up
89 // a bogus manifest text without block signatures.
90 cy.createCollection(adminUser.token, {
92 owner_uuid: activeUser.user.uuid,
93 preserve_version: true,
94 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
96 cy.loginAs(activeUser);
100 cy.get('[data-cy=search-results]').should('contain', colName);
102 cy.get('[data-cy=search-results]').contains(colName).closest('tr').click();
104 cy.get('[data-cy=element-path]').should('contain', `/ Projects / ${colName}`);
108 it('can search items using quotes', function() {
109 const random = Math.floor(Math.random() * Math.floor(999999));
110 const colName = `Collection ${random}`;
111 const colName2 = `Collection test ${random}`;
113 // Creates the collection using the admin token so we can set up
114 // a bogus manifest text without block signatures.
115 cy.createCollection(adminUser.token, {
117 owner_uuid: activeUser.user.uuid,
118 preserve_version: true,
119 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
120 }).as('collection1');
122 cy.createCollection(adminUser.token, {
124 owner_uuid: activeUser.user.uuid,
125 preserve_version: true,
126 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
127 }).as('collection2');
129 cy.getAll('@collection1', '@collection2')
131 cy.loginAs(activeUser);
133 cy.doSearch(colName);
134 cy.get('[data-cy=search-results] table tbody tr').should('have.length', 2);
136 cy.doSearch(`"${colName}"`);
137 cy.get('[data-cy=search-results] table tbody tr').should('have.length', 1);
141 it('can display owner of the item', function() {
142 const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
144 cy.createCollection(adminUser.token, {
146 owner_uuid: activeUser.user.uuid,
147 preserve_version: true,
148 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
150 cy.loginAs(activeUser);
152 cy.doSearch(colName);
154 cy.get('[data-cy=search-results]').should('contain', colName);
156 cy.get('[data-cy=search-results]').contains(colName).closest('tr')
158 cy.get('p').contains(activeUser.user.uuid).should('contain', activeUser.user.full_name);