/
AlignTest.coffee
146 lines (114 loc) · 3.5 KB
/
AlignTest.coffee
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
describe "Align", ->
createAlignedLayers = (property,value,properties={}) ->
properties.width ?= 500
properties.height ?= 300
parent = new Layer properties
child = createSublayer(parent,property,value)
{parent: parent, child: child}
createSublayer = (layer,property, value) ->
layer = new Layer
width: 100
height: 200
superLayer: layer
layer[property] = value
layer
describe "center", ->
it "should center the layer", ->
{child} = createAlignedLayers('x',Align.center)
child.x.should.equal 200
{child} = createAlignedLayers('y',Align.center)
child.y.should.equal 50
it "should work when the layer has no parent", ->
layer = new Layer
width: 100
height: 150
x: Align.center
y: Align.center
layer.x.should.equal 150
layer.y.should.equal 75
it "should take borderWidth into account", ->
{child} = createAlignedLayers('x',Align.center,{borderWidth:30})
child.x.should.equal 170
{child} = createAlignedLayers('y',Align.center,{borderWidth:30})
child.y.should.equal 20
describe "left", ->
it "should left align the layer", ->
{child} = createAlignedLayers('x',Align.left)
child.x.should.equal 0
it "should work when the layer has no parent", ->
layer = new Layer
width: 100
x: Align.left
layer.x.should.equal 0
it "should take borderWidth into account", ->
{child} = createAlignedLayers('x',Align.left,{borderWidth:30})
child.x.should.equal 0
describe "right", ->
it "should right align the layer", ->
{child} = createAlignedLayers('x',Align.right)
child.x.should.equal 400
it "should work when the layer has no parent", ->
layer = new Layer
width: 100
x: Align.right
layer.x.should.equal 300
it "should take borderWidth into account", ->
{child} = createAlignedLayers('x',Align.right,{borderWidth:30})
child.x.should.equal 340
describe "top", ->
it "should top align the layer", ->
{child} = createAlignedLayers('y',Align.top)
child.y.should.equal 0
it "should work when the layer has no parent", ->
layer = new Layer
height: 100
y: Align.top
layer.y.should.equal 0
it "should take borderWidth into account", ->
{child} = createAlignedLayers('y',Align.top,{borderWidth:30})
child.y.should.equal 0
describe "bottom", ->
it "should bottom align the layer", ->
{child} = createAlignedLayers('y',Align.bottom)
child.y.should.equal 100
it "should work when the layer has no parent", ->
layer = new Layer
height: 100
y: Align.bottom
layer.y.should.equal 200
it "should take borderWidth into account", ->
{child} = createAlignedLayers('y',Align.bottom,{borderWidth:30})
child.y.should.equal 40
describe "constructors", ->
it "should work with size", ->
test = new Layer
parent: new Layer size: 200
x: Align.center
y: Align.center
size: 100
test.x.should.equal 50
test.y.should.equal 50
it "should work with point and size", ->
test = new Layer
parent: new Layer size: 200
size: 100
point: Align.center
test.x.should.equal 50
test.y.should.equal 50
it "should work with point", ->
test = new Layer
parent: new Layer size: 200
width: 100
height: 100
point: Align.center
test.x.should.equal 50
test.y.should.equal 50
it "should work with both size and width height", ->
test = new Layer
parent: new Layer size: 200
width: 100
height: 100
point: Align.center
size: 200
test.x.should.equal 50
test.y.should.equal 50