Welcome to mirror list, hosted at ThFree Co, Russian Federation.

leave_group_spec.rb « members « groups « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 85255187457595d7ecdab5fe294690939bda44c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Groups > Members > Leave group', feature_category: :groups_and_projects do
  include Features::MembersHelpers
  include Spec::Support::Helpers::ModalHelpers

  let(:user) { create(:user) }
  let(:other_user) { create(:user) }
  let(:group) { create(:group) }
  let(:more_actions_dropdown) do
    find('[data-testid="groups-projects-more-actions-dropdown"] .gl-new-dropdown-custom-toggle')
  end

  before do
    sign_in(user)
  end

  it 'guest leaves the group', :js do
    group.add_guest(user)
    group.add_owner(other_user)

    visit group_path(group)
    more_actions_dropdown.click
    click_link 'Leave group'
    accept_gl_confirm(button_text: 'Leave group')

    expect(page).to have_current_path(dashboard_groups_path, ignore_query: true)
    expect(page).to have_content left_group_message(group)
    expect(group).not_to have_user(user)
  end

  it 'guest leaves the group by url param', :js do
    group.add_guest(user)
    group.add_owner(other_user)

    visit group_path(group, leave: 1)
    accept_gl_confirm(button_text: 'Leave group')

    expect(page).to have_current_path(dashboard_groups_path, ignore_query: true)
    expect(group).not_to have_user(user)
  end

  it 'guest leaves the group as last member', :js do
    group.add_guest(user)

    visit group_path(group)
    more_actions_dropdown.click
    click_link 'Leave group'
    accept_gl_confirm(button_text: 'Leave group')

    expect(page).to have_current_path(dashboard_groups_path, ignore_query: true)
    expect(page).to have_content left_group_message(group)
    expect(group).not_to have_user(user)
  end

  it 'owner leaves the group if they are not the last owner', :js do
    group.add_owner(user)
    group.add_owner(other_user)

    visit group_path(group)
    more_actions_dropdown.click
    click_link 'Leave group'
    accept_gl_confirm(button_text: 'Leave group')

    expect(page).to have_current_path(dashboard_groups_path, ignore_query: true)
    expect(page).to have_content left_group_message(group)
    expect(group).not_to have_user(user)
  end

  it 'owner can not leave the group if they are the last owner', :js do
    group.add_owner(user)

    visit group_path(group)
    more_actions_dropdown.click

    expect(page).not_to have_content 'Leave group'

    visit group_group_members_path(group)

    expect(members_table).not_to have_selector 'button[title="Leave"]'
  end

  it 'owner can not leave the group by url param if they are the last owner', :js do
    group.add_owner(user)

    visit group_path(group, leave: 1)

    expect(find_by_testid('alert-danger')).to have_content 'You do not have permission to leave this group'
  end

  def left_group_message(group)
    "You left the \"#{group.name}\""
  end
end