1- import { transform , getBorder , getTransformations , getResize , toTransformationStr } from '../lib/transformers'
1+ import { transform , getBorder , getTransformations , getResize , toTransformationStr , getPosition } from '../lib/transformers'
22import { resize } from '../lib/transformers/resize'
33import { border } from '../lib/transformers/border'
4+ import { position } from '../lib/transformers/position'
5+ import { effect } from '../lib/transformers/effect'
46
57describe ( 'Modifiers' , ( ) => {
68 describe ( 'transform()' , ( ) => {
@@ -112,14 +114,15 @@ describe('Modifiers', () => {
112114 expect ( getResize ( options ) ) . toEqual ( 'h_20' )
113115 } )
114116
115- it ( 'should support width, height and crop field' , ( ) => {
117+ it ( 'should support width, height, aspectRatio and crop field' , ( ) => {
116118 const options = {
117119 height : 20 ,
118120 width : 20 ,
119- crop : 'scale'
121+ crop : 'scale' ,
122+ aspectRatio : '1:1'
120123 }
121124
122- expect ( getResize ( options ) ) . toEqual ( 'c_scale,w_20,h_20' )
125+ expect ( getResize ( options ) ) . toEqual ( 'c_scale,w_20,h_20,ar_1:1 ' )
123126 } )
124127 } )
125128
@@ -148,6 +151,31 @@ describe('Modifiers', () => {
148151 )
149152 } )
150153 } )
154+
155+ describe ( 'getPosition()' , ( ) => {
156+ it ( 'should prioritize position field' , ( ) => {
157+ const options = {
158+ position : {
159+ x : 10 ,
160+ y : 10 ,
161+ } ,
162+ x : 20 ,
163+ y : 20
164+ }
165+
166+ expect ( getPosition ( options ) ) . toEqual ( 'x_10,y_10' )
167+ } )
168+
169+ it ( 'should take x field' , ( ) => {
170+ expect ( getPosition ( {
171+ x : 10
172+ } ) ) . toBe ( 'x_10' )
173+ } )
174+
175+ it ( 'should take y field' , ( ) => {
176+ expect ( getPosition ( { y : 10 } ) ) . toBe ( 'y_10' )
177+ } )
178+ } )
151179} )
152180
153181describe ( 'resize()' , ( ) => {
@@ -176,4 +204,36 @@ describe('border', () => {
176204 it ( 'should return options' , ( ) => {
177205 expect ( border ( { type : 'dotted' , color : 'blue' , width : 10 } ) ) . toEqual ( 'bo_10px_dotted_blue' )
178206 } )
207+ } )
208+
209+ describe ( 'position' , ( ) => {
210+ it ( 'should return full options string' , ( ) => {
211+ expect ( position ( { x : 10 , y : 10 } ) ) . toBe ( 'x_10,y_10' )
212+ } )
213+
214+ it ( 'should return x only' , ( ) => {
215+ expect ( position ( { x : 10 } ) ) . toBe ( 'x_10' )
216+ } )
217+
218+ it ( 'should return y only' , ( ) => {
219+ expect ( position ( { y : 10 } ) ) . toBe ( 'y_10' )
220+ } )
221+
222+ it ( 'should return empty string' , ( ) => {
223+ expect ( position ( { } ) ) . toBe ( '' )
224+ } )
225+ } )
226+
227+ describe ( 'effect' , ( ) => {
228+ it ( 'should return legal string for array input' , ( ) => {
229+ expect ( effect ( [ 'grayscale' , 'tint:80' ] ) ) . toBe ( 'e_grayscale:tint:80' )
230+ } )
231+
232+ it ( 'should return legal string for string input' , ( ) => {
233+ expect ( effect ( 'grayscale:tint' ) ) . toBe ( 'e_grayscale:tint' )
234+ } )
235+
236+ it ( 'should return empty string' , ( ) => {
237+ expect ( effect ( '' ) ) . toBe ( '' )
238+ } )
179239} )
0 commit comments