@@ -2,17 +2,63 @@ import { describe, expect, it } from '@jest/globals';
22import OrCondition from './orCondition' ;
33
44describe ( 'OR Condition' , ( ) => {
5+ const conditionWithoutClass : Condition = {
6+ field : 'testField' ,
7+ class : null ,
8+ value : null ,
9+ operator : '' ,
10+ } ;
11+
12+ const orConditionWithoutClass = new OrCondition ( conditionWithoutClass ) ;
13+
514 it ( 'getConditionFieldNames() returns an array of field names from provided Condition' , ( ) => {
6- const condition : Condition = {
7- field : 'testField' ,
8- class : null ,
9- value : null ,
10- operator : '' ,
11- } ;
15+ expect ( orConditionWithoutClass . getConditionFieldNames ( ) ) . toEqual ( [ 'testField' ] ) ;
16+ } ) ;
1217
13- const orCondition = new OrCondition ( condition ) ;
14- const fieldNames = orCondition . getConditionFieldNames ( ) ;
18+ it ( 'getConditions() returns an array of Conditions' , ( ) => {
19+ expect ( orConditionWithoutClass . getConditions ( ) ) . toEqual ( [ conditionWithoutClass ] ) ;
20+ } ) ;
21+
22+ it ( 'validate() returns true if no class' , ( ) => {
23+ expect ( orConditionWithoutClass . validate ( ) ) . toEqual ( true ) ;
24+ } ) ;
1525
16- expect ( fieldNames ) . toEqual ( [ 'testField' ] ) ;
26+ it ( 'validate() returns false if field is already disabled' , ( ) => {
27+ const orCondition = new OrCondition ( createConditionWithClass ( true , true ) ) ;
28+ expect ( orCondition . validate ( ) ) . toEqual ( false ) ;
1729 } ) ;
18- } ) ;
30+
31+ it ( 'validate() returns true if is not disabled and condition is valid' , ( ) => {
32+ const orCondition = new OrCondition ( createConditionWithClass ( false , true ) ) ;
33+ expect ( orCondition . validate ( ) ) . toEqual ( true ) ;
34+ } ) ;
35+
36+ it ( 'validate() returns false if validation failed' , ( ) => {
37+ const orCondition = new OrCondition ( createConditionWithClass ( false , false ) ) ;
38+ expect ( orCondition . validate ( ) ) . toEqual ( false ) ;
39+ } ) ;
40+ } ) ;
41+
42+ function createConditionWithClass ( isDisabled : boolean , isValid : boolean ) : Condition {
43+ return {
44+ field : 'testField' ,
45+ class : {
46+ getConditionsHandler ( ) {
47+ return {
48+ getIsDisabled ( ) {
49+ return isDisabled ;
50+ }
51+ } as ConditionsHandlerInterface ;
52+ } ,
53+ getConditionValidator ( ) {
54+ return {
55+ validate ( condition : Condition ) {
56+ return isValid ;
57+ }
58+ } as ConditionValidatorInterface ;
59+ } ,
60+ } as FieldInterface ,
61+ value : null ,
62+ operator : '' ,
63+ } as Condition ;
64+ }
0 commit comments