Skip to content

Commit 6b0a7be

Browse files
minor test refactoring and improvements in table, list and br components
1 parent 9dc0695 commit 6b0a7be

File tree

12 files changed

+66
-23
lines changed

12 files changed

+66
-23
lines changed

app/concepts/br/view/br.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- unless options[:times].nil?
22
- options[:times].times do
3-
%br
3+
%br{@tag_attributes}
44
- else
5-
%br
5+
%br{@tag_attributes}

app/concepts/ol/view/ol.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
%ol{"class": options[:class], "id": component_id}
1+
%ol{@tag_attributes}
22
- if block_given?
33
= yield
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
module Progress::Cell
22
class Progress < Component::Cell::Static
33

4+
REQUIRED_KEYS = [:max]
5+
6+
def setup
7+
@tag_attributes.merge!({
8+
'value': options[:value] ||= 0,
9+
'max': options[:max]
10+
})
11+
end
12+
413
end
514
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
%progress{"id": component_id, "class": options[:class], "value": options[:value], "max": options[:max]}
1+
%progress{@tag_attributes}
22
- if block_given?
33
= yield

app/concepts/table/view/table.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
%table{"class": options[:class], "id": component_id}
1+
%table{@tag_attributes}
22
- if block_given?
33
= yield

app/concepts/td/view/td.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
- if options[:text].nil?
2-
%td{"class": options[:class], "id": component_id}
2+
%td{@tag_attributes}
33
- if block_given?
44
= yield
55

66
- else
7-
%td{"class": options[:class], "id": component_id}
7+
%td{@tag_attributes}
88
= options[:text]

app/concepts/th/view/th.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
- if options[:text].nil?
2-
%th{"class": options[:class], "id": component_id}
2+
%th{@tag_attributes}
33
- if block_given?
44
= yield
55

66
- else
7-
%th{"class": options[:class], "id": component_id}
7+
%th{@tag_attributes}
88
= options[:text]

app/concepts/tr/view/tr.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
%tr{"class": options[:class], "id": component_id}
1+
%tr{@tag_attributes}
22
- if block_given?
33
= yield

spec/usage/components/br_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def response
1818
plain 'hello'
1919
br times: 5
2020
plain 'world!'
21+
22+
# br tag with id and class
23+
plain 'hello'
24+
br id: 'my-br', class: 'fancy-br-class'
25+
plain 'world!'
2126
}
2227
end
2328

@@ -39,6 +44,10 @@ def response
3944
<br>
4045
<br>
4146
world!
47+
48+
hello
49+
<br id="my-br" class="fancy-br-class">
50+
world!
4251
HTML
4352

4453
expected_static_output_2 = <<~HTML
@@ -53,6 +62,10 @@ def response
5362
<br/>
5463
<br/>
5564
world!
65+
66+
hello
67+
<br id="my-br" class="fancy-br-class">
68+
world!
5669
HTML
5770

5871
expect(stripped(static_output)).to ( include(stripped(expected_static_output_1)) or include(stripped(expected_static_output_2)) )

spec/usage/components/progress_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
describe 'Progress Component', type: :feature, js: true do
55

6-
it 'Example 1' do
6+
it 'Example 1: Test positive behavior' do
77

88
class ExamplePage < Page::Cell::Page
99

@@ -13,6 +13,8 @@ def response
1313
progress value: 75, max: 100
1414
# enhanced progress bar
1515
progress id: 'my-id', class: 'my-class', value: 33, max: 330
16+
# expect value to default to zero
17+
progress max: 500
1618
}
1719
end
1820

@@ -25,9 +27,28 @@ def response
2527
expected_static_output = <<~HTML
2628
<progress max="100" value="75"></progress>
2729
<progress id="my-id" max="330" value="33" class="my-class"></progress>
30+
<progress max="500" value="0"></progress>
2831
HTML
2932

3033
expect(stripped(static_output)).to include(stripped(expected_static_output))
3134
end
3235

36+
it 'Example 2: Test REQUIRED_KEYS' do
37+
38+
class ExamplePage < Page::Cell::Page
39+
40+
def response
41+
components {
42+
# miss max option
43+
progress value: 75
44+
}
45+
end
46+
47+
end
48+
49+
visit '/example'
50+
51+
expect(page).to have_content("progress > required key 'max' is missing")
52+
end
53+
3354
end

spec/usage/components/table_th_tr_td_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def prepare
7272

7373
def response
7474
components {
75-
table class: 'foo' do
76-
tr class: 'bar' do
75+
table id: 'my-table-component', class: 'foo' do
76+
tr id: 'my-first-table-row', class: 'bar' do
7777
@users.each do |user|
78-
th text: user
78+
th class: 'user-cell', text: user
7979
end
8080
end
8181
tr do
@@ -108,12 +108,12 @@ def response
108108
static_output = page.html
109109

110110
expected_static_output = <<~HTML
111-
<table class="foo">
111+
<table id="my-table-component" class="foo">
112112
<tbody>
113-
<tr class="bar">
114-
<th>Jonas</th>
115-
<th>Pascal</th>
116-
<th>Chris</th>
113+
<tr id="my-first-table-row" class="bar">
114+
<th class="user-cell">Jonas</th>
115+
<th class="user-cell">Pascal</th>
116+
<th class="user-cell">Chris</th>
117117
</tr>
118118
<tr>
119119
<td>One</td>

spec/usage/components/ul_ol_li_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def response
1717
end
1818

1919
# advanced unordered list
20-
ul id: 'custom-unordered-list' do
20+
ul id: 'custom-unordered-list', class: 'custom-list' do
2121
li class: 'inline-li-element', text: 'I am inline text'
2222
li class: 'yield-li-element' do
2323
plain 'I am yielded plain'
@@ -42,7 +42,7 @@ def response
4242
<li>I am simple!</li>
4343
</ul>
4444
45-
<ul id="custom-unordered-list">
45+
<ul id="custom-unordered-list" class="custom-list">
4646
<li class="inline-li-element">I am inline text</li>
4747
<li class="yield-li-element">I am yielded plain</li>
4848
<li class="inline-li-element">I am inline text</li>
@@ -66,7 +66,7 @@ def response
6666
end
6767

6868
# advanced ordered list
69-
ol id: 'custom-ordered-list' do
69+
ol id: 'custom-ordered-list', class: 'custom-list' do
7070
li class: 'inline-li-element', text: 'I am inline text'
7171
li class: 'yield-li-element' do
7272
plain 'I am yielded plain'
@@ -91,7 +91,7 @@ def response
9191
<li>I am simple!</li>
9292
</ol>
9393
94-
<ol id="custom-ordered-list">
94+
<ol id="custom-ordered-list" class="custom-list">
9595
<li class="inline-li-element">I am inline text</li>
9696
<li class="yield-li-element">I am yielded plain</li>
9797
<li class="inline-li-element">I am inline text</li>

0 commit comments

Comments
 (0)