Skip to content

Implementing issue 83 #84

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 2 commits into from
Jul 23, 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
11 changes: 5 additions & 6 deletions app/concepts/matestack/ui/core/link/link.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
- if options[:text].nil?
= link_to link_path, @tag_attributes do
- if block_given?
= yield
- else
= link_to options[:text], link_path, @tag_attributes
%a{@tag_attributes}
- if options[:text].nil? && block_given?
= yield
- else
= options[:text]
6 changes: 4 additions & 2 deletions app/concepts/matestack/ui/core/link/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ class Link < Matestack::Ui::Core::Component::Static
REQUIRED_KEYS = [:path]

def setup
@tag_attributes.merge!({ "class": options[:class],
@tag_attributes.merge!({
"class": options[:class],
"id": component_id,
"method": options[:method],
"target": options[:target] ||= nil
"target": options[:target] ||= nil,
"href": link_path
})
end

Expand Down
156 changes: 122 additions & 34 deletions spec/usage/components/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,127 @@
include Utils

describe 'Link Component', type: :feature, js: true do
# does not work at all. Maybe a problem with the dummy application?
# it 'Example 1' do
#
# class ExamplePage < Matestack::Ui::Page
#
# def response
# components {
# div id: "foo", class: "bar" do
# link path: "https://matestack.org", text: 'here'
# end
# # div id: "foo", class: "bar" do
# # link path: "https://matestack.org" do
# # plain 'here'
# # end
# # end
#
# }
# end
#
# end
#
# visit "/example"
#
# sleep 500
# static_output = page.html
#
# expected_static_output = <<~HTML
# <div id="foo" class="bar">
# <a href="https://matestack.org">here</a>
# </div>
# HTML
#
# expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
# end

it 'Example 1 - Text Option' do

class ExamplePage < Matestack::Ui::Page

def response
components {
div id: "foo", class: "bar" do
link path: "https://matestack.org", text: 'here'
end
}
end

end

visit "/example"

static_output = page.html

expected_static_output = <<~HTML
<div id="foo" class="bar">
<a href="https://matestack.org">here</a>
</div>
HTML

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

it 'Example 2 - Yield' do

class ExamplePage < Matestack::Ui::Page

def response
components {
div id: "foo", class: "bar" do
link path: "https://matestack.org" do
plain 'here'
end
end

}
end

end

visit "/example"

static_output = page.html

expected_static_output = <<~HTML
<div id="foo" class="bar">
<a href="https://matestack.org">here</a>
</div>
HTML

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

it 'Example 3 - Target' do

class ExamplePage < Matestack::Ui::Page

def response
components {
div id: "foo", class: "bar" do
link path: "https://matestack.org", target: "_blank" do
plain 'here'
end
end

}
end

end

visit "/example"

static_output = page.html

expected_static_output = <<~HTML
<div id="foo" class="bar">
<a href="https://matestack.org" target="_blank">here</a>
</div>
HTML

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

it 'Example 4 - Rails Routing' do

Rails.application.routes.append do
get '/some_link_test_path', to: 'page_test#my_action', as: 'link_test'
end
Rails.application.reload_routes!

class ExamplePage < Matestack::Ui::Page

def response
components {
div id: "foo", class: "bar" do
link path: :link_test_path do
plain 'here'
end
end

}
end

end

visit "/example"

static_output = page.html

expected_static_output = <<~HTML
<div id="foo" class="bar">
<a href="/some_link_test_path">here</a>
</div>
HTML

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

end