Skip to content

Commit 990c801

Browse files
author
Nils Henning
committed
update action component and specs
1 parent c5c4380 commit 990c801

File tree

5 files changed

+224
-443
lines changed

5 files changed

+224
-443
lines changed

app/concepts/matestack/ui/core/action/action.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
module Matestack::Ui::Core::Action
22
class Action < Matestack::Ui::Core::Component::Dynamic
33

4+
def vuejs_component_name
5+
'matestack-ui-core-action'
6+
end
7+
48
def setup
59
@component_config[:action_path] = action_path
610
@component_config[:method] = options[:method]

lib/matestack/ui/core/components.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def self.require_core_component(name)
2727
require_app_path "concepts/matestack/ui/core/component/static"
2828

2929
require_core_component "abbr"
30+
require_core_component "action"
3031
require_core_component "address"
3132
require_core_component "area"
3233
require_core_component "article"
@@ -124,6 +125,7 @@ def self.require_core_component(name)
124125

125126
Matestack::Ui::Core::Component::Registry.register_components(
126127
abbr: Matestack::Ui::Core::Abbr::Abbr,
128+
action: Matestack::Ui::Core::Action::Action,
127129
address: Matestack::Ui::Core::Address::Address,
128130
area: Matestack::Ui::Core::Area::Area,
129131
article: Matestack::Ui::Core::Article::Article,

spec/0.8/components/action/delay_spec.rb

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,34 @@
55
describe "Action Component", type: :feature, js: true do
66

77
before :each do
8-
98
class ActionTestController < TestController
10-
119
def test
1210
receive_timestamp = DateTime.now.strftime('%Q')
1311
render json: { received_at: receive_timestamp }, status: 200
1412
end
15-
1613
end
1714

1815
allow_any_instance_of(ActionTestController).to receive(:expect_params)
19-
2016
end
2117

2218
describe "delay attribute" do
2319

2420
it "if set, delays action submit" do
25-
2621
Rails.application.routes.append do
2722
post '/action_test', to: 'action_test#test', as: 'action_delay_test'
2823
end
2924
Rails.application.reload_routes!
3025

31-
3226
class ExamplePage < Matestack::Ui::Page
33-
3427
def response
35-
components {
36-
action action_config do
37-
button text: "Click me!"
38-
end
39-
div id: "timestamp" do
40-
async show_on: "action_submitted_successfully" do
41-
plain "{{event.data.received_at}}"
42-
end
28+
action action_config do
29+
button text: "Click me!"
30+
end
31+
div id: "timestamp" do
32+
async show_on: "action_submitted_successfully" do
33+
plain "{{event.data.received_at}}"
4334
end
44-
}
35+
end
4536
end
4637

4738
def action_config
@@ -57,21 +48,15 @@ def action_config
5748
}
5849
}
5950
end
60-
6151
end
6252

6353
visit "/example"
64-
6554
submit_timestamp = DateTime.now.strftime('%Q').to_i
6655
click_button "Click me!"
67-
6856
sleep 1.5
69-
7057
element = page.find("#timestamp")
7158
receive_timestamp = element.text.to_i
72-
7359
expect(receive_timestamp - submit_timestamp).to be > 1000
74-
7560
end
7661

7762
end

spec/0.8/components/action/emit_spec.rb

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,31 @@
55
describe "Action Component", type: :feature, js: true do
66

77
before :each do
8-
98
class ActionTestController < TestController
10-
119
def test
1210
render json: { }, status: 200
1311
end
14-
1512
end
1613

1714
allow_any_instance_of(ActionTestController).to receive(:expect_params)
18-
1915
end
2016

2117
describe "emit attribute" do
2218

2319
it "if set, emits event directly when action is submitted (not waiting for success or failure)" do
24-
2520
Rails.application.routes.append do
2621
post '/action_test', to: 'action_test#test', as: 'action_emit'
2722
end
2823
Rails.application.reload_routes!
2924

30-
3125
class ExamplePage < Matestack::Ui::Page
32-
3326
def response
34-
components {
35-
action action_config do
36-
button text: "Click me!"
37-
end
38-
async show_on: "action_submitted" do
39-
plain "action submitted!"
40-
end
41-
}
27+
action action_config do
28+
button text: "Click me!"
29+
end
30+
async show_on: "action_submitted" do
31+
plain "action submitted!"
32+
end
4233
end
4334

4435
def action_config
@@ -51,16 +42,12 @@ def action_config
5142
emit: "action_submitted"
5243
}
5344
end
54-
5545
end
5646

5747
visit "/example"
58-
5948
expect_any_instance_of(ActionTestController).to receive(:expect_params)
6049
.with(hash_including(:foo => "bar"))
61-
6250
click_button "Click me!"
63-
6451
expect(page).to have_content("action submitted!")
6552
end
6653

0 commit comments

Comments
 (0)