summaryrefslogtreecommitdiff
path: root/spec/features/projects/members/tabs_spec.rb
blob: 232420224fc22235251fb02cc43b9d3e1093003f (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Projects > Members > Tabs', :js, feature_category: :subgroups do
  include Spec::Support::Helpers::Features::MembersHelpers
  using RSpec::Parameterized::TableSyntax

  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project, creator: user, namespace: user.namespace) }
  let_it_be(:group) { create(:group) }
  let_it_be(:project_members) { create_list(:project_member, 2, project: project) }
  let_it_be(:access_requests) { create_list(:project_member, 2, :access_request, project: project) }
  let_it_be(:invites) { create_list(:project_member, 2, :invited, project: project) }
  let_it_be(:project_group_links) { create_list(:project_group_link, 2, project: project) }

  before do
    sign_in(user)
    visit project_project_members_path(project)
  end

  shared_examples 'active "Members" tab' do
    it 'displays "Members" tab' do
      expect(page).to have_selector('.nav-link.active', text: 'Members')
    end
  end

  context 'tabs' do
    where(:tab, :count) do
      'Members'         | 3
      'Invited'         | 2
      'Groups'          | 2
      'Access requests' | 2
    end

    with_them do
      it "renders #{params[:tab]} tab" do
        expect(page).to have_selector('.nav-link', text: "#{tab} #{count}")
      end
    end

    context 'displays "Members" tab by default' do
      it_behaves_like 'active "Members" tab'
    end
  end

  context 'when searching "Groups"' do
    before do
      click_link 'Groups'

      fill_in_filtered_search 'Search groups', with: 'group'
    end

    it 'displays "Groups" tab' do
      expect(page).to have_selector('.nav-link.active', text: 'Groups')
    end

    context 'and then searching "Members"' do
      before do
        click_link 'Members 3'

        fill_in_filtered_search 'Filter members', with: 'user'
      end

      it_behaves_like 'active "Members" tab'
    end
  end
end