BigW Consortium Gitlab

members.rb 4.1 KB
Newer Older
1
class Spinach::Features::GroupMembers < Spinach::FeatureSteps
Phil Hughes committed
2
  include WaitForAjax
3 4 5 6 7 8 9 10 11 12 13 14 15 16
  include SharedAuthentication
  include SharedPaths
  include SharedGroup
  include SharedUser
  include Select2Helper

  step 'I select "Mike" as "Reporter"' do
    user = User.find_by(name: "Mike")

    page.within ".users-group-form" do
      select2(user.id, from: "#user_ids", multiple: true)
      select "Reporter", from: "access_level"
    end

Phil Hughes committed
17
    click_button "Add to group"
18 19 20 21 22 23 24 25 26 27
  end

  step 'I select "Mike" as "Master"' do
    user = User.find_by(name: "Mike")

    page.within ".users-group-form" do
      select2(user.id, from: "#user_ids", multiple: true)
      select "Master", from: "access_level"
    end

Phil Hughes committed
28
    click_button "Add to group"
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  end

  step 'I should see "Mike" in team list as "Reporter"' do
    page.within '.content-list' do
      expect(page).to have_content('Mike')
      expect(page).to have_content('Reporter')
    end
  end

  step 'I should see "Mike" in team list as "Owner"' do
    page.within '.content-list' do
      expect(page).to have_content('Mike')
      expect(page).to have_content('Owner')
    end
  end

  step 'I select "sjobs@apple.com" as "Reporter"' do
    page.within ".users-group-form" do
      select2("sjobs@apple.com", from: "#user_ids", multiple: true)
      select "Reporter", from: "access_level"
    end

Phil Hughes committed
51
    click_button "Add to group"
52 53 54 55 56
  end

  step 'I should see "sjobs@apple.com" in team list as invited "Reporter"' do
    page.within '.content-list' do
      expect(page).to have_content('sjobs@apple.com')
57
      expect(page).to have_content('Invited')
58 59 60 61 62 63 64 65 66 67 68 69
      expect(page).to have_content('Reporter')
    end
  end

  step 'I select user "Mary Jane" from list with role "Reporter"' do
    user = User.find_by(name: "Mary Jane") || create(:user, name: "Mary Jane")

    page.within ".users-group-form" do
      select2(user.id, from: "#user_ids", multiple: true)
      select "Reporter", from: "access_level"
    end

Phil Hughes committed
70
    click_button "Add to group"
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  end

  step 'I should see user "John Doe" in team list' do
    expect(group_members_list).to have_content("John Doe")
  end

  step 'I should not see user "John Doe" in team list' do
    expect(group_members_list).not_to have_content("John Doe")
  end

  step 'I should see user "Mary Jane" in team list' do
    expect(group_members_list).to have_content("Mary Jane")
  end

  step 'I should not see user "Mary Jane" in team list' do
    expect(group_members_list).not_to have_content("Mary Jane")
  end

  step 'I click on the "Remove User From Group" button for "John Doe"' do
    find(:css, 'li', text: "John Doe").find(:css, 'a.btn-remove').click
    # poltergeist always confirms popups.
  end

  step 'I click on the "Remove User From Group" button for "Mary Jane"' do
    find(:css, 'li', text: "Mary Jane").find(:css, 'a.btn-remove').click
    # poltergeist always confirms popups.
  end

  step 'I should not see the "Remove User From Group" button for "John Doe"' do
    expect(find(:css, 'li', text: "John Doe")).not_to have_selector(:css, 'a.btn-remove')
    # poltergeist always confirms popups.
  end

  step 'I should not see the "Remove User From Group" button for "Mary Jane"' do
    expect(find(:css, 'li', text: "Mary Jane")).not_to have_selector(:css, 'a.btn-remove')
    # poltergeist always confirms popups.
  end

  step 'I search for \'Mary\' member' do
    page.within '.member-search-form' do
      fill_in 'search', with: 'Mary'
Phil Hughes committed
112
      find('.member-search-btn').click
113 114 115 116 117 118 119
    end
  end

  step 'I change the "Mary Jane" role to "Developer"' do
    member = mary_jane_member

    page.within "#group_member_#{member.id}" do
120 121 122 123 124 125
      click_button member.human_access

      page.within '.dropdown-menu' do
        click_link 'Developer'
      end

Phil Hughes committed
126
      wait_for_ajax
127 128 129 130 131 132 133
    end
  end

  step 'I should see "Mary Jane" as "Developer"' do
    member = mary_jane_member

    page.within "#group_member_#{member.id}" do
134
      expect(page).to have_content "Developer"
135 136 137 138 139 140 141 142 143 144 145 146 147 148
    end
  end

  private

  def mary_jane_member
    user = User.find_by(name: "Mary Jane")
    owned_group.members.find_by(user_id: user.id)
  end

  def group_members_list
    find(".panel .content-list")
  end
end