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

inviting_groups_shared_examples.rb « features « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4921676a0656ec92cb8beac75d6bb5398b581db9 (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
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
# frozen_string_literal: true

RSpec.shared_examples 'inviting groups search results' do
  context 'with instance admin considerations' do
    let_it_be(:group_to_invite) { create(:group) }

    context 'when user is an admin' do
      let_it_be(:admin) { create(:admin) }

      before do
        sign_in(admin)
        gitlab_enable_admin_mode_sign_in(admin)
      end

      it 'shows groups where the admin has no direct membership' do
        visit members_page_path

        click_on 'Invite a group'
        click_on 'Select a group'
        wait_for_requests

        page.within(group_dropdown_selector) do
          expect_to_have_group(group_to_invite)
          expect_not_to_have_group(group)
        end
      end

      it 'shows groups where the admin has at least guest level membership' do
        group_to_invite.add_guest(admin)

        visit members_page_path

        click_on 'Invite a group'
        click_on 'Select a group'
        wait_for_requests

        page.within(group_dropdown_selector) do
          expect_to_have_group(group_to_invite)
          expect_not_to_have_group(group)
        end
      end
    end

    context 'when user is not an admin' do
      before do
        group.add_owner(user)
        sign_in(user)
      end

      it 'does not show groups where the user has no direct membership' do
        visit members_page_path

        click_on 'Invite a group'
        click_on 'Select a group'
        wait_for_requests

        page.within(group_dropdown_selector) do
          expect_not_to_have_group(group_to_invite)
          expect_not_to_have_group(group)
        end
      end

      it 'shows groups where the user has at least guest level membership' do
        group_to_invite.add_guest(user)

        visit members_page_path

        click_on 'Invite a group'
        click_on 'Select a group'
        wait_for_requests

        page.within(group_dropdown_selector) do
          expect_to_have_group(group_to_invite)
          expect_not_to_have_group(group)
        end
      end
    end
  end

  context 'when user is not an admin and there are hierarchy considerations' do
    let_it_be(:group_outside_hierarchy) { create(:group) }

    before_all do
      group.add_owner(user)
      group_within_hierarchy.add_owner(user)
      group_outside_hierarchy.add_owner(user)
    end

    before do
      sign_in(user)
    end

    it 'does not show self or ancestors', :aggregate_failures do
      group_sibling = create(:group, parent: group)
      group_sibling.add_owner(user)

      visit members_page_path_within_hierarchy

      click_on 'Invite a group'
      click_on 'Select a group'
      wait_for_requests

      page.within(group_dropdown_selector) do
        expect_to_have_group(group_outside_hierarchy)
        expect_to_have_group(group_sibling)
        expect_not_to_have_group(group)
        expect_not_to_have_group(group_within_hierarchy)
      end
    end

    context 'when sharing with groups outside the hierarchy is enabled' do
      it 'shows groups within and outside the hierarchy in search results' do
        visit members_page_path

        click_on 'Invite a group'
        click_on 'Select a group'
        wait_for_requests

        page.within(group_dropdown_selector) do
          expect_to_have_group(group_within_hierarchy)
          expect_to_have_group(group_outside_hierarchy)
        end
      end
    end

    context 'when sharing with groups outside the hierarchy is disabled' do
      before do
        group.update!(prevent_sharing_groups_outside_hierarchy: true)
      end

      it 'shows only groups within the hierarchy in search results' do
        visit members_page_path

        click_on 'Invite a group'
        click_on 'Select a group'

        page.within(group_dropdown_selector) do
          expect_to_have_group(group_within_hierarchy)
          expect_not_to_have_group(group_outside_hierarchy)
        end
      end
    end
  end
end