admin_groups_spec.rb 4.1 KB
Newer Older
1 2 3
require 'spec_helper'

feature 'Admin Groups', feature: true do
4 5
  include Select2Helper

6
  let(:internal) { Gitlab::VisibilityLevel::INTERNAL }
7 8 9
  let(:user) { create :user }
  let!(:group) { create :group }
  let!(:current_user) { login_as :admin }
10 11 12 13 14

  before do
    stub_application_setting(default_group_visibility: internal)
  end

15 16 17 18 19 20 21 22
  describe 'list' do
    it 'renders groups' do
      visit admin_groups_path

      expect(page).to have_content(group.name)
    end
  end

23
  describe 'create a group' do
24 25 26 27 28 29 30 31 32 33 34 35 36
    it 'creates new group' do
      visit admin_groups_path

      click_link "New Group"
      fill_in 'group_path', with: 'gitlab'
      fill_in 'group_description', with: 'Group description'
      click_button "Create group"

      expect(current_path).to eq admin_group_path(Group.find_by(path: 'gitlab'))
      expect(page).to have_content('Group: gitlab')
      expect(page).to have_content('Group description')
    end

37 38 39 40 41 42 43
    scenario 'shows the visibility level radio populated with the default value' do
      visit new_admin_group_path

      expect_selected_visibility(internal)
    end
  end

44 45 46 47 48 49 50 51 52 53
  describe 'show a group' do
    scenario 'shows the group' do
      group = create(:group, :private)

      visit admin_group_path(group)

      expect(page).to have_content("Group: #{group.name}")
    end
  end

54 55 56 57
  describe 'group edit' do
    scenario 'shows the visibility level radio populated with the group visibility_level value' do
      group = create(:group, :private)

58
      visit admin_group_edit_path(group)
59 60 61 62 63

      expect_selected_visibility(group.visibility_level)
    end
  end

64 65 66 67 68 69 70 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  describe 'add user into a group', js: true do
    shared_context 'adds user into a group' do
      it do
        visit admin_group_path(group)

        select2(user_selector, from: '#user_ids', multiple: true)
        page.within '#new_project_member' do
          select2(Gitlab::Access::REPORTER, from: '#access_level')
        end
        click_button "Add users to group"
        page.within ".group-users-list" do
          expect(page).to have_content(user.name)
          expect(page).to have_content('Reporter')
        end
      end
    end

    it_behaves_like 'adds user into a group' do
      let(:user_selector) { user.id }
    end

    it_behaves_like 'adds user into a group' do
      let(:user_selector) { user.email }
    end
  end

  describe 'add admin himself to a group' do
    before do
      group.add_user(:user, Gitlab::Access::OWNER)
    end

    it 'adds admin a to a group as developer', js: true do
      visit group_group_members_path(group)

      page.within '.users-group-form' do
        select2(current_user.id, from: '#user_ids', multiple: true)
        select 'Developer', from: 'access_level'
      end

      click_button 'Add to group'

      page.within '.content-list' do
        expect(page).to have_content(current_user.name)
        expect(page).to have_content('Developer')
      end
    end
  end

  describe 'admin remove himself from a group', js: true do
    it 'removes admin from the group' do
      group.add_user(current_user, Gitlab::Access::DEVELOPER)

      visit group_group_members_path(group)

      page.within '.content-list' do
        expect(page).to have_content(current_user.name)
        expect(page).to have_content('Developer')
      end

      find(:css, 'li', text: current_user.name).find(:css, 'a.btn-remove').click

      visit group_group_members_path(group)

      page.within '.content-list' do
        expect(page).not_to have_content(current_user.name)
        expect(page).not_to have_content('Developer')
      end
    end
  end

  describe 'shared projects' do
    it 'renders shared project' do
      empty_project = create(:empty_project)
      empty_project.project_group_links.create!(
        group_access: Gitlab::Access::MASTER,
        group: group
      )

      visit admin_group_path(group)

      expect(page).to have_content(empty_project.name_with_namespace)
      expect(page).to have_content('Projects shared with')
    end
  end

149 150 151 152 153 154
  def expect_selected_visibility(level)
    selector = "#group_visibility_level_#{level}[checked=checked]"

    expect(page).to have_selector(selector, count: 1)
  end
end