6
6
describe "defer" do
7
7
8
8
it "deferred loading without any timeout, deferred request right after component mounting" do
9
-
10
9
class SomeComponent < Matestack ::Ui ::StaticComponent
11
10
def response
12
11
async defer : true do
@@ -21,7 +20,6 @@ def response
21
20
22
21
23
22
class ExamplePage < Matestack ::Ui ::Page
24
-
25
23
def prepare
26
24
@current_time = DateTime . now . strftime ( '%Q' )
27
25
end
@@ -42,30 +40,23 @@ def response
42
40
end
43
41
some_component current_time : @current_time
44
42
end
45
-
46
43
end
47
44
48
45
visit "/example"
49
46
sleep 0.5
50
-
51
47
initial_timestamp = page . find ( "#my-reference-div" ) . text #initial page load
52
48
non_deferred_timestamp = page . find ( "#my-not-deferred-div" ) . text #initial page load
53
-
54
49
deferred_timestamp = page . find ( "#my-deferred-div" ) . text #deferred loading
55
50
deferred_timestamp_on_component = page . find ( "#my-deferred-div-on-component" ) . text #deferred loading
56
-
57
51
expect ( non_deferred_timestamp ) . to eq initial_timestamp
58
52
expect ( deferred_timestamp ) . to be > initial_timestamp
59
53
expect ( deferred_timestamp_on_component ) . to be > initial_timestamp
60
-
61
54
expect ( deferred_timestamp . to_i - initial_timestamp . to_i ) . to be_between ( 0 , 2000 ) . inclusive
62
55
expect ( deferred_timestamp_on_component . to_i - initial_timestamp . to_i ) . to be_between ( 0 , 2000 ) . inclusive
63
56
end
64
57
65
58
it "deferred loading with a specific timeout" do
66
-
67
59
class ExamplePage < Matestack ::Ui ::Page
68
-
69
60
def prepare
70
61
@current_time = DateTime . now . strftime ( '%Q' )
71
62
end
@@ -85,26 +76,20 @@ def response
85
76
end
86
77
end
87
78
end
88
-
89
79
end
90
80
91
81
visit "/example"
92
-
93
82
initial_timestamp = page . find ( "#my-reference-div" ) . text #initial page load
94
83
non_deferred_timestamp = page . find ( "#my-not-deferred-div" ) . text #initial page load
95
-
96
84
deferred_timestamp = page . find ( "#my-deferred-div" ) . text #deferred loading
97
-
98
85
expect ( non_deferred_timestamp ) . to eq initial_timestamp
99
86
expect ( deferred_timestamp ) . to be > initial_timestamp
100
87
expect ( deferred_timestamp . to_i - initial_timestamp . to_i ) . to be_between ( 1000 , 3000 ) . inclusive
101
-
102
88
end
103
89
104
90
it "multiple deferred loadings with a specific timeout" do
105
91
106
92
class ExamplePage < Matestack ::Ui ::Page
107
-
108
93
def prepare
109
94
@current_time = DateTime . now . strftime ( '%Q' )
110
95
end
@@ -129,29 +114,22 @@ def response
129
114
end
130
115
end
131
116
end
132
-
133
117
end
134
118
135
119
visit "/example"
136
-
137
120
initial_timestamp = page . find ( "#my-reference-div" ) . text #initial page load
138
121
non_deferred_timestamp = page . find ( "#my-not-deferred-div" ) . text #initial page load
139
-
140
122
deferred_timestamp = page . find ( "#my-deferred-div" ) . text #deferred loading
141
123
second_deferred_timestamp = page . find ( "#my-second-deferred-div" ) . text #deferred loading
142
-
143
124
expect ( non_deferred_timestamp ) . to eq initial_timestamp
144
125
expect ( deferred_timestamp ) . to be > initial_timestamp
145
126
expect ( second_deferred_timestamp ) . to be > initial_timestamp
146
127
expect ( deferred_timestamp . to_i - initial_timestamp . to_i ) . to be_between ( 1000 , 3000 ) . inclusive
147
128
expect ( second_deferred_timestamp . to_i - initial_timestamp . to_i ) . to be_between ( 2000 , 4000 ) . inclusive
148
-
149
129
end
150
130
151
131
it "deferred loading without any timeout, triggered by on_show event" do
152
-
153
132
class ExamplePage < Matestack ::Ui ::Page
154
-
155
133
def prepare
156
134
@current_time = DateTime . now . strftime ( '%Q' )
157
135
end
@@ -167,34 +145,23 @@ def response
167
145
end
168
146
end
169
147
end
170
-
171
148
end
172
149
173
150
visit "/example"
174
-
175
151
initial_timestamp = page . find ( "#my-reference-div" ) . text #initial page load
176
-
177
152
expect ( page ) . not_to have_content ( "waited for 'my_event'" )
178
153
179
154
sleep 2
180
-
181
155
page . execute_script ( 'MatestackUiCore.matestackEventHub.$emit("my_event")' )
182
-
183
156
expect ( page ) . to have_content ( "waited for 'my_event'" )
184
-
185
157
deferred_timestamp = page . find ( "#my-deferred-div" ) . text #deferred loading after click
186
-
187
158
expect ( deferred_timestamp . to_i - initial_timestamp . to_i ) . to be_between ( 2000 , 4000 ) . inclusive
188
159
189
160
sleep 1
190
-
191
161
page . execute_script ( 'MatestackUiCore.matestackEventHub.$emit("my_other_event")' )
192
162
page . execute_script ( 'MatestackUiCore.matestackEventHub.$emit("my_event")' )
193
-
194
163
new_deferred_timestamp = page . find ( "#my-deferred-div" ) . text #deferred loading after another click
195
-
196
164
expect ( new_deferred_timestamp . to_i - deferred_timestamp . to_i ) . to be_between ( 1000 , 2000 ) . inclusive
197
-
198
165
end
199
166
200
167
end
0 commit comments