Skip to content

Commit

Permalink
Order sections by name without prefix, (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaierhofer committed May 10, 2024
1 parent 3aa05d3 commit f381f2d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/helpers/sac_cas/sheet/group/nav_left.rb
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas

module SacCas::Sheet::Group::NavLeft
NAME_WITHOUT_PREFIX = "REPLACE(REPLACE(name, 'SAC ', ''), 'CAS ', '')".freeze

private

def sub_layers
return super unless @entry.root?

super.reorder(Arel.sql(NAME_WITHOUT_PREFIX))
end
end
1 change: 1 addition & 0 deletions lib/hitobito_sac_cas/wagon.rb
Expand Up @@ -102,6 +102,7 @@ class Wagon < Rails::Engine
Dropdown::PeopleExport.prepend SacCas::Dropdown::PeopleExport
Dropdown::TableDisplays.prepend SacCas::Dropdown::TableDisplays
Event::ParticipationButtons.prepend SacCas::Event::ParticipationButtons
Sheet::Group::NavLeft.prepend SacCas::Sheet::Group::NavLeft

admin_item = NavigationHelper::MAIN.find { |item| item[:label] == :admin }
admin_item[:active_for] += %w(cost_centers cost_units)
Expand Down
45 changes: 45 additions & 0 deletions spec/helpers/sheet/group/nav_left_spec.rb
@@ -0,0 +1,45 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas

require 'spec_helper'

describe 'Sheet::Group::NavLeft' do
let(:group) { groups(:root) }
let(:sheet) { Sheet::Group.new(self, nil, group) }
let(:nav) { Sheet::Group::NavLeft.new(sheet) }

let(:request) { ActionController::TestRequest.create({}) }

let(:html) { nav.render }
subject(:dom) { Capybara::Node::Simple.new(html) }

def can?(*_args)
true
end

describe 'ordering of sections' do
let(:links) { dom.all('li').map(&:text) }
let(:sections) { links[links.index('Sektionen')+1..] }
let(:bluemlisalp) { groups(:bluemlisalp) }
let(:matterhorn) { groups(:matterhorn) }

it 'orders sections by name' do
expect(sections).to eq ['SAC Blüemlisalp', 'SAC Matterhorn']
end

it 'ignores cas prefix' do
matterhorn.update!(name: 'CAS Matterhorn')
expect(sections).to eq ['SAC Blüemlisalp', 'CAS Matterhorn']
end

it 'ignores sac prefix' do
bluemlisalp.update!(name: 'CAS Blüemlisalp')
matterhorn.update!(name: 'SAC Altels')
expect(sections).to eq ['SAC Altels', 'CAS Blüemlisalp']
end
end
end

0 comments on commit f381f2d

Please sign in to comment.