Skip to content

Add core component tests #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/concepts/br/view/br.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- unless options[:times].nil?
- options[:times].times do
%br
%br{@tag_attributes}
- else
%br
%br{@tag_attributes}
2 changes: 1 addition & 1 deletion app/concepts/ol/view/ol.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
%ol{"class": options[:class], "id": component_id}
%ol{@tag_attributes}
- if block_given?
= yield
9 changes: 9 additions & 0 deletions app/concepts/progress/cell/progress.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
module Progress::Cell
class Progress < Component::Cell::Static

REQUIRED_KEYS = [:max]

def setup
@tag_attributes.merge!({
'value': options[:value] ||= 0,
'max': options[:max]
})
end

end
end
2 changes: 1 addition & 1 deletion app/concepts/progress/view/progress.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
%progress{"id": component_id, "class": options[:class], "value": options[:value], "max": options[:max]}
%progress{@tag_attributes}
- if block_given?
= yield
2 changes: 1 addition & 1 deletion app/concepts/table/view/table.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
%table{"class": options[:class], "id": component_id}
%table{@tag_attributes}
- if block_given?
= yield
4 changes: 2 additions & 2 deletions app/concepts/td/view/td.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- if options[:text].nil?
%td{"class": options[:class], "id": component_id}
%td{@tag_attributes}
- if block_given?
= yield

- else
%td{"class": options[:class], "id": component_id}
%td{@tag_attributes}
= options[:text]
4 changes: 2 additions & 2 deletions app/concepts/th/view/th.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- if options[:text].nil?
%th{"class": options[:class], "id": component_id}
%th{@tag_attributes}
- if block_given?
= yield

- else
%th{"class": options[:class], "id": component_id}
%th{@tag_attributes}
= options[:text]
2 changes: 1 addition & 1 deletion app/concepts/tr/view/tr.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
%tr{"class": options[:class], "id": component_id}
%tr{@tag_attributes}
- if block_given?
= yield
2 changes: 1 addition & 1 deletion matestack-ui-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |s|
s.name = "matestack-ui-core"
s.version = Matestack::Ui::Core::VERSION
s.authors = ["Jonas Jabari", "Pascal Wengerter", "Christopher Bastert"]
s.email = ["jonas@basemate.io", "pascal@basemate.io", "chris@basemate.io"]
s.email = ["jonas@basemate.com", "pascal@basemate.com", "chris@basemate.com"]
s.homepage = "https://basemate.io"
s.summary = "Escape the frontend hustle. Create beautiful software easily. Use matestack."
s.description = "We're replacing the original view-layer of Ruby on Rails, the most productive MVC framework we know, with our technology. By introducing matestack we get dynamic, fast and simple user interfaces without the need to touch HTML/HAML/ERB/JS/CSS. Plus, it feels like a single page application, but there's no need for all the API hustle SPAs usually bring with them."
Expand Down
13 changes: 13 additions & 0 deletions spec/usage/components/br_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def response
plain 'hello'
br times: 5
plain 'world!'

# br tag with id and class
plain 'hello'
br id: 'my-br', class: 'fancy-br-class'
plain 'world!'
}
end

Expand All @@ -39,6 +44,10 @@ def response
<br>
<br>
world!

hello
<br id="my-br" class="fancy-br-class">
world!
HTML

expected_static_output_2 = <<~HTML
Expand All @@ -53,6 +62,10 @@ def response
<br/>
<br/>
world!

hello
<br id="my-br" class="fancy-br-class">
world!
HTML

expect(stripped(static_output)).to ( include(stripped(expected_static_output_1)) or include(stripped(expected_static_output_2)) )
Expand Down
23 changes: 22 additions & 1 deletion spec/usage/components/progress_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

it 'Example 1' do
it 'Example 1: Test positive behavior' do

class ExamplePage < Page::Cell::Page

Expand All @@ -13,6 +13,8 @@ def response
progress value: 75, max: 100
# enhanced progress bar
progress id: 'my-id', class: 'my-class', value: 33, max: 330
# expect value to default to zero
progress max: 500
}
end

Expand All @@ -25,9 +27,28 @@ def response
expected_static_output = <<~HTML
<progress max="100" value="75"></progress>
<progress id="my-id" max="330" value="33" class="my-class"></progress>
<progress max="500" value="0"></progress>
HTML

expect(stripped(static_output)).to include(stripped(expected_static_output))
end

it 'Example 2: Test REQUIRED_KEYS' do

class ExamplePage < Page::Cell::Page

def response
components {
# miss max option
progress value: 75
}
end

end

visit '/example'

expect(page).to have_content("progress > required key 'max' is missing")
end

end
16 changes: 8 additions & 8 deletions spec/usage/components/table_th_tr_td_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def prepare

def response
components {
table class: 'foo' do
tr class: 'bar' do
table id: 'my-table-component', class: 'foo' do
tr id: 'my-first-table-row', class: 'bar' do
@users.each do |user|
th text: user
th class: 'user-cell', text: user
end
end
tr do
Expand Down Expand Up @@ -108,12 +108,12 @@ def response
static_output = page.html

expected_static_output = <<~HTML
<table class="foo">
<table id="my-table-component" class="foo">
<tbody>
<tr class="bar">
<th>Jonas</th>
<th>Pascal</th>
<th>Chris</th>
<tr id="my-first-table-row" class="bar">
<th class="user-cell">Jonas</th>
<th class="user-cell">Pascal</th>
<th class="user-cell">Chris</th>
</tr>
<tr>
<td>One</td>
Expand Down
8 changes: 4 additions & 4 deletions spec/usage/components/ul_ol_li_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def response
end

# advanced unordered list
ul id: 'custom-unordered-list' do
ul id: 'custom-unordered-list', class: 'custom-list' do
li class: 'inline-li-element', text: 'I am inline text'
li class: 'yield-li-element' do
plain 'I am yielded plain'
Expand All @@ -42,7 +42,7 @@ def response
<li>I am simple!</li>
</ul>

<ul id="custom-unordered-list">
<ul id="custom-unordered-list" class="custom-list">
<li class="inline-li-element">I am inline text</li>
<li class="yield-li-element">I am yielded plain</li>
<li class="inline-li-element">I am inline text</li>
Expand All @@ -66,7 +66,7 @@ def response
end

# advanced ordered list
ol id: 'custom-ordered-list' do
ol id: 'custom-ordered-list', class: 'custom-list' do
li class: 'inline-li-element', text: 'I am inline text'
li class: 'yield-li-element' do
plain 'I am yielded plain'
Expand All @@ -91,7 +91,7 @@ def response
<li>I am simple!</li>
</ol>

<ol id="custom-ordered-list">
<ol id="custom-ordered-list" class="custom-list">
<li class="inline-li-element">I am inline text</li>
<li class="yield-li-element">I am yielded plain</li>
<li class="inline-li-element">I am inline text</li>
Expand Down