Skip to content

Adds docs and tests for onclick component #96

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
Aug 17, 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
21 changes: 19 additions & 2 deletions docs/components/onclick.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# matestack core component: Action
# matestack core component: Onclick

Show [specs](../../spec/usage/components/action_spec.rb)
Show [specs](../../spec/usage/components/onclick_spec.rb)

The `onclick` component renders a div that runs a function when the user clicks on it. This is a simple component that can be used to wrap components with a onclick function that will emit a event. The event that must be emitted onclick can defined by passing a hash into the `onclick` component that has the key `emit`. See example below for more details.

```ruby
class Pages::MyPage::Home < Matestack::Ui::Page
def response
components{
onclick(emit: "abc") do
plain "Hello world"
end
}
async rerender_on: "abc" do
plain "Render this text when the 'abc' event is emitted"
end
end
end
```
46 changes: 46 additions & 0 deletions spec/usage/components/onclick_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require_relative "../../support/utils"
include Utils

describe "Onclick Component", type: :feature, js: true do

it "Example 1" do
class ExamplePage < Matestack::Ui::Page
def response
components {
async show_on: 'show_message' do
div id: 'the_message' do
plain "{{event.data.message}}"
end
end
onclick click_function do
div id: 'click_this' do
plain "Click me"
end
end
}
end

def click_function
return {
emit: 'show_message'
}
end
end

visit "/example"

static_output = page.html

expected_static_output = <<~HTML
<div><div id="click_this">Click me</div></div>
HTML

expect(stripped(static_output)).to include(stripped(expected_static_output))
find('div', id: 'click_this').click

new_expected_static_output = <<~HTML
<div id="the_message">This is a cool message</div>
<div>Click me!</div>
HTML
end
end