groups_list_spec.rb 2.77 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'spec_helper'

5
describe 'Explore Groups page', :js do
6 7 8 9
  let!(:user) { create :user }
  let!(:group) { create(:group) }
  let!(:public_group) { create(:group, :public) }
  let!(:private_group) { create(:group, :private) }
10
  let!(:empty_project) { create(:project, group: public_group) }
11 12 13 14

  before do
    group.add_owner(user)

15
    sign_in(user)
16 17

    visit explore_groups_path
18
    wait_for_requests
19 20 21 22 23 24 25 26 27
  end

  it 'shows groups user is member of' do
    expect(page).to have_content(group.full_name)
    expect(page).to have_content(public_group.full_name)
    expect(page).not_to have_content(private_group.full_name)
  end

  it 'filters groups' do
28
    fill_in 'filter', with: group.name
29
    wait_for_requests
30 31 32 33 34

    expect(page).to have_content(group.full_name)
    expect(page).not_to have_content(public_group.full_name)
    expect(page).not_to have_content(private_group.full_name)
  end
35 36

  it 'resets search when user cleans the input' do
37
    fill_in 'filter', with: group.name
38
    wait_for_requests
39

40 41 42
    expect(page).to have_content(group.full_name)
    expect(page).not_to have_content(public_group.full_name)

43
    fill_in 'filter', with: ""
44
    page.find('[name="filter"]').send_keys(:enter)
45
    wait_for_requests
46 47 48 49 50 51

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

  it 'shows non-archived projects count' do
    # Initially project is not archived
55
    expect(find('.js-groups-list-holder .content-list li:first-child .stats .number-projects')).to have_text("1")
56

57
    # Archive project
58
    ::Projects::UpdateService.new(empty_project, user, archived: true).execute
59 60 61
    visit explore_groups_path

    # Check project count
62
    expect(find('.js-groups-list-holder .content-list li:first-child .stats .number-projects')).to have_text("0")
63

64
    # Unarchive project
65
    ::Projects::UpdateService.new(empty_project, user, archived: false).execute
66 67 68
    visit explore_groups_path

    # Check project count
69
    expect(find('.js-groups-list-holder .content-list li:first-child .stats .number-projects')).to have_text("1")
70 71 72
  end

  describe 'landing component' do
73
    it 'shows a landing component' do
74 75 76
      expect(page).to have_content('Below you will find all the groups that are public.')
    end

77
    it 'is dismissable' do
78 79 80 81 82
      find('.dismiss-button').click

      expect(page).not_to have_content('Below you will find all the groups that are public.')
    end

83
    it 'does not show persistently once dismissed' do
84 85 86 87 88 89
      find('.dismiss-button').click

      visit explore_groups_path

      expect(page).not_to have_content('Below you will find all the groups that are public.')
    end
90
  end
91
end