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
|
# frozen_string_literal: true
require 'tc_helper'
class TestVmlShape < Test::Unit::TestCase
def setup
p = Axlsx::Package.new
wb = p.workbook
@ws = wb.add_worksheet
@ws.add_comment ref: 'A1', text: 'penut machine', author: 'crank', visible: true
@ws.add_comment ref: 'C3', text: 'rust bucket', author: 'PO', visible: false
@comments = @ws.comments
end
def test_initialize
assert_raise(ArgumentError) { Axlsx::VmlDrawing.new }
end
def test_row
shape = @comments.first.vml_shape
assert_equal(0, shape.row)
shape = @comments.last.vml_shape
assert_equal(2, shape.row)
end
def test_column
shape = @comments.first.vml_shape
assert_equal(0, shape.column)
shape = @comments.last.vml_shape
assert_equal(2, shape.column)
end
def test_left_column
shape = @comments.first.vml_shape
shape.left_column = 3
assert_equal(3, shape.left_column)
assert_raise(ArgumentError) { shape.left_column = [] }
end
def test_left_offset
shape = @comments.first.vml_shape
shape.left_offset = 3
assert_equal(3, shape.left_offset)
assert_raise(ArgumentError) { shape.left_offset = [] }
end
def test_right_column
shape = @comments.first.vml_shape
shape.right_column = 3
assert_equal(3, shape.right_column)
assert_raise(ArgumentError) { shape.right_column = [] }
end
def test_right_offset
shape = @comments.first.vml_shape
shape.right_offset = 3
assert_equal(3, shape.right_offset)
assert_raise(ArgumentError) { shape.right_offset = [] }
end
def test_top_offset
shape = @comments.first.vml_shape
shape.top_offset = 3
assert_equal(3, shape.top_offset)
assert_raise(ArgumentError) { shape.top_offset = [] }
end
def test_bottom_offset
shape = @comments.first.vml_shape
shape.bottom_offset = 3
assert_equal(3, shape.bottom_offset)
assert_raise(ArgumentError) { shape.bottom_offset = [] }
end
def test_bottom_row
shape = @comments.first.vml_shape
shape.bottom_row = 3
assert_equal(3, shape.bottom_row)
assert_raise(ArgumentError) { shape.bottom_row = [] }
end
def test_top_row
shape = @comments.first.vml_shape
shape.top_row = 3
assert_equal(3, shape.top_row)
assert_raise(ArgumentError) { shape.top_row = [] }
end
def test_visible
shape = @comments.first.vml_shape
shape.visible = false
refute(shape.visible)
assert_raise(ArgumentError) { shape.visible = 'foo' }
end
def test_to_xml_string
str = @comments.vml_drawing.to_xml_string
doc = Nokogiri::XML(str)
assert_equal(2, doc.xpath("//v:shape").size)
assert_equal(1, doc.xpath("//x:Visible").size, 'ClientData/x:Visible element rendering')
@comments.each do |comment|
shape = comment.vml_shape
assert_equal(1, doc.xpath("//v:shape/x:ClientData/x:Row[text()='#{shape.row}']").size)
assert_equal(1, doc.xpath("//v:shape/x:ClientData/x:Column[text()='#{shape.column}']").size)
assert_equal(1, doc.xpath("//v:shape/x:ClientData/x:Anchor[text()='#{shape.left_column}, #{shape.left_offset}, #{shape.top_row}, #{shape.top_offset}, #{shape.right_column}, #{shape.right_offset}, #{shape.bottom_row}, #{shape.bottom_offset}']").size)
end
end
end
|