cut.test.js
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const cut = require('../src/cut').default
const assert = require('assert')
describe('cut', function () {
const self = {}
self.cut = {
x: 30,
y: 30,
width: 100,
height: 100
}
// init cut.js
cut.apply(self)
describe('outsideBound', function () {
// 检查outsideBound方法是否已经bind到实例上
it('outsideBound funtion exist', function () {
const type = toString.call(self.outsideBound)
assert.equal(type, '[object Function]')
})
// 测试outsideBound
it('outsideBound functionality', function () {
// 左边界处理
let imgLeft
let imgTop
self.scaleWidth = 120
self.scaleHeight = 120
// 超出左边界
imgLeft = 40
imgTop = 30
self.outsideBound.apply(self, [imgLeft, imgTop])
assert.equal(self.imgLeft, self.cut.x)
// 未超出左边界, 超出右边界
imgLeft = 0
self.outsideBound.apply(self, [imgLeft, imgTop])
assert.equal(self.imgLeft, self.cut.width + self.cut.x - self.scaleWidth)
// 未超出左边界,未超出右边界
imgLeft = 15
self.outsideBound.apply(self, [imgLeft, imgTop])
assert.equal(self.imgLeft, imgLeft)
// 超出上边界
imgTop = 40
self.outsideBound.apply(self, [imgLeft, imgTop])
assert.equal(self.imgTop, self.cut.y)
// 未超出上边界,超出下边界
imgTop = 0
self.outsideBound.apply(self, [imgLeft, imgTop])
assert.equal(self.imgTop, self.cut.height + self.cut.y - self.scaleHeight)
// 未超出上边界,未超出下边界
imgTop = 15
self.outsideBound.apply(self, [imgLeft, imgTop])
assert.equal(self.imgTop, imgTop)
})
})
})