19079: Add federated case to search results context menu tests
[arvados-workbench2.git] / cypress / integration / search.spec.js
index 86d86877724cb1965367b916592739097987772c..2216c067f8423f7c36fdfd4c7b10ca23402d707c 100644 (file)
@@ -129,6 +129,80 @@ describe('Search tests', function() {
 
     it('shows search context menu', function() {
         const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
+        const federatedColName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
+        const federatedColUuid = "xxxxx-4zz18-000000000000000";
+
+        // Intercept config to insert remote cluster
+        cy.intercept({method: 'GET', hostname: 'localhost', url: '**/arvados/v1/config?nocache=*'}, (req) => {
+            req.reply((res) => {
+                res.body.RemoteClusters = {
+                    "*": res.body.RemoteClusters["*"],
+                    "xxxxx": {
+                        "ActivateUsers": true,
+                        "Host": "xxxxx.fakecluster.tld",
+                        "Insecure": false,
+                        "Proxy": true,
+                        "Scheme": ""
+                    }
+                };
+            });
+        });
+
+        // Fake remote cluster config
+        cy.intercept(
+          {
+            method: "GET",
+            hostname: "xxxxx.fakecluster.tld",
+            url: "**/arvados/v1/config",
+          },
+          {
+            statusCode: 200,
+            body: {
+              API: {},
+              ClusterID: "xxxxx",
+              Collections: {},
+              Containers: {},
+              InstanceTypes: {},
+              Login: {},
+              Mail: { SupportEmailAddress: "arvados@example.com" },
+              RemoteClusters: {
+                "*": {
+                  ActivateUsers: false,
+                  Host: "",
+                  Insecure: false,
+                  Proxy: false,
+                  Scheme: "https",
+                },
+              },
+              Services: {
+                Composer: { ExternalURL: "" },
+                Controller: { ExternalURL: "https://xxxxx.fakecluster.tld:34763/" },
+                DispatchCloud: { ExternalURL: "" },
+                DispatchLSF: { ExternalURL: "" },
+                DispatchSLURM: { ExternalURL: "" },
+                GitHTTP: { ExternalURL: "https://xxxxx.fakecluster.tld:39105/" },
+                GitSSH: { ExternalURL: "" },
+                Health: { ExternalURL: "https://xxxxx.fakecluster.tld:42915/" },
+                Keepbalance: { ExternalURL: "" },
+                Keepproxy: { ExternalURL: "https://xxxxx.fakecluster.tld:46773/" },
+                Keepstore: { ExternalURL: "" },
+                RailsAPI: { ExternalURL: "" },
+                WebDAV: { ExternalURL: "https://xxxxx.fakecluster.tld:36041/" },
+                WebDAVDownload: { ExternalURL: "https://xxxxx.fakecluster.tld:42957/" },
+                WebShell: { ExternalURL: "" },
+                Websocket: { ExternalURL: "wss://xxxxx.fakecluster.tld:37121/websocket" },
+                Workbench1: { ExternalURL: "https://wb1.xxxxx.fakecluster.tld/" },
+                Workbench2: { ExternalURL: "https://wb2.xxxxx.fakecluster.tld/" },
+              },
+              StorageClasses: {
+                default: { Default: true, Priority: 0 },
+              },
+              Users: {},
+              Volumes: {},
+              Workbench: {},
+            },
+          }
+        );
 
         cy.createCollection(adminUser.token, {
             name: colName,
@@ -138,6 +212,23 @@ describe('Search tests', function() {
         }).then(function(testCollection) {
             cy.loginAs(activeUser);
 
+            // Intercept search results to add federated result
+            cy.intercept({method: 'GET', url: '**/arvados/v1/groups/contents?*'}, (req) => {
+                req.reply((res) => {
+                    res.body.items = [
+                        res.body.items[0],
+                        {
+                            ...res.body.items[0],
+                            uuid: federatedColUuid,
+                            portable_data_hash: "00000000000000000000000000000000+0",
+                            name: federatedColName,
+                            href: res.body.items[0].href.replace(testCollection.uuid, federatedColUuid),
+                        }
+                    ];
+                    res.body.items_available += 1;
+                });
+            });
+
             cy.doSearch(colName);
 
             // Stub new window
@@ -145,6 +236,7 @@ describe('Search tests', function() {
                 cy.stub(win, 'open').as('Open')
             });
 
+            // Check copy to clipboard
             cy.get('[data-cy=search-results]').contains(colName).rightclick();
             cy.get('[data-cy=context-menu]').within((ctx) => {
                 // Check that there are 4 items in the menu
@@ -155,21 +247,37 @@ describe('Search tests', function() {
                 cy.contains('View details');
 
                 cy.contains('Copy to clipboard').click();
-                cy.window().then((win) => {
+                cy.window().then((win) => (
                     win.navigator.clipboard.readText().then((text) => {
-                        expect(text).to.endWith(`/collections/${testCollection.uuid}`);
-                    });
-                });
-
+                        expect(text).to.match(new RegExp(`/collections/${testCollection.uuid}$`));
+                    })
+                ));
             });
 
-
+            // Check open in new tab
             cy.get('[data-cy=search-results]').contains(colName).rightclick();
-            cy.get('[data-cy=context-menu]').within((ctx) => {
+            cy.get('[data-cy=context-menu]').within(() => {
                 cy.contains('Open in new tab').click();
                 cy.get('@Open').should('have.been.calledOnceWith', `${window.location.origin}/collections/${testCollection.uuid}`)
             });
 
+            // Check federated result copy to clipboard
+            cy.get('[data-cy=search-results]').contains(federatedColName).rightclick();
+            cy.get('[data-cy=context-menu]').within(() => {
+                cy.contains('Copy to clipboard').click();
+                cy.window().then((win) => (
+                    win.navigator.clipboard.readText().then((text) => {
+                        expect(text).to.equal(`https://wb2.xxxxx.fakecluster.tld/collections/${federatedColUuid}`);
+                    })
+                ));
+            });
+            // Check open in new tab
+            cy.get('[data-cy=search-results]').contains(federatedColName).rightclick();
+            cy.get('[data-cy=context-menu]').within(() => {
+                cy.contains('Open in new tab').click();
+                cy.get('@Open').should('have.been.calledWith', `https://wb2.xxxxx.fakecluster.tld/collections/${federatedColUuid}`)
+            });
+
         });
     });
 });