Verified Commit 452fd9ec authored by Markus Koller's avatar Markus Koller 🦊
Browse files

Fix filters on find_clients

parent ca3d2fa1
Pipeline #18835 passed with stage
in 52 minutes and 58 seconds
......@@ -73,10 +73,6 @@ module ApplicationHelper
c.translations[I18n.locale.to_s] || c.name
end
def request_filter(query, all)
params.try(:q).try(query) || all
end
def request_params_filter(query)
search_parameters.deep_merge(q: query)
end
......
......@@ -36,7 +36,10 @@ class Client < ApplicationRecord
has_many :journals, as: :journalable, dependent: :destroy
accepts_nested_attributes_for :journals, allow_destroy: true
validates :salutation, presence: true
validates :salutation, presence: true, inclusion: { in: SALUTATIONS.map(&:to_s) }
validates :gender_request, inclusion: { in: GENDER_REQUESTS.map(&:to_s), allow_blank: true }
validates :age_request, inclusion: { in: AGE_REQUESTS.map(&:to_s), allow_blank: true }
validates :permit, inclusion: { in: PERMITS.map(&:to_s), allow_blank: true }
validates :acceptance, exclusion: {
in: ['resigned'],
......
......@@ -19,13 +19,17 @@ class LanguageSkill < ApplicationRecord
native_languages.first || LanguageSkill.new
end
def language_name
def self.language_name(language)
return '' if language.blank?
return 'Dari' if language == 'DR'
return 'Farsi' if language == 'FS'
I18nData.languages(I18n.locale)[language]
end
def language_name
self.class.language_name(language)
end
def full_language_skills
level_human = level? ? I18n.t(level, scope: [:language_level]) : ''
[language_name, level_human].reject(&:blank?).join(', ') if language?
......
- age_request_filter = request_filter(:age_request_cont, 'all')
- age_request_filter = search_parameters[:age_request_cont].presence || 'all'
.btn-group
button.btn.btn-default.dropdown-toggle type='button' data-toggle='dropdown' aria-label="#{t_attr(:age_request)}" aria-haspopup='true' aria-expanded='false' class="btn-md"
= "#{t_attr(:age_request, Client)} : "
= "#{t_attr(:age_request, Client)}: "
= t(age_request_filter, scope: [:simple_form, :options, :client, :age_request]) + ' '
span.caret aria-hidden='true'
ul.dropdown-menu
......
- gender_request_filter = request_filter(:gender_request_cont, 'all')
- gender_request_filter = search_parameters[:gender_request_cont].presence || 'all'
.btn-group
button.btn.btn-default.dropdown-toggle type='button' data-toggle='dropdown' aria-label="#{t_attr(:gender_request)}" aria-haspopup='true' aria-expanded='false' class="btn-md"
= "#{t_attr(:gender_request, Client)} : "
= "#{t_attr(:gender_request, Client)}: "
= t(gender_request_filter, scope: [:simple_form, :options, :client, :gender_request]) + ' '
span.caret aria-hidden='true'
ul.dropdown-menu
......
- language_skills_language_filter = request_filter(:language_skills_language_cont, t('all'))
- language_skills_language_filter = search_parameters[:language_skills_language_cont].presence
.btn-group
button.btn.btn-default.dropdown-toggle type='button' data-toggle='dropdown' aria-label="#{t_attr(:language_skills)}" aria-haspopup='true' aria-expanded='false' class="btn-md"
= "#{t_attr(:language_skills, Client)} : "
= language_skills_language_filter + ' '
= "#{t_attr(:language_skills, Client)}: "
= language_skills_language_filter ? LanguageSkill.language_name(language_skills_language_filter) : t('all')
= ' '
span.caret aria-hidden='true'
ul.dropdown-menu
li
......
......@@ -22,32 +22,29 @@ class AssignmentsTest < ApplicationSystemTestCase
assert page.has_link? @client.contact.full_name
end
# TODO: Flappy test
# test 'assign unassigned client' do
# login_as @user
# visit volunteers_path
# click_link 'Klienten suchen'
# click_link 'Klient/in suchen'
# wait_for_ajax
# click_link 'Begleitung erstellen'
test 'assign unassigned client' do
login_as @user
visit volunteers_path
click_link 'Klient/in suchen', match: :first
click_link 'Klient/in suchen'
click_link 'Begleitung erstellen'
# fill_in 'Einsatzbeginn', with: 2.days.ago.to_date
# click_button 'Begleitung erfassen'
fill_in 'Einsatzbeginn', with: 2.days.ago.to_date
click_button 'Begleitung erfassen', match: :first
# assert_text @client.contact.full_name
# assert_text @volunteer.contact.full_name
assert_text @client.contact.full_name
assert_text @volunteer.contact.full_name
# visit client_path(@client)
visit client_path(@client)
# assert_text 'Aktiv'
# assert_text @volunteer
assert_text 'Aktiv'
assert_text @volunteer
# visit volunteer_path(@volunteer)
visit volunteer_path(@volunteer)
# assert_text 'Aktiv'
# assert_text @client
# end
assert_text 'Aktiv'
assert_text @client
end
test 'creating_a_pdf_with_a_user_that_has_no_profile_will_not_crash' do
user = create :user, :without_profile
......
......@@ -3,18 +3,20 @@ require 'application_system_test_case'
class ClientsFilterDropdownsTest < ApplicationSystemTestCase
def setup
@user = create :user, role: 'superadmin'
@accepted_mrs_same_age_old = create(:client, acceptance: 'accepted', salutation: 'mrs',
gender_request: 'same', age_request: 'age_old')
create :assignment_active, client: @accepted_mrs_same_age_old
@accepted_mrs_same_age_old = @accepted_mrs_same_age_old.contact.full_name
@accepted_mr_no_matter_age_old = create(:client, acceptance: 'accepted', salutation: 'mr',
@accepted_woman_age_old = create(:client, acceptance: 'accepted', salutation: 'mrs',
gender_request: 'woman', age_request: 'age_old')
create :assignment_active, client: @accepted_woman_age_old
@accepted_no_matter_age_old = create(:client, acceptance: 'accepted', salutation: 'mr',
gender_request: 'no_matter', age_request: 'age_old')
create :assignment_active, client: @accepted_mr_no_matter_age_old
@accepted_mr_no_matter_age_old = @accepted_mr_no_matter_age_old.contact.full_name
@resigned_mrs_same_age_middle = create(:client, acceptance: 'resigned', salutation: 'mrs',
gender_request: 'same', age_request: 'age_middle').contact.full_name
@rejected_mr_no_matter_age_middle = create(:client, acceptance: 'rejected', salutation: 'mr',
create :assignment_active, client: @accepted_no_matter_age_old
@resigned_woman_age_middle = create(:client, acceptance: 'resigned', salutation: 'mrs',
gender_request: 'woman', age_request: 'age_middle').contact.full_name
@rejected_no_matter_age_middle = create(:client, acceptance: 'rejected', salutation: 'mr',
gender_request: 'no_matter', age_request: 'age_middle').contact.full_name
login_as @user
visit clients_path
end
......@@ -26,10 +28,10 @@ class ClientsFilterDropdownsTest < ApplicationSystemTestCase
end
visit current_url
within 'tbody' do
assert page.has_text? @accepted_mrs_same_age_old
assert page.has_text? @accepted_mr_no_matter_age_old
refute page.has_text? @resigned_mrs_same_age_middle
refute page.has_text? @rejected_mr_no_matter_age_middle
assert_text @accepted_woman_age_old
assert_text @accepted_no_matter_age_old
refute_text @resigned_woman_age_middle
refute_text @rejected_no_matter_age_middle
end
within '.section-navigation' do
click_link 'Prozess: Angemeldet'
......@@ -38,10 +40,10 @@ class ClientsFilterDropdownsTest < ApplicationSystemTestCase
end
visit current_url
within 'tbody' do
assert page.has_text? @accepted_mrs_same_age_old
assert page.has_text? @accepted_mr_no_matter_age_old
assert page.has_text? @resigned_mrs_same_age_middle
assert page.has_text? @rejected_mr_no_matter_age_middle
assert_text @accepted_woman_age_old
assert_text @accepted_no_matter_age_old
assert_text @resigned_woman_age_middle
assert_text @rejected_no_matter_age_middle
end
end
......@@ -57,10 +59,10 @@ class ClientsFilterDropdownsTest < ApplicationSystemTestCase
end
visit current_url
within 'tbody' do
refute page.has_text? @accepted_mrs_same_age_old
assert page.has_text? @accepted_mr_no_matter_age_old
refute page.has_text? @resigned_mrs_same_age_middle
refute page.has_text? @rejected_mr_no_matter_age_middle
refute_text @accepted_woman_age_old
assert_text @accepted_no_matter_age_old
refute_text @resigned_woman_age_middle
refute_text @rejected_no_matter_age_middle
end
within '.section-navigation' do
click_link 'Anrede: Herr'
......@@ -69,18 +71,18 @@ class ClientsFilterDropdownsTest < ApplicationSystemTestCase
end
visit current_url
within 'tbody' do
assert page.has_text? @accepted_mrs_same_age_old
assert page.has_text? @accepted_mr_no_matter_age_old
refute page.has_text? @resigned_mrs_same_age_middle
refute page.has_text? @rejected_mr_no_matter_age_middle
assert_text @accepted_woman_age_old
assert_text @accepted_no_matter_age_old
refute_text @resigned_woman_age_middle
refute_text @rejected_no_matter_age_middle
end
click_link 'Filter aufheben'
visit current_url
within 'tbody' do
assert page.has_text? @accepted_mrs_same_age_old
assert page.has_text? @accepted_mr_no_matter_age_old
assert page.has_text? @resigned_mrs_same_age_middle
assert page.has_text? @rejected_mr_no_matter_age_middle
assert_text @accepted_woman_age_old
assert_text @accepted_no_matter_age_old
assert_text @resigned_woman_age_middle
assert_text @rejected_no_matter_age_middle
end
end
......@@ -101,10 +103,10 @@ class ClientsFilterDropdownsTest < ApplicationSystemTestCase
end
visit current_url
within 'tbody' do
assert page.has_text? @accepted_mrs_same_age_old
refute page.has_text? @accepted_mr_no_matter_age_old
refute page.has_text? @resigned_mrs_same_age_middle
refute page.has_text? @rejected_mr_no_matter_age_middle
assert_text @accepted_woman_age_old
refute_text @accepted_no_matter_age_old
refute_text @resigned_woman_age_middle
refute_text @rejected_no_matter_age_middle
end
within '.section-navigation' do
click_link 'Anrede: Frau'
......@@ -113,18 +115,67 @@ class ClientsFilterDropdownsTest < ApplicationSystemTestCase
end
visit current_url
within 'tbody' do
assert page.has_text? @accepted_mrs_same_age_old
assert page.has_text? @accepted_mr_no_matter_age_old
refute page.has_text? @resigned_mrs_same_age_middle
refute page.has_text? @rejected_mr_no_matter_age_middle
assert_text @accepted_woman_age_old
assert_text @accepted_no_matter_age_old
refute_text @resigned_woman_age_middle
refute_text @rejected_no_matter_age_middle
end
click_link 'Filter aufheben'
visit current_url
within 'tbody' do
assert page.has_text? @accepted_mrs_same_age_old
assert page.has_text? @accepted_mr_no_matter_age_old
assert page.has_text? @resigned_mrs_same_age_middle
assert page.has_text? @rejected_mr_no_matter_age_middle
assert_text @accepted_woman_age_old
assert_text @accepted_no_matter_age_old
assert_text @resigned_woman_age_middle
assert_text @rejected_no_matter_age_middle
end
end
test 'filter_find_client' do
Assignment.destroy_all
create :volunteer
client_with_language_skills = create :client, :with_language_skills,
age_request: 'age_young', gender_request: 'woman'
login_as @user
visit volunteers_path
click_on 'Klient/in suchen', match: :first
click_on 'Klient/in suchen'
assert_button 'Geschlecht Freiwillige/r: Alle'
assert_button 'Alter Freiwillige/r: Alle'
assert_button 'Sprachkenntnisse: Alle'
assert_text client_with_language_skills
assert_text @accepted_woman_age_old
assert_text @accepted_no_matter_age_old
refute_text @resigned_woman_age_middle
refute_text @rejected_no_matter_age_middle
click_on 'Geschlecht Freiwillige/r: Alle'
click_on 'Frau'
assert_text client_with_language_skills
assert_text @accepted_woman_age_old
refute_text @accepted_no_matter_age_old
refute_text @resigned_woman_age_middle
refute_text @rejected_no_matter_age_middle
click_on 'Alter Freiwillige/r: Alle'
click_on '20 - 35'
assert_text client_with_language_skills
refute_text @accepted_woman_age_old
refute_text @accepted_no_matter_age_old
refute_text @resigned_woman_age_middle
refute_text @rejected_no_matter_age_middle
click_on 'Sprachkenntnisse: Alle'
click_on client_with_language_skills.language_skills.first.language_name
assert_text client_with_language_skills
refute_text @accepted_woman_age_old
refute_text @accepted_no_matter_age_old
refute_text @resigned_woman_age_middle
refute_text @rejected_no_matter_age_middle
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment