@@ -13,7 +13,34 @@ describe("SmartCrop", function() {
13
13
expect ( result . topCrop . width ) . to . be . within ( 1 , img . width ) ;
14
14
expect ( result . topCrop . height ) . to . be . within ( 1 , img . height ) ;
15
15
}
16
+ describe ( "isAvailable" , function ( ) {
17
+ it ( "should return true when canvas is available" , function ( ) {
18
+ expect ( SmartCrop . isAvailable ( ) ) . to . equal ( true ) ;
19
+ } ) ;
20
+ it ( "should return false when canvas is not available" , function ( ) {
21
+ expect ( SmartCrop . isAvailable ( { canvasFactory : function ( ) { } } ) ) . to . equal ( false ) ;
22
+ } ) ;
23
+ } ) ;
16
24
describe ( "crop" , function ( ) {
25
+ it ( "should do something sane" , function ( done ) {
26
+ var c = document . createElement ( 'canvas' ) ,
27
+ ctx = c . getContext ( '2d' ) ;
28
+ c . width = 128 ;
29
+ c . height = 64 ;
30
+ ctx . fillStyle = 'white' ;
31
+ ctx . fillRect ( 0 , 0 , 128 , 64 ) ;
32
+ ctx . fillStyle = 'red' ;
33
+ ctx . fillRect ( 96 , 32 , 16 , 16 ) ;
34
+ SmartCrop . crop ( c , { debug : false } , function ( result ) {
35
+ //document.body.appendChild(c);
36
+ //document.body.appendChild(result.debugCanvas);
37
+ expect ( result . topCrop . x ) . to . be . lessThan ( 96 ) ;
38
+ expect ( result . topCrop . y ) . to . be . lessThan ( 32 ) ;
39
+ expect ( result . topCrop . x + result . topCrop . width ) . to . be . greaterThan ( 112 ) ;
40
+ expect ( result . topCrop . y + result . topCrop . height ) . to . be . greaterThan ( 48 ) ;
41
+ done ( ) ;
42
+ } ) ;
43
+ } ) ;
17
44
it ( "should adhere to minScale" , function ( done ) {
18
45
SmartCrop . crop ( img , { minScale : 1 } , function ( result ) {
19
46
validResult ( result ) ;
0 commit comments