11import getConditionFunction from "./getConditionFunction" ;
22
3- test ( 'queries separated by a comma should act as an "or"' , ( ) => {
3+ test ( 'should treat multiple conditions as an "or"' , ( ) => {
44 // When either width or height is greater than 100
55 const condFn = getConditionFunction ( [
66 [ [ "width" , ">=" , 100 ] ] ,
@@ -22,7 +22,7 @@ test('queries separated by a comma should act as an "or"', () => {
2222 expect ( condFn2 ( { width : 100 , height : 20 } ) ) . toBe ( true ) ;
2323} ) ;
2424
25- test ( "non array conditions should return function always returning true" , ( ) => {
25+ test ( "should return a function always returning true for non-array conditions " , ( ) => {
2626 const condFn = getConditionFunction ( ) ;
2727 const condFn2 = getConditionFunction ( [ ] ) ;
2828
@@ -35,7 +35,7 @@ test("non array conditions should return function always returning true", () =>
3535 expect ( condFn2 ( { width : 99999 , height : 99999 } ) ) . toBe ( true ) ;
3636} ) ;
3737
38- test ( "orientation conditions" , ( ) => {
38+ test ( "should work with orientation conditions" , ( ) => {
3939 const portraitCondFn = getConditionFunction ( [
4040 [ [ "orientation" , ":" , "portrait" ] ]
4141 ] ) ;
@@ -57,7 +57,7 @@ test("orientation conditions", () => {
5757 expect ( landscapeCondFn ( { width : 10 , height : 100 } ) ) . toBe ( false ) ;
5858} ) ;
5959
60- test ( "width conditions" , ( ) => {
60+ test ( "should work with width conditions" , ( ) => {
6161 const ltCondFn = getConditionFunction ( [ [ [ "width" , "<" , 100 ] ] ] ) ;
6262 const lteCondFn = getConditionFunction ( [ [ [ "width" , "<=" , 100 ] ] ] ) ;
6363 const gtCondFn = getConditionFunction ( [ [ [ "width" , ">" , 100 ] ] ] ) ;
@@ -92,7 +92,7 @@ test("width conditions", () => {
9292 expect ( gteCondFn ( { width : 0 } ) ) . toBe ( false ) ;
9393} ) ;
9494
95- test ( "height conditions" , ( ) => {
95+ test ( "should work with height conditions" , ( ) => {
9696 const ltCondFn = getConditionFunction ( [ [ [ "height" , "<" , 100 ] ] ] ) ;
9797 const lteCondFn = getConditionFunction ( [ [ [ "height" , "<=" , 100 ] ] ] ) ;
9898 const gtCondFn = getConditionFunction ( [ [ [ "height" , ">" , 100 ] ] ] ) ;
@@ -127,7 +127,7 @@ test("height conditions", () => {
127127 expect ( gteCondFn ( { height : 0 } ) ) . toBe ( false ) ;
128128} ) ;
129129
130- test ( "aspect-ratio conditions" , ( ) => {
130+ test ( "should work with aspect-ratio conditions" , ( ) => {
131131 const ltCondFn = getConditionFunction ( [ [ [ "aspect-ratio" , "<" , 1 ] ] ] ) ;
132132 const lteCondFn = getConditionFunction ( [ [ [ "aspect-ratio" , "<=" , 1 ] ] ] ) ;
133133 const gtCondFn = getConditionFunction ( [ [ [ "aspect-ratio" , ">" , 1 ] ] ] ) ;
@@ -158,7 +158,7 @@ test("aspect-ratio conditions", () => {
158158 expect ( gteCondFn ( { width : 10 , height : 100 } ) ) . toBe ( false ) ;
159159} ) ;
160160
161- test ( "multiple conditions should work" , ( ) => {
161+ test ( "should work for multiple conditions " , ( ) => {
162162 const multiCondFn = getConditionFunction ( [
163163 [
164164 [ "orientation" , ":" , "landscape" ] ,
@@ -174,16 +174,25 @@ test("multiple conditions should work", () => {
174174 expect ( multiCondFn ( { width : 101 , height : 20 } ) ) . toBe ( true ) ;
175175} ) ;
176176
177- test ( "unsupported condition always returns true" , ( ) => {
178- const condFn = getConditionFunction ( [
177+ test ( "should return a function always returning true for invalid conditions " , ( ) => {
178+ const noCondFn1 = getConditionFunction ( [
179179 [ [ "something" , "that's" , "unrecognisable" ] ]
180180 ] ) ;
181181
182- expect ( typeof condFn ) . toBe ( "function" ) ;
183- expect ( condFn ( ) ) . toBe ( true ) ;
184- expect ( condFn ( { } ) ) . toBe ( true ) ;
185- expect ( condFn ( { width : 100 , height : 100 } ) ) . toBe ( true ) ;
186- expect ( condFn ( { width : 200 , height : 100 } ) ) . toBe ( true ) ;
187- expect ( condFn ( { width : 100 , height : 200 } ) ) . toBe ( true ) ;
188- expect ( condFn ( { width : 0 , height : 0 } ) ) . toBe ( true ) ;
182+ const noCondFn2 = getConditionFunction ( [ [ [ "width" , "?" , 1 ] ] ] ) ;
183+ expect ( typeof noCondFn2 ) . toBe ( "function" ) ;
184+
185+ const noCondFn3 = getConditionFunction ( [ [ [ "height" , "?" , 1 ] ] ] ) ;
186+ expect ( typeof noCondFn3 ) . toBe ( "function" ) ;
187+
188+ const noCondFn4 = getConditionFunction ( [ [ [ "aspect-ratio" , "?" , 1 ] ] ] ) ;
189+ expect ( typeof noCondFn4 ) . toBe ( "function" ) ;
190+
191+ expect ( typeof noCondFn1 ) . toBe ( "function" ) ;
192+ expect ( noCondFn1 ( ) ) . toBe ( true ) ;
193+ expect ( noCondFn1 ( { } ) ) . toBe ( true ) ;
194+ expect ( noCondFn1 ( { width : 100 , height : 100 } ) ) . toBe ( true ) ;
195+ expect ( noCondFn1 ( { width : 200 , height : 100 } ) ) . toBe ( true ) ;
196+ expect ( noCondFn1 ( { width : 100 , height : 200 } ) ) . toBe ( true ) ;
197+ expect ( noCondFn1 ( { width : 0 , height : 0 } ) ) . toBe ( true ) ;
189198} ) ;
0 commit comments