@@ -54,19 +54,60 @@ describe('Viewport', () => {
5454 beforeEach ( ( ) => image = sinon . createStubInstance ( Image ) ) ;
5555
5656 it ( 'should ignore passed areas' , ( ) => {
57- const viewport = createViewport ( { image, pixelRatio : 1 } ) ;
57+ const viewport = createViewport ( { coords : { top : 0 , left : 0 , width : 20 , height : 20 } , image, pixelRatio : 1 } ) ;
5858
59- viewport . ignoreAreas ( [ { top : 1 , left : 1 } ] ) ;
59+ viewport . ignoreAreas ( [ { top : 1 , left : 1 , width : 10 , height : 10 } ] ) ;
6060
61- assert . calledWith ( image . clear , { top : 1 , left : 1 } , { scaleFactor : 1 } ) ;
61+ assert . calledWith ( image . clear , { top : 1 , left : 1 , width : 10 , height : 10 } , { scaleFactor : 1 } ) ;
6262 } ) ;
6363
6464 it ( 'should transform area coordinates to a viewport origin' , ( ) => {
65- const viewport = createViewport ( { coords : { top : 1 , left : 1 } , image} ) ;
65+ const viewport = createViewport ( { coords : { top : 1 , left : 1 , width : 20 , height : 20 } , image} ) ;
66+
67+ viewport . ignoreAreas ( [ { top : 1 , left : 1 , width : 10 , height : 10 } ] ) ;
68+
69+ assert . calledWith ( image . clear , { top : 0 , left : 0 , width : 10 , height : 10 } ) ;
70+ } ) ;
71+
72+ it ( 'should crop area size to a viewport origin (inside)' , ( ) => {
73+ const viewport = createViewport ( { coords : { top : 0 , left : 0 , width : 30 , height : 20 } , image} ) ;
74+
75+ const area = { top : 10 , left : 5 , width : 20 , height : 5 } ;
76+ viewport . ignoreAreas ( [ area ] ) ;
77+
78+ assert . calledWith ( image . clear , area ) ;
79+ } ) ;
80+
81+ it ( 'should crop area size to a viewport origin (bottom right)' , ( ) => {
82+ const viewport = createViewport ( { coords : { top : 0 , left : 0 , width : 30 , height : 20 } , image} ) ;
83+
84+ viewport . ignoreAreas ( [ { top : 10 , left : 5 , width : 30 , height : 5 } ] ) ;
85+
86+ assert . calledWith ( image . clear , { top : 10 , left : 5 , width : 25 , height : 5 } ) ;
87+ } ) ;
88+
89+ it ( 'should crop area size to a viewport origin (top left)' , ( ) => {
90+ const viewport = createViewport ( { coords : { top : 20 , left : 15 , width : 30 , height : 20 } , image} ) ;
91+
92+ viewport . ignoreAreas ( [ { top : 10 , left : 5 , width : 20 , height : 20 } ] ) ;
93+
94+ assert . calledWith ( image . clear , { top : 0 , left : 0 , width : 10 , height : 10 } ) ;
95+ } ) ;
96+
97+ it ( 'should not clear image if area is outside of viewport (bottom right)' , ( ) => {
98+ const viewport = createViewport ( { coords : { top : 0 , left : 0 , width : 30 , height : 20 } , image} ) ;
99+
100+ viewport . ignoreAreas ( [ { top : 21 , left : 31 , width : 30 , height : 5 } ] ) ;
101+
102+ assert . notCalled ( image . clear ) ;
103+ } ) ;
104+
105+ it ( 'should not clear image if area is outside of viewport (top left)' , ( ) => {
106+ const viewport = createViewport ( { coords : { top : 21 , left : 31 , width : 30 , height : 20 } , image} ) ;
66107
67- viewport . ignoreAreas ( [ { top : 1 , left : 1 } ] ) ;
108+ viewport . ignoreAreas ( [ { top : 0 , left : 0 , width : 30 , height : 20 } ] ) ;
68109
69- assert . calledWith ( image . clear , { top : 0 , left : 0 } ) ;
110+ assert . notCalled ( image . clear ) ;
70111 } ) ;
71112 } ) ;
72113
0 commit comments