Skip to content

Commit

Permalink
✅ Test copying to clipboard, also on the join page
Browse files Browse the repository at this point in the history
Why:
- There is a risk of breaking that feature when removing the SPA site,
  because the clipboard code is in same files as the React components.
  • Loading branch information
luontola committed Jul 17, 2024
1 parent 5818e5e commit 8782834
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
36 changes: 22 additions & 14 deletions test/territory_bro/browser_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
(def auth0-username "[email protected]")
(def auth0-password "m6ER6MU7bBYEHrByt8lyop3cG1W811r2")

(def browser-config
{:size [1920 1080]
;; TODO: figure out how to enable reading what the browser copied to clipboard
#_#_:prefs {:profile.content_settings.exceptions.clipboard {"*" {"setting" 1
"last_modified" (System/currentTimeMillis)}}}})
(def browser-config {:size [1920 1080]})
(def postmortem-dir (io/file "target/etaoin-postmortem"))

(defn per-test-subdir [parent-dir]
Expand Down Expand Up @@ -60,6 +56,11 @@
(b/wait-visible q)
(b/click q)))

(defn clipboard-content [driver]
;; Headless Chrome won't modify the system clipboard, so the browser tests
;; don't have a direct method for observing what was copied to clipboard.
(b/js-execute driver "return window.latestCopyToClipboard"))

(defn submit-auth0-login-form [driver]
(doto driver
(b/wait-visible :username)
Expand Down Expand Up @@ -196,9 +197,11 @@
(wait-and-click {:tag :button, :fn/has-string "Share a link"})
(wait-and-click :copy-share-link))
(let [original-url (b/get-url *driver*)
share-link (b/js-execute *driver* "return window.latestCopyToClipboard")]
share-link (b/get-element-value *driver* :share-link)]
(is (str/includes? share-link "/share/demo-")
"generates a demo share link")
(is (= share-link (clipboard-content *driver*))
"can copy to clipboard")

(testing "- open the share"
(doto *driver*
Expand Down Expand Up @@ -253,11 +256,13 @@
(testing "find out user2's ID"
(doto *driver*
(dev-login-as user2)
(go-to-page "Join an existing congregation"))

(let [user2-id (b/get-element-text *driver* :your-user-id)]
(is (some? (parse-uuid user2-id)))
(reset! *user2-id user2-id)))
(go-to-page "Join an existing congregation")
(wait-and-click :copy-your-user-id))
(let [user2-id (reset! *user2-id (b/get-element-text *driver* :your-user-id))]
(is (some? (parse-uuid user2-id))
"shows the user ID")
(is (= user2-id (clipboard-content *driver*))
"can copy to clipboard")))

(testing "add user2 to congregation"
(doto *driver*
Expand Down Expand Up @@ -320,9 +325,12 @@
(doto *driver*
(wait-and-click {:tag :button, :fn/has-string "Share a link"})
(wait-and-click :copy-share-link))
(let [share-link (b/js-execute *driver* "return window.latestCopyToClipboard")]
(is (str/starts-with? share-link (str *base-url* "/share/"))
"generates a share link")
(let [share-link (b/get-element-value *driver* :share-link)]
(testing "share a link"
(is (str/starts-with? share-link (str *base-url* "/share/"))
"generates a share link")
(is (= share-link (clipboard-content *driver*))
"can copy to clipboard"))

(testing "open shared link as anonymous user"
(doto *driver*
Expand Down
2 changes: 1 addition & 1 deletion web/src/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import ClipboardJS from "clipboard";
export function installCopyToClipboard(target: string) {
const clipboard = new ClipboardJS(target);
clipboard.on('success', (event) => {
(window as any).latestCopyToClipboard = event.text;
(window as any).latestCopyToClipboard = event.text; // expose for tests
});
}

0 comments on commit 8782834

Please sign in to comment.