+ def check_sharing(want_state, link_regexp)
+ # We specifically want to click buttons. See #4291.
+ if want_state == :off
+ click_button "Unshare"
+ text_assertion = :assert_no_text
+ link_assertion = :assert_empty
+ else
+ click_button "Create sharing link"
+ text_assertion = :assert_text
+ link_assertion = :refute_empty
+ end
+ using_wait_time(Capybara.default_wait_time * 3) do
+ send(text_assertion, "Shared at:")
+ end
+ send(link_assertion, all("a").select { |a| a[:href] =~ link_regexp })
+ end
+
+ test "creating and uncreating a sharing link" do
+ coll_uuid = api_fixture("collections", "collection_owned_by_active", "uuid")
+ download_link_re =
+ Regexp.new(Regexp.escape("/collections/download/#{coll_uuid}/"))
+ visit page_with_token("active_trustedclient", "/collections/#{coll_uuid}")
+ within "#sharing-button" do
+ check_sharing(:on, download_link_re)
+ check_sharing(:off, download_link_re)
+ end
+ end
+