Merge pull request #7670 from betagouv/add_is_not_eq

feat(conditional): ajoute l'operateur "n'est pas égal" s'appliquant à un choix parmis une liste
This commit is contained in:
LeSim 2022-08-10 12:05:10 +02:00 committed by GitHub
commit 354248c88a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 2 deletions

View file

@ -111,7 +111,8 @@ class TypesDeChampEditor::ConditionsComponent < ApplicationComponent
]
when ChampValue::CHAMP_VALUE_TYPE.fetch(:enum)
[
[t('is', scope: 'logic'), Eq.name]
[t('is', scope: 'logic'), Eq.name],
[t('is_not', scope: 'logic'), NotEq.name]
]
when ChampValue::CHAMP_VALUE_TYPE.fetch(:number)
[Eq, LessThan, GreaterThan, LessThanEq, GreaterThanEq]

View file

@ -8,7 +8,7 @@ module Logic
end
def self.class_from_name(name)
[ChampValue, Constant, Empty, LessThan, LessThanEq, Eq, GreaterThanEq, GreaterThan, EmptyOperator, And, Or]
[ChampValue, Constant, Empty, LessThan, LessThanEq, Eq, NotEq, GreaterThanEq, GreaterThan, EmptyOperator, And, Or]
.find { |c| c.name == name }
end
@ -74,6 +74,8 @@ module Logic
def ds_eq(left, right) = Logic::Eq.new(left, right)
def ds_not_eq(left, right) = Logic::NotEq.new(left, right)
def greater_than(left, right) = Logic::GreaterThan.new(left, right)
def greater_than_eq(left, right) = Logic::GreaterThanEq.new(left, right)

View file

@ -0,0 +1,3 @@
class Logic::NotEq < Logic::Eq
def operation = :!=
end

View file

@ -2,6 +2,7 @@ fr:
logic:
empty: un membre vide
is: Est
is_not: Nest pas
operators:
'Logic::LessThan': Inférieur à
'Logic::LessThanEq': Inférieur ou égal à

View file

@ -0,0 +1,17 @@
describe Logic::NotEq do
include Logic
describe '#compute' do
it { expect(ds_not_eq(constant(1), constant(1)).compute).to be(false) }
it { expect(ds_not_eq(constant(1), constant(2)).compute).to be(true) }
end
describe '#errors' do
it { expect(ds_not_eq(constant(true), constant(true)).errors).to be_empty }
it { expect(ds_not_eq(constant(true), constant(1)).errors).to eq(["les types sont incompatibles : (Oui != 1)"]) }
end
describe '#==' do
it { expect(ds_not_eq(constant(true), constant(false))).to eq(ds_not_eq(constant(false), constant(true))) }
end
end