3686: ensure Advanced is always the last pane even after adding the Sharing pane.
[arvados.git] / apps / workbench / test / helpers / share_object_helper.rb
1 module ShareObjectHelper
2   def show_object_using(auth_key, type, key, expect)
3     obj_uuid = api_fixture(type)[key]['uuid']
4     visit(page_with_token(auth_key, "/#{type}/#{obj_uuid}"))
5     assert(page.has_text?(expect), "expected string not found: #{expect}")
6   end
7
8   def share_rows
9     find('#object_sharing').all('tr')
10   end
11
12   def add_share_and_check(share_type, name, obj=nil)
13     assert(page.has_no_text?(name), "project is already shared with #{name}")
14     start_share_count = share_rows.size
15     click_on("Share with #{share_type}")
16     within(".modal-container") do
17       # Order is important here: we should find something that appears in the
18       # modal before we make any assertions about what's not in the modal.
19       # Otherwise, the not-included assertions might falsely pass because
20       # the modal hasn't loaded yet.
21       find(".selectable", text: name).click
22       assert(has_no_selector?(".modal-dialog-preview-pane"),
23              "preview pane available in sharing dialog")
24       if share_type == 'users' and obj and obj['email']
25         assert(page.has_text?(obj['email']), "Did not find user's email")
26       end
27       assert_raises(Capybara::ElementNotFound,
28                     "Projects pulldown available from sharing dialog") do
29         click_on "All projects"
30       end
31       click_on "Add"
32     end
33     using_wait_time(Capybara.default_wait_time * 3) do
34       assert(page.has_link?(name),
35              "new share was not added to sharing table")
36       assert_equal(start_share_count + 1, share_rows.size,
37                    "new share did not add row to sharing table")
38     end
39   end
40
41   def modify_share_and_check(name)
42     start_rows = share_rows
43     link_row = start_rows.select { |row| row.has_text?(name) }
44     assert_equal(1, link_row.size, "row with new permission not found")
45     within(link_row.first) do
46       click_on("Read")
47       select("Write", from: "share_change_level")
48       click_on("editable-submit")
49       assert(has_link?("Write"),
50              "failed to change access level on new share")
51       click_on "Revoke"
52       if Capybara.current_driver == :selenium
53         page.driver.browser.switch_to.alert.accept
54       else
55         # poltergeist returns true for confirm(), so we don't need to accept.
56       end
57     end
58     wait_for_ajax
59     using_wait_time(Capybara.default_wait_time * 3) do
60       assert(page.has_no_text?(name),
61              "new share row still exists after being revoked")
62       assert_equal(start_rows.size - 1, share_rows.size,
63                    "revoking share did not remove row from sharing table")
64     end
65   end
66
67   def user_can_manage(user_sym, fixture)
68     get(:show, {id: fixture["uuid"]}, session_for(user_sym))
69     is_manager = assigns(:user_is_manager)
70     assert_not_nil(is_manager, "user_is_manager flag not set")
71     if not is_manager
72       assert_empty(assigns(:share_links),
73                    "non-manager has share links set")
74     end
75     is_manager
76   end
77
78 end