Merge branch '19567-copy-to-clipboard' into main. Closes #19567
authorStephen Smith <stephen@curii.com>
Thu, 22 Sep 2022 15:45:24 +0000 (11:45 -0400)
committerStephen Smith <stephen@curii.com>
Thu, 22 Sep 2022 15:45:24 +0000 (11:45 -0400)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

cypress/integration/project.spec.js
src/store/open-in-new-tab/open-in-new-tab.actions.ts

index 9c5e791cda64c849fb6ca15c4cc1d1ec39141982..ea795e6c393a23fa1edb33783c65322d0e72985a 100644 (file)
@@ -311,4 +311,30 @@ describe('Project tests', function() {
                 });
         });
     });
+
+    it('copies project URL to clipboard', () => {
+        const projectName = `Test project (${Math.floor(999999 * Math.random())})`;
+
+        cy.loginAs(activeUser);
+        cy.get('[data-cy=side-panel-button]').click();
+        cy.get('[data-cy=side-panel-new-project]').click();
+        cy.get('[data-cy=form-dialog]')
+            .should('contain', 'New Project')
+            .within(() => {
+                cy.get('[data-cy=name-field]').within(() => {
+                    cy.get('input').type(projectName);
+                });
+                cy.get('[data-cy=form-submit-btn]').click();
+            });
+
+        cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
+        cy.get('[data-cy=project-panel]').contains(projectName).rightclick();
+        cy.get('[data-cy=context-menu]').contains('Copy to clipboard').click();
+        cy.window().then((win) => (
+            win.navigator.clipboard.readText().then((text) => {
+                expect(text).to.match(/https\:\/\/localhost\:[0-9]+\/projects\/[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/,);
+            })
+        ));
+
+    });
 });
index c465aae8695a51291918aa0fd630e57fe8b327c6..6b9db6a538e1322004f14138b4e45b0bd8b53a73 100644 (file)
@@ -21,7 +21,9 @@ export const copyToClipboardAction = (resource: any) => (dispatch: Dispatch, get
     // Copy to clipboard omits token to avoid accidental sharing
     const url = getNavUrl(resource.uuid, getState().auth, false);
 
-    if (url) {
+    if (url[0] === '/') {
+        copy(`${window.location.origin}${url}`);
+    } else if (url.length) {
         copy(url);
     }
 };