groups_list_spec.rb 3.92 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Dashboard Groups page', js: true, feature: true do
4 5 6 7 8
  let!(:user) { create :user }
  let!(:group) { create(:group) }
  let!(:nested_group) { create(:group, :nested) }
  let!(:another_group) { create(:group) }

9
  it 'shows groups user is member of' do
10 11 12 13 14 15 16 17 18 19 20
    group.add_owner(user)
    nested_group.add_owner(user)

    login_as(user)
    visit dashboard_groups_path

    expect(page).to have_content(group.full_name)
    expect(page).to have_content(nested_group.full_name)
    expect(page).not_to have_content(another_group.full_name)
  end

21 22 23 24
  describe 'when filtering groups' do
    before do
      group.add_owner(user)
      nested_group.add_owner(user)
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
      login_as(user)

      visit dashboard_groups_path
    end

    it 'filters groups' do
      fill_in 'filter_groups', with: group.name
      wait_for_requests

      expect(page).to have_content(group.full_name)
      expect(page).not_to have_content(nested_group.full_name)
      expect(page).not_to have_content(another_group.full_name)
    end

    it 'resets search when user cleans the input' do
      fill_in 'filter_groups', with: group.name
      wait_for_requests

      fill_in 'filter_groups', with: ""
      wait_for_requests

      expect(page).to have_content(group.full_name)
      expect(page).to have_content(nested_group.full_name)
      expect(page).not_to have_content(another_group.full_name)
      expect(page.all('.js-groups-list-holder .content-list li').length).to eq 2
    end
52
  end
53

54 55
  describe 'group with subgroups' do
    let!(:subgroup) { create(:group, :public, parent: group) }
56

57 58 59
    before do
      group.add_owner(user)
      subgroup.add_owner(user)
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
      login_as(user)

      visit dashboard_groups_path
    end

    it 'shows subgroups inside of its parent group' do
      expect(page).to have_selector('.groups-list-tree-container .group-list-tree', count: 2)
      expect(page).to have_selector(".groups-list-tree-container #group-#{group.id} #group-#{subgroup.id}", count: 1)
    end

    it 'can toggle parent group' do
      # Expanded by default
      expect(page).to have_selector("#group-#{group.id} .fa-caret-down", count: 1)
      expect(page).not_to have_selector("#group-#{group.id} .fa-caret-right")

      # Collapse
      find("#group-#{group.id}").trigger('click')

      expect(page).not_to have_selector("#group-#{group.id} .fa-caret-down")
      expect(page).to have_selector("#group-#{group.id} .fa-caret-right", count: 1)
      expect(page).not_to have_selector("#group-#{group.id} #group-#{subgroup.id}")

      # Expand
      find("#group-#{group.id}").trigger('click')

      expect(page).to have_selector("#group-#{group.id} .fa-caret-down", count: 1)
      expect(page).not_to have_selector("#group-#{group.id} .fa-caret-right")
      expect(page).to have_selector("#group-#{group.id} #group-#{subgroup.id}")
    end
  end

  describe 'when using pagination' do
    let(:group2) { create(:group) }

    before do
      group.add_owner(user)
      group2.add_owner(user)

      allow(Kaminari.config).to receive(:default_per_page).and_return(1)

      login_as(user)
      visit dashboard_groups_path
    end

    it 'shows pagination' do
      expect(page).to have_selector('.gl-pagination')
      expect(page).to have_selector('.gl-pagination .page', count: 2)
    end

    it 'loads results for next page' do
      # Check first page
      expect(page).to have_content(group2.full_name)
      expect(page).to have_selector("#group-#{group2.id}")
      expect(page).not_to have_content(group.full_name)
      expect(page).not_to have_selector("#group-#{group.id}")

      # Go to next page
      find(".gl-pagination .page:not(.active) a").trigger('click')

      wait_for_requests

      # Check second page
      expect(page).to have_content(group.full_name)
      expect(page).to have_selector("#group-#{group.id}")
      expect(page).not_to have_content(group2.full_name)
      expect(page).not_to have_selector("#group-#{group2.id}")
    end
128
  end
129
end