@@ -116,6 +116,7 @@ describe('SigCanvas wrapper methods return equivalent to SigPad', () => {
116
116
} )
117
117
} )
118
118
119
+ // comes after props and wrapper methods as it uses both
119
120
describe ( 'get methods return correct canvases' , ( ) => {
120
121
const instance = mount (
121
122
< SignatureCanvas canvasProps = { dotF . canvasProps } />
@@ -133,3 +134,60 @@ describe('get methods return correct canvases', () => {
133
134
expect ( trimmed . height ) . toBe ( dotF . trimmedSize . height )
134
135
} )
135
136
} )
137
+
138
+ // comes after props, wrappers, and gets as it uses them all
139
+ describe ( 'resizing works correctly' , ( ) => {
140
+ const wrapper = mount ( < SignatureCanvas /> )
141
+ const instance = wrapper . instance ( )
142
+ const canvas = instance . getCanvas ( )
143
+
144
+ test ( 'canvas should clear on resize' , ( ) => {
145
+ instance . fromData ( dotF . data )
146
+ expect ( instance . isEmpty ( ) ) . toBe ( false )
147
+
148
+ window . resizeTo ( 500 , 500 )
149
+ expect ( instance . isEmpty ( ) ) . toBe ( true )
150
+ } )
151
+
152
+ test ( 'canvas should not clear when clearOnResize is false' , ( ) => {
153
+ wrapper . setProps ( { clearOnResize : false } )
154
+
155
+ instance . fromData ( dotF . data )
156
+ expect ( instance . isEmpty ( ) ) . toBe ( false )
157
+
158
+ window . resizeTo ( 500 , 500 )
159
+ expect ( instance . isEmpty ( ) ) . toBe ( false )
160
+ } )
161
+
162
+ const size = { width : 100 , height : 100 }
163
+ test ( 'canvas should not change size if fixed width & height' , ( ) => {
164
+ wrapper . setProps ( { canvasProps : size } )
165
+ window . resizeTo ( 500 , 500 )
166
+
167
+ expect ( canvas . width ) . toBe ( size . width )
168
+ expect ( canvas . height ) . toBe ( size . height )
169
+ } )
170
+
171
+ test ( 'canvas should change size if no width or height' , ( ) => {
172
+ wrapper . setProps ( { canvasProps : { } } )
173
+ window . resizeTo ( 500 , 500 )
174
+
175
+ expect ( canvas . width ) . not . toBe ( size . width )
176
+ expect ( canvas . height ) . not . toBe ( size . height )
177
+ } )
178
+
179
+ test ( 'canvas should partially change size if one of width or height' , ( ) => {
180
+ wrapper . setProps ( { canvasProps : { width : size . width } } )
181
+ window . resizeTo ( 500 , 500 )
182
+
183
+ expect ( canvas . width ) . toBe ( size . width )
184
+ expect ( canvas . height ) . not . toBe ( size . height )
185
+
186
+ // now do height instead
187
+ wrapper . setProps ( { canvasProps : { height : size . height } } )
188
+ window . resizeTo ( 500 , 500 )
189
+
190
+ expect ( canvas . width ) . not . toBe ( size . width )
191
+ expect ( canvas . height ) . toBe ( size . height )
192
+ } )
193
+ } )
0 commit comments