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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
describe('Image', function() {
var image
beforeEach(function() {
image = draw.image(imageUrl, 100, 100)
})
afterEach(function() {
draw.clear()
})
describe('x()', function() {
it('should return the value of x without an argument', function() {
expect(image.x()).toBe(0)
})
it('should set the value of x with the first argument', function() {
image.x(123)
var box = image.bbox()
expect(box.x).toBe(123)
})
})
describe('y()', function() {
it('should return the value of y without an argument', function() {
expect(image.y()).toBe(0)
})
it('should set the value of y with the first argument', function() {
image.y(345)
var box = image.bbox()
expect(box.y).toBe(345)
})
})
describe('cx()', function() {
it('should return the value of cx without an argument', function() {
expect(image.cx()).toBe(50)
})
it('should set the value of cx with the first argument', function() {
image.cx(123)
var box = image.bbox()
expect(box.cx).toBe(123)
})
})
describe('cy()', function() {
it('should return the value of cy without an argument', function() {
expect(image.cy()).toBe(50)
})
it('should set the value of cy with the first argument', function() {
image.cy(345)
var box = image.bbox()
expect(box.cy).toBe(345)
})
})
describe('move()', function() {
it('should set the x and y position', function() {
image.move(123,456)
expect(image.node.getAttribute('x')).toBe('123')
expect(image.node.getAttribute('y')).toBe('456')
})
})
describe('center()', function() {
it('should set the cx and cy position', function() {
image.center(321,567)
var box = image.bbox()
expect(box.cx).toBe(321)
expect(box.cy).toBe(567)
})
})
describe('size()', function() {
it('should define the width and height of the element', function() {
image.size(987,654)
expect(image.node.getAttribute('width')).toBe('987')
expect(image.node.getAttribute('height')).toBe('654')
})
})
describe('scale()', function() {
it('should scale the element universally with one argument', function() {
var box = image.scale(2).bbox()
expect(box.width).toBe(image.attr('width') * 2)
expect(box.height).toBe(image.attr('height') * 2)
})
it('should scale the element over individual x and y axes with two arguments', function() {
var box = image.scale(2, 3.5).bbox()
expect(box.width).toBe(image.attr('width') * 2)
expect(box.height).toBe(image.attr('height') * 3.5)
})
})
describe('translate()', function() {
it('should set the translation of an element', function() {
image.transform({ x: 12, y: 12 })
expect(image.node.getAttribute('transform')).toBe('translate(12,12)')
})
})
})
|