-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathaccessibility_spec.rb
More file actions
100 lines (77 loc) · 2.62 KB
/
accessibility_spec.rb
File metadata and controls
100 lines (77 loc) · 2.62 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
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
# encoding: utf-8
require 'spec_helper'
describe 'Table Accessibility' do
let(:pdf) { Prawn::Document.new(marked: true, language: 'en-US', margin: 0) }
describe 'tagged table rendering' do
it 'wraps the table in a Table structure element' do
data = [['Name', 'Age'], ['Alice', '30']]
pdf.table(data, header: true)
output = pdf.render
expect(output).to include('/Table')
expect(output).to include('/StructTreeRoot')
end
it 'creates TR structure elements for each row' do
data = [['A', 'B'], ['C', 'D']]
pdf.table(data)
output = pdf.render
expect(output).to include('/TR')
end
it 'creates TH elements for header cells' do
data = [['Name', 'Age'], ['Alice', '30']]
pdf.table(data, header: true)
output = pdf.render
expect(output).to include('/TH')
end
it 'creates TD elements for data cells' do
data = [['Name', 'Age'], ['Alice', '30']]
pdf.table(data, header: true)
output = pdf.render
expect(output).to include('/TD')
end
it 'sets Scope on TH elements' do
data = [['Name', 'Age'], ['Alice', '30']]
pdf.table(data, header: true)
output = pdf.render
expect(output).to include('/Scope /Column')
end
it 'marks all cells as TD when no header is set' do
data = [['A', 'B'], ['C', 'D']]
pdf.table(data)
output = pdf.render
expect(output).to include('/TD')
expect(output).not_to include('/TH')
end
it 'supports multiple header rows' do
data = [['Group', ''], ['Name', 'Age'], ['Alice', '30']]
pdf.table(data, header: 2)
output = pdf.render
expect(output).to include('/TH')
end
end
describe 'untagged table rendering' do
it 'does not emit structure tags when not marked' do
plain_pdf = Prawn::Document.new(margin: 0)
data = [['Name', 'Age'], ['Alice', '30']]
plain_pdf.table(data, header: true)
output = plain_pdf.render
expect(output).not_to include('/StructTreeRoot')
expect(output).not_to include('/TH')
expect(output).not_to include('/TD')
end
end
describe 'Cell#header?' do
it 'returns true for cells in header rows' do
data = [['Name', 'Age'], ['Alice', '30']]
table = pdf.make_table(data, header: true)
header_cell = table.cells[0, 0]
data_cell = table.cells[1, 0]
expect(header_cell).to be_header
expect(data_cell).not_to be_header
end
it 'returns false when no header is set' do
data = [['A', 'B'], ['C', 'D']]
table = pdf.make_table(data)
expect(table.cells[0, 0]).not_to be_header
end
end
end