BigW Consortium Gitlab

groups_spec.rb 5.85 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Group' do
4
  before do
5
    sign_in(create(:admin))
6 7
  end

8 9 10 11 12 13
  matcher :have_namespace_error_message do
    match do |page|
      page.has_content?("Path can contain only letters, digits, '_', '-' and '.'. Cannot start with '-' or end in '.', '.git' or '.atom'.")
    end
  end

14
  describe 'create a group' do
15 16 17
    before do
      visit new_group_path
    end
18

19 20 21 22
    describe 'with space in group path' do
      it 'renders new group form with validation errors' do
        fill_in 'Group path', with: 'space group'
        click_button 'Create group'
23

24 25 26
        expect(current_path).to eq(groups_path)
        expect(page).to have_namespace_error_message
      end
27 28
    end

29 30 31 32
    describe 'with .atom at end of group path' do
      it 'renders new group form with validation errors' do
        fill_in 'Group path', with: 'atom_group.atom'
        click_button 'Create group'
33

34 35 36
        expect(current_path).to eq(groups_path)
        expect(page).to have_namespace_error_message
      end
37 38
    end

39 40 41 42
    describe 'with .git at end of group path' do
      it 'renders new group form with validation errors' do
        fill_in 'Group path', with: 'git_group.git'
        click_button 'Create group'
43

44 45 46
        expect(current_path).to eq(groups_path)
        expect(page).to have_namespace_error_message
      end
47
    end
48 49 50

    describe 'Mattermost team creation' do
      before do
51
        stub_mattermost_setting(enabled: mattermost_enabled)
52

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
        visit new_group_path
      end

      context 'Mattermost enabled' do
        let(:mattermost_enabled) { true }

        it 'displays a team creation checkbox' do
          expect(page).to have_selector('#group_create_chat_team')
        end

        it 'checks the checkbox by default' do
          expect(find('#group_create_chat_team')['checked']).to eq(true)
        end

        it 'updates the team URL on graph path update', :js do
68
          out_span = find('span[data-bind-out="create_chat_team"]', visible: false)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

          expect(out_span.text).to be_empty

          fill_in('group_path', with: 'test-group')

          expect(out_span.text).to eq('test-group')
        end
      end

      context 'Mattermost disabled' do
        let(:mattermost_enabled) { false }

        it 'doesnt show a team creation checkbox if Mattermost not enabled' do
          expect(page).not_to have_selector('#group_create_chat_team')
        end
      end
    end
86 87
  end

88
  describe 'create a nested group', :nested_groups, :js do
89 90
    let(:group) { create(:group, path: 'foo') }

91 92
    context 'as admin' do
      before do
93
        visit new_group_path(group, parent_id: group.id)
94 95 96 97 98 99 100 101 102
      end

      it 'creates a nested group' do
        fill_in 'Group path', with: 'bar'
        click_button 'Create group'

        expect(current_path).to eq(group_path('foo/bar'))
        expect(page).to have_content("Group 'bar' was successfully created.")
      end
103 104
    end

105
    context 'as group owner' do
106 107
      it 'creates a nested group' do
        user = create(:user)
108

109
        group.add_owner(user)
110 111
        sign_out(:user)
        sign_in(user)
112

113
        visit new_group_path(group, parent_id: group.id)
114

115 116 117 118 119 120
        fill_in 'Group path', with: 'bar'
        click_button 'Create group'

        expect(current_path).to eq(group_path('foo/bar'))
        expect(page).to have_content("Group 'bar' was successfully created.")
      end
121 122 123
    end
  end

124 125 126
  it 'checks permissions to avoid exposing groups by parent_id' do
    group = create(:group, :private, path: 'secret-group')

127 128
    sign_out(:user)
    sign_in(create(:user))
129 130 131 132 133
    visit new_group_path(parent_id: group.id)

    expect(page).not_to have_content('secret-group')
  end

134
  describe 'group edit', :js do
135 136
    let(:group) { create(:group) }
    let(:path)  { edit_group_path(group) }
137
    let(:new_name) { 'new-name' }
138

139 140 141
    before do
      visit path
    end
142

143 144
    it 'saves new settings' do
      fill_in 'group_name', with: new_name
145 146 147
      click_button 'Save group'

      expect(page).to have_content 'successfully updated'
148 149
      expect(find('#group_name').value).to eq(new_name)

Phil Hughes committed
150
      page.within ".breadcrumbs" do
151 152
        expect(page).to have_content new_name
      end
153 154 155
    end

    it 'removes group' do
156 157
      expect { remove_with_confirm('Remove group', group.path) }.to change {Group.count}.by(-1)
      expect(group.members.all.count).to be_zero
158 159 160 161
      expect(page).to have_content "scheduled for deletion"
    end
  end

162
  describe 'group page with markdown description' do
163 164 165 166 167
    let(:group) { create(:group) }
    let(:path)  { group_path(group) }

    it 'parses Markdown' do
      group.update_attribute(:description, 'This is **my** group')
168

169
      visit path
170

171
      expect(page).to have_css('.group-home-desc > p > strong')
172 173 174 175
    end

    it 'passes through html-pipeline' do
      group.update_attribute(:description, 'This group is the :poop:')
176

177
      visit path
178

179
      expect(page).to have_css('.group-home-desc > p > gl-emoji')
180 181 182 183
    end

    it 'sanitizes unwanted tags' do
      group.update_attribute(:description, '# Group Description')
184

185
      visit path
186

187
      expect(page).not_to have_css('.group-home-desc h1')
188 189 190 191
    end

    it 'permits `rel` attribute on links' do
      group.update_attribute(:description, 'https://google.com/')
192

193
      visit path
194

195
      expect(page).to have_css('.group-home-desc a[rel]')
196 197
    end
  end
198

199
  describe 'group page with nested groups', :nested_groups, :js do
200 201
    let!(:group) { create(:group) }
    let!(:nested_group) { create(:group, parent: group) }
202
    let!(:project) { create(:project, namespace: group) }
203 204
    let!(:path)  { group_path(group) }

205
    it 'it renders projects and groups on the page' do
206
      visit path
207
      wait_for_requests
208

209
      expect(page).to have_content(nested_group.name)
210
      expect(page).to have_content(project.name)
211 212
    end
  end
213 214 215 216 217 218

  def remove_with_confirm(button_text, confirm_with)
    click_button button_text
    fill_in 'confirm_name_input', with: confirm_with
    click_button 'Confirm'
  end
219
end