Merge pull request #10977 from tchak/champ-oui-non-improve-format-on-export

ETQ Instructeur, je veux pouvoir faire la différence entre un champ Oui/Non vide et “Non”
This commit is contained in:
Paul Chavard 2024-10-23 09:24:57 +00:00 committed by GitHub
commit 1b188f65b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 61 additions and 18 deletions

View file

@ -78,6 +78,7 @@ class API::V2::Schema < GraphQL::Schema
Types::Champs::TextChampType, Types::Champs::TextChampType,
Types::Champs::TitreIdentiteChampType, Types::Champs::TitreIdentiteChampType,
Types::Champs::EngagementJuridiqueChampType, Types::Champs::EngagementJuridiqueChampType,
Types::Champs::YesNoChampType,
Types::GeoAreas::ParcelleCadastraleType, Types::GeoAreas::ParcelleCadastraleType,
Types::GeoAreas::SelectionUtilisateurType, Types::GeoAreas::SelectionUtilisateurType,
Types::PersonneMoraleType, Types::PersonneMoraleType,

View file

@ -509,6 +509,9 @@ class API::V2::StoredQuery
... on CheckboxChamp { ... on CheckboxChamp {
checked: value checked: value
} }
... on YesNoChamp {
selected: value
}
... on DecimalNumberChamp { ... on DecimalNumberChamp {
decimalNumber: value decimalNumber: value
} }

View file

@ -4605,6 +4605,31 @@ type WarningMessage {
message: String! message: String!
} }
type YesNoChamp implements Champ {
"""
L'identifiant du champDescriptor de ce champ
"""
champDescriptorId: String!
id: ID!
"""
Libellé du champ.
"""
label: String!
prefilled: Boolean!
"""
La valeur du champ sous forme texte.
"""
stringValue: String
"""
Date de dernière modification du champ.
"""
updatedAt: ISO8601DateTime!
value: Boolean
}
type YesNoChampDescriptor implements ChampDescriptor { type YesNoChampDescriptor implements ChampDescriptor {
""" """
Description des champs dun bloc répétable. Description des champs dun bloc répétable.

View file

@ -24,8 +24,14 @@ module Types
else else
Types::Champs::TextChampType Types::Champs::TextChampType
end end
when ::Champs::YesNoChamp, ::Champs::CheckboxChamp when ::Champs::CheckboxChamp
Types::Champs::CheckboxChampType Types::Champs::CheckboxChampType
when ::Champs::YesNoChamp
if context.has_fragment?(:YesNoChamp)
Types::Champs::YesNoChampType
else
Types::Champs::CheckboxChampType
end
when ::Champs::DateChamp when ::Champs::DateChamp
Types::Champs::DateChampType Types::Champs::DateChampType
when ::Champs::DatetimeChamp when ::Champs::DatetimeChamp

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Types::Champs
class YesNoChampType < Types::BaseObject
implements Types::ChampType
field :value, Boolean, null: true
def value
if object.blank?
nil
else
object.true?
end
end
end
end

View file

@ -33,20 +33,11 @@ class TypesDeChamp::YesNoTypeDeChamp < TypesDeChamp::CheckboxTypeDeChamp
end end
def champ_default_value def champ_default_value
'Non' ''
end end
def champ_default_export_value(path = :value) def champ_default_export_value(path = :value)
'Non' ''
end
def champ_default_api_value(version = 2)
case version
when 2
'false'
else
nil
end
end end
private private

View file

@ -212,7 +212,7 @@ describe Champ do
context 'if nil' do context 'if nil' do
let(:value) { nil } let(:value) { nil }
it { expect(value_for_export).to eq('Non') } it { expect(value_for_export).to eq('') }
end end
end end
@ -236,7 +236,7 @@ describe Champ do
allow(champ_text).to receive(:type_de_champ).and_return(type_de_champ_text) allow(champ_text).to receive(:type_de_champ).and_return(type_de_champ_text)
end end
it { expect(type_de_champ_text.champ_value_for_export(champ_yes_no)).to eq(nil) } it { expect(type_de_champ_text.champ_value_for_export(champ_yes_no)).to eq(nil) }
it { expect(type_de_champ_yes_no.champ_value_for_export(champ_text)).to eq('Non') } it { expect(type_de_champ_yes_no.champ_value_for_export(champ_text)).to eq('') }
end end
end end

View file

@ -3,7 +3,7 @@
describe Champs::CheckboxChamp do describe Champs::CheckboxChamp do
let(:boolean_champ) { described_class.new(value: value) } let(:boolean_champ) { described_class.new(value: value) }
before { allow(boolean_champ).to receive(:type_de_champ).and_return(build(:type_de_champ_checkbox)) } before { allow(boolean_champ).to receive(:type_de_champ).and_return(build(:type_de_champ_checkbox)) }
it_behaves_like "a boolean champ" it_behaves_like "a boolean champ", false
# TODO remove when normalize_checkbox_values is over # TODO remove when normalize_checkbox_values is over
describe '#true?' do describe '#true?' do

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
describe Champs::YesNoChamp do describe Champs::YesNoChamp do
it_behaves_like "a boolean champ" do it_behaves_like "a boolean champ", true do
let(:boolean_champ) { described_class.new(value: value) } let(:boolean_champ) { described_class.new(value: value) }
before { allow(boolean_champ).to receive(:type_de_champ).and_return(build(:type_de_champ_yes_no)) } before { allow(boolean_champ).to receive(:type_de_champ).and_return(build(:type_de_champ_yes_no)) }
end end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples "a boolean champ" do RSpec.shared_examples "a boolean champ" do |nullable|
describe 'before validation' do describe 'before validation' do
subject { boolean_champ.valid? } subject { boolean_champ.valid? }
@ -55,7 +55,7 @@ RSpec.shared_examples "a boolean champ" do
context 'when the value is nil' do context 'when the value is nil' do
let(:value) { nil } let(:value) { nil }
it { is_expected.to eq("Non") } it { is_expected.to eq(nullable ? '' : 'Non') }
end end
end end
end end