Skip to content

Commit bac1eef

Browse files
author
Nils Henning
committed
update async component and specs
1 parent 990c801 commit bac1eef

File tree

4 files changed

+25
-150
lines changed

4 files changed

+25
-150
lines changed

spec/0.8/components/async_new_spec.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# Temporary new home for async to get the new examples going
55
# Examples adapted from the original async_spec
66
describe Matestack::Ui::Core::Async::Async, type: :feature, js: true do
7-
it "Example 1 - Rerender on event on page-level" do
87

8+
it "Example 1 - Rerender on event on page-level" do
99
class CoolAsync < described_class
1010
def response
1111
div id: "my-div" do
@@ -17,23 +17,18 @@ def response
1717
end
1818

1919
class ExamplePage < Matestack::Ui::Page
20-
2120
def response
2221
my_async_component rerender_on: "my_event"
2322
end
24-
2523
end
2624

2725
visit "/example"
28-
2926
element = page.find("#my-div")
3027
before_content = element.text
31-
3228
page.execute_script('MatestackUiCore.matestackEventHub.$emit("my_event")')
3329

3430
# TODO: show Jonas re flakies
3531
expect(page).to have_no_content(before_content)
36-
3732
expect(page).to have_css("#my-div")
3833
end
3934

spec/0.8/components/dynamic/async/defer_spec.rb

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
describe "defer" do
77

88
it "deferred loading without any timeout, deferred request right after component mounting" do
9-
109
class SomeComponent < Matestack::Ui::StaticComponent
1110
def response
1211
async defer: true do
@@ -21,7 +20,6 @@ def response
2120

2221

2322
class ExamplePage < Matestack::Ui::Page
24-
2523
def prepare
2624
@current_time = DateTime.now.strftime('%Q')
2725
end
@@ -42,30 +40,23 @@ def response
4240
end
4341
some_component current_time: @current_time
4442
end
45-
4643
end
4744

4845
visit "/example"
4946
sleep 0.5
50-
5147
initial_timestamp = page.find("#my-reference-div").text #initial page load
5248
non_deferred_timestamp = page.find("#my-not-deferred-div").text #initial page load
53-
5449
deferred_timestamp = page.find("#my-deferred-div").text #deferred loading
5550
deferred_timestamp_on_component = page.find("#my-deferred-div-on-component").text #deferred loading
56-
5751
expect(non_deferred_timestamp).to eq initial_timestamp
5852
expect(deferred_timestamp).to be > initial_timestamp
5953
expect(deferred_timestamp_on_component).to be > initial_timestamp
60-
6154
expect(deferred_timestamp.to_i - initial_timestamp.to_i).to be_between(0, 2000).inclusive
6255
expect(deferred_timestamp_on_component.to_i - initial_timestamp.to_i).to be_between(0, 2000).inclusive
6356
end
6457

6558
it "deferred loading with a specific timeout" do
66-
6759
class ExamplePage < Matestack::Ui::Page
68-
6960
def prepare
7061
@current_time = DateTime.now.strftime('%Q')
7162
end
@@ -85,26 +76,20 @@ def response
8576
end
8677
end
8778
end
88-
8979
end
9080

9181
visit "/example"
92-
9382
initial_timestamp = page.find("#my-reference-div").text #initial page load
9483
non_deferred_timestamp = page.find("#my-not-deferred-div").text #initial page load
95-
9684
deferred_timestamp = page.find("#my-deferred-div").text #deferred loading
97-
9885
expect(non_deferred_timestamp).to eq initial_timestamp
9986
expect(deferred_timestamp).to be > initial_timestamp
10087
expect(deferred_timestamp.to_i - initial_timestamp.to_i).to be_between(1000, 3000).inclusive
101-
10288
end
10389

10490
it "multiple deferred loadings with a specific timeout" do
10591

10692
class ExamplePage < Matestack::Ui::Page
107-
10893
def prepare
10994
@current_time = DateTime.now.strftime('%Q')
11095
end
@@ -129,29 +114,22 @@ def response
129114
end
130115
end
131116
end
132-
133117
end
134118

135119
visit "/example"
136-
137120
initial_timestamp = page.find("#my-reference-div").text #initial page load
138121
non_deferred_timestamp = page.find("#my-not-deferred-div").text #initial page load
139-
140122
deferred_timestamp = page.find("#my-deferred-div").text #deferred loading
141123
second_deferred_timestamp = page.find("#my-second-deferred-div").text #deferred loading
142-
143124
expect(non_deferred_timestamp).to eq initial_timestamp
144125
expect(deferred_timestamp).to be > initial_timestamp
145126
expect(second_deferred_timestamp).to be > initial_timestamp
146127
expect(deferred_timestamp.to_i - initial_timestamp.to_i).to be_between(1000, 3000).inclusive
147128
expect(second_deferred_timestamp.to_i - initial_timestamp.to_i).to be_between(2000, 4000).inclusive
148-
149129
end
150130

151131
it "deferred loading without any timeout, triggered by on_show event" do
152-
153132
class ExamplePage < Matestack::Ui::Page
154-
155133
def prepare
156134
@current_time = DateTime.now.strftime('%Q')
157135
end
@@ -167,34 +145,23 @@ def response
167145
end
168146
end
169147
end
170-
171148
end
172149

173150
visit "/example"
174-
175151
initial_timestamp = page.find("#my-reference-div").text #initial page load
176-
177152
expect(page).not_to have_content("waited for 'my_event'")
178153

179154
sleep 2
180-
181155
page.execute_script('MatestackUiCore.matestackEventHub.$emit("my_event")')
182-
183156
expect(page).to have_content("waited for 'my_event'")
184-
185157
deferred_timestamp = page.find("#my-deferred-div").text #deferred loading after click
186-
187158
expect(deferred_timestamp.to_i - initial_timestamp.to_i).to be_between(2000, 4000).inclusive
188159

189160
sleep 1
190-
191161
page.execute_script('MatestackUiCore.matestackEventHub.$emit("my_other_event")')
192162
page.execute_script('MatestackUiCore.matestackEventHub.$emit("my_event")')
193-
194163
new_deferred_timestamp = page.find("#my-deferred-div").text #deferred loading after another click
195-
196164
expect(new_deferred_timestamp.to_i - deferred_timestamp.to_i).to be_between(1000, 2000).inclusive
197-
198165
end
199166

200167
end

0 commit comments

Comments
 (0)