BigW Consortium Gitlab

sorting_spec.rb 3.32 KB
Newer Older
1 2 3 4 5 6 7 8
require 'spec_helper'

feature 'Groups > Members > Sorting', feature: true do
  let(:owner)     { create(:user, name: 'John Doe') }
  let(:developer) { create(:user, name: 'Mary Jane', last_sign_in_at: 5.days.ago) }
  let(:group)     { create(:group) }

  background do
9 10
    create(:group_member, :owner, user: owner, group: group, created_at: 5.days.ago)
    create(:group_member, :developer, user: developer, group: group, created_at: 3.days.ago)
11 12 13 14

    login_as(owner)
  end

15 16 17 18 19
  scenario 'sorts alphabetically by default' do
    visit_members_list(sort: nil)

    expect(first_member).to include(owner.name)
    expect(second_member).to include(developer.name)
20
    expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Name, ascending')
21 22
  end

23 24 25 26 27
  scenario 'sorts by access level ascending' do
    visit_members_list(sort: :access_level_asc)

    expect(first_member).to include(developer.name)
    expect(second_member).to include(owner.name)
28
    expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Access level, ascending')
29 30 31 32 33 34 35
  end

  scenario 'sorts by access level descending' do
    visit_members_list(sort: :access_level_desc)

    expect(first_member).to include(owner.name)
    expect(second_member).to include(developer.name)
36
    expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Access level, descending')
37 38 39 40 41 42 43
  end

  scenario 'sorts by last joined' do
    visit_members_list(sort: :last_joined)

    expect(first_member).to include(developer.name)
    expect(second_member).to include(owner.name)
44
    expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Last joined')
45 46 47 48 49 50 51
  end

  scenario 'sorts by oldest joined' do
    visit_members_list(sort: :oldest_joined)

    expect(first_member).to include(owner.name)
    expect(second_member).to include(developer.name)
52
    expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Oldest joined')
53 54 55 56 57 58 59
  end

  scenario 'sorts by name ascending' do
    visit_members_list(sort: :name_asc)

    expect(first_member).to include(owner.name)
    expect(second_member).to include(developer.name)
60
    expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Name, ascending')
61 62 63 64 65 66 67
  end

  scenario 'sorts by name descending' do
    visit_members_list(sort: :name_desc)

    expect(first_member).to include(developer.name)
    expect(second_member).to include(owner.name)
68
    expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Name, descending')
69 70 71 72 73 74 75
  end

  scenario 'sorts by recent sign in' do
    visit_members_list(sort: :recent_sign_in)

    expect(first_member).to include(owner.name)
    expect(second_member).to include(developer.name)
76
    expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Recent sign in')
77 78 79 80 81 82 83
  end

  scenario 'sorts by oldest sign in' do
    visit_members_list(sort: :oldest_sign_in)

    expect(first_member).to include(developer.name)
    expect(second_member).to include(owner.name)
84
    expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Oldest sign in')
85 86 87 88 89 90 91 92 93 94 95 96 97 98
  end

  def visit_members_list(sort:)
    visit group_group_members_path(group.to_param, sort: sort)
  end

  def first_member
    page.all('ul.content-list > li').first.text
  end

  def second_member
    page.all('ul.content-list > li').last.text
  end
end