diff --git a/app/helpers/signature_sheets_helper.rb b/app/helpers/signature_sheets_helper.rb index 8e75dccfd..d40689837 100644 --- a/app/helpers/signature_sheets_helper.rb +++ b/app/helpers/signature_sheets_helper.rb @@ -5,4 +5,48 @@ module SignatureSheetsHelper [t("activerecord.models.budget/investment", count: 1), Budget::Investment]] end -end \ No newline at end of file + def required_fields_to_verify_text_help + if Setting["feature.remote_census"].present? + date_of_birth_and_postal_code_text_help + else + t("admin.signature_sheets.new.document_numbers_note") + end + end + + def date_of_birth_and_postal_code_text_help + text_help = t("admin.signature_sheets.new.text_help.required_fields_note") + + if Setting.force_presence_date_of_birth? + text_help += t("admin.signature_sheets.new.text_help.date_of_birth_note") + end + + if Setting.force_presence_postal_code? + text_help += t("admin.signature_sheets.new.text_help.postal_code_note") + end + + text_help += "
" + text_help += t("admin.signature_sheets.new.text_help.required_fields_structure_note") + + return text_help.html_safe + end + + def example_text_help + text_example = t("admin.signature_sheets.new.text_help.example_text") + example_1 = "12345678Z" + example_2 = "87654321Y" + + if Setting.force_presence_date_of_birth? + example_1 += ", 01/01/1980" + example_2 += ", 01/02/1990" + end + + if Setting.force_presence_postal_code? + example_1 += ", 28001" + example_2 += ", 28002" + end + + text_example += "#{example_1}; #{example_2}" + return text_example + end + +end diff --git a/app/views/admin/signature_sheets/new.html.erb b/app/views/admin/signature_sheets/new.html.erb index d78046a1b..cc889d68a 100644 --- a/app/views/admin/signature_sheets/new.html.erb +++ b/app/views/admin/signature_sheets/new.html.erb @@ -15,7 +15,8 @@ <%= f.label :required_fields_to_verify %> -

<%= t("admin.signature_sheets.new.document_numbers_note") %>

+

<%= required_fields_to_verify_text_help %>

+

<%= example_text_help %>

<%= f.text_area :required_fields_to_verify, rows: "6", label: false, aria: {describedby: "required-fields-to-verify-help-text"} %> <%= f.submit(class: "button", value: t("admin.signature_sheets.new.submit")) %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index c87a77835..14964755c 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1402,6 +1402,12 @@ en: title: New signature sheets document_numbers_note: "Write the numbers separated by semicolons (;)" submit: Create signature sheet + text_help: + required_fields_note: "To verify a user, your application needs: Document number" + date_of_birth_note: ", Day of birth (dd/mm/yyyy)" + postal_code_note: " and Postal Code" + required_fields_structure_note: "Required fields for each user must be separated by commas and each user must be separated by semicolons." + example_text: "Example: " show: created_at: Created author: Author diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 9fb494dfb..40c49c389 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1400,6 +1400,12 @@ es: title: Nueva hoja de firmas document_numbers_note: "Introduce los números separados por punto y coma (;)" submit: Crear hoja de firmas + text_help: + required_fields_note: "Para verificar un usuario, su aplicación necesita: Número de documento" + date_of_birth_note: ", Día de nacimiento (dd/mm/yyyy)" + postal_code_note: " y Código Postal" + required_fields_structure_note: "Los campos requeridos para cada usuario deben ir separados por comas y cada usuario debe ir separado por punto y coma." + example_text: "Ejemplo: " show: created_at: Creado author: Autor diff --git a/spec/helpers/signature_sheets_helper_spec.rb b/spec/helpers/signature_sheets_helper_spec.rb new file mode 100644 index 000000000..5e53e7ec4 --- /dev/null +++ b/spec/helpers/signature_sheets_helper_spec.rb @@ -0,0 +1,82 @@ +require "rails_helper" + +describe SignatureSheetsHelper do + + describe "#required_fields_to_verify_text_help by default" do + + it "returns text help by default" do + text = "Write the numbers separated by semicolons (;)" + expect(required_fields_to_verify_text_help).to eq(text) + end + + end + + describe "#required_fields_to_verify_text_help with remote_census active" do + + before do + Setting["feature.remote_census"] = true + end + + after do + Setting["feature.remote_census"] = nil + end + + it "returns text help when date_of_birth and postal_code are not required" do + text_help_1 = "To verify a user, your application needs: Document number" + text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." + text_example = "Example: 12345678Z; 87654321Y" + + expect(required_fields_to_verify_text_help).to include(text_help_1) + expect(required_fields_to_verify_text_help).to include(text_help_2) + expect(example_text_help).to include(text_example) + end + + it "returns text help when date_of_birth is required" do + Setting["remote_census.request.date_of_birth"] = "some.value" + + text_help_1 = "To verify a user, your application needs: Document number, Day of birth (dd/mm/yyyy)" + text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." + text_example = "Example: 12345678Z, 01/01/1980; 87654321Y, 01/02/1990" + + expect(required_fields_to_verify_text_help).to include(text_help_1) + expect(required_fields_to_verify_text_help).to include(text_help_2) + expect(example_text_help).to include(text_example) + + Setting["remote_census.request.date_of_birth"] = nil + end + + it "returns text help when postal_code is required" do + Setting["remote_census.request.postal_code"] = "some.value" + + text_help_1 = "To verify a user, your application needs: Document number and Postal Code" + text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." + text_example = "Example: 12345678Z, 28001; 87654321Y, 28002" + + expect(required_fields_to_verify_text_help).to include(text_help_1) + expect(required_fields_to_verify_text_help).to include(text_help_2) + expect(example_text_help).to include(text_example) + + Setting["remote_census.request.postal_code"] = nil + end + + it "returns text help when date_of_birth and postal_code are required" do + Setting["remote_census.request.date_of_birth"] = "some.value" + Setting["remote_census.request.postal_code"] = "some.value" + + text_help_1 = "To verify a user, your application needs: Document number, Day of birth (dd/mm/yyyy) and Postal Code" + text_help_2 = "Required fields for each user must be separated by commas and each user must be separated by semicolons." + text_example = "Example: 12345678Z, 01/01/1980, 28001; 87654321Y, 01/02/1990, 28002" + + expect(required_fields_to_verify_text_help).to include(text_help_1) + expect(required_fields_to_verify_text_help).to include(text_help_2) + expect(example_text_help).to include(text_example) + + Setting["remote_census.request.postal_code"] = nil + Setting["remote_census.request.postal_code"] = nil + end + + end + + + +end