@@ -43,6 +43,27 @@ def self.semaphore
4343 FactoryBot . create ( :user , first_name : 'Coffee' , last_name : 'Boxer' )
4444 end
4545
46+ it "will display the while loading message for a fetch within a component" do
47+ ReactiveRecord ::Operations ::Fetch . semaphore . synchronize do
48+ mount "WhileLoadingTester" , { } , no_wait : true do
49+ class WhileLoadingTester < HyperComponent
50+ include Hyperstack ::Component ::WhileLoading
51+ render ( DIV ) do
52+ if resources_loaded?
53+ "#{ User . find_by_first_name ( 'Lily' ) . last_name } is a dog"
54+ else
55+ 'loading...'
56+ end
57+ end
58+ end
59+ end
60+ expect ( page ) . to have_content ( 'loading...' )
61+ expect ( page ) . not_to have_content ( 'is a dog' , wait : 0 )
62+ end
63+ expect ( page ) . to have_content ( 'DaDog is a dog' )
64+ expect ( page ) . not_to have_content ( 'loading...' , wait : 0 )
65+ end
66+
4667 it "will display the while loading message for a fetch within a nested component" do
4768 ReactiveRecord ::Operations ::Fetch . semaphore . synchronize do
4869 mount "WhileLoadingTester" , { } , no_wait : true do
@@ -71,6 +92,54 @@ class WhileLoadingTester < HyperComponent
7192 expect ( page ) . not_to have_content ( 'loading...' , wait : 0 )
7293 end
7394
95+ it "while loading works along side rescues" do
96+ # double check because WhileLoading is built on top of rescues
97+ ReactiveRecord ::Operations ::Fetch . semaphore . synchronize do
98+ mount "WhileLoadingTester" , { } , no_wait : true do
99+ class WhileLoadingTester < HyperComponent
100+ include Hyperstack ::Component ::WhileLoading
101+ class << self
102+ mutator :raise_error! do
103+ @raise_error = true
104+ end
105+ def check_error
106+ if @raise_error
107+ @raise_error = false
108+ raise 'Error Raised'
109+ end
110+ end
111+ end
112+ render ( DIV ) do
113+ WhileLoadingTester . check_error
114+ if @rescued
115+ @rescued = false
116+ "rescued"
117+ elsif resources_loaded?
118+ "#{ User . find_by_first_name ( 'Lily' ) . last_name } is a dog"
119+ else
120+ 'loading...'
121+ end
122+ end
123+ rescues do
124+ @rescued = true
125+ end
126+ end
127+ end
128+ expect ( page ) . to have_content ( 'loading...' )
129+ expect ( page ) . not_to have_content ( 'is a dog' , wait : 0 )
130+ end
131+ expect ( page ) . to have_content ( 'DaDog is a dog' )
132+ expect ( page ) . not_to have_content ( 'loading...' , wait : 0 )
133+ evaluate_ruby do
134+ WhileLoadingTester . raise_error!
135+ end
136+ expect ( page ) . to have_content ( 'rescued' )
137+ evaluate_ruby do
138+ Hyperstack ::Component . force_update!
139+ end
140+ expect ( page ) . to have_content ( 'DaDog is a dog' )
141+ end
142+
74143 it "will display the while loading message for a fetch within a nested component when attached to that component" do
75144 ReactiveRecord ::Operations ::Fetch . semaphore . synchronize do
76145 mount "WhileLoadingTester" , { } , no_wait : true do
@@ -82,11 +151,7 @@ class MyNestedGuy < HyperComponent
82151 class WhileLoadingTester < HyperComponent
83152 include Hyperstack ::Component ::WhileLoading
84153 render ( DIV ) do
85- if resources_loaded?
86- MyNestedGuy { }
87- else
88- SPAN { 'loading...' }
89- end
154+ resources_loading? ? 'loading...' : MyNestedGuy { }
90155 end
91156 end
92157 end
@@ -130,105 +195,6 @@ class WhileLoadingTester < HyperComponent
130195 expect ( page ) . not_to have_content ( 'i should not display' , wait : 0 )
131196 end
132197
133- # it "while loading can take a string param instead of a block" do
134- # ReactiveRecord::Operations::Fetch.semaphore.synchronize do
135- # mount "WhileLoadingTester", {}, no_wait: true do
136- # class WhileLoadingTester < HyperComponent
137- # render do
138- # DIV do
139- # User.find_by_first_name('Lily').last_name
140- # end
141- # .while_loading 'loading...'
142- # end
143- # end
144- # end
145- # expect(page).to have_content('loading...')
146- # expect(page).not_to have_content('DaDog', wait: 0)
147- # end
148- # expect(page).to have_content('DaDog')
149- # expect(page).not_to have_content('loading...', wait: 0)
150- # end
151- #
152- # it "while loading can take an element param instead of a block" do
153- # ReactiveRecord::Operations::Fetch.semaphore.synchronize do
154- # mount "WhileLoadingTester", {}, no_wait: true do
155- # class WhileLoadingTester < HyperComponent
156- # render do
157- # DIV do
158- # User.find_by_first_name('Lily').last_name
159- # end
160- # .while_loading(DIV { 'loading...' })
161- # end
162- # end
163- # end
164- # expect(page).to have_content('loading...')
165- # expect(page).not_to have_content('DaDog', wait: 0)
166- # end
167- # expect(page).to have_content('DaDog')
168- # expect(page).not_to have_content('loading...', wait: 0)
169- # end
170- #
171- # it "achieving while_loading behavior with state variables" do
172- # ReactiveRecord::Operations::Fetch.semaphore.synchronize do
173- # mount "WhileLoadingTester", {}, no_wait: true do
174- # class MyComponent < HyperComponent
175- # render do
176- # SPAN { 'loading...' }
177- # end
178- # end
179- #
180- # class WhileLoadingTester < HyperComponent
181- #
182- # before_mount do
183- # ReactiveRecord.load do
184- # User.find_by_first_name('Lily').last_name
185- # end.then do |last_name|
186- # mutate @last_name = last_name
187- # end
188- # end
189- #
190- # render do
191- # if @last_name
192- # DIV { @last_name }
193- # else
194- # MyComponent {}
195- # end
196- # end
197- # end
198- # end
199- # expect(page).to have_content('loading...')
200- # expect(page).not_to have_content('DaDog', wait: 0)
201- # end
202- # expect(page).to have_content('DaDog')
203- # expect(page).not_to have_content('loading...', wait: 0)
204- # end
205- #
206- # it "while loading display an application defined element" do
207- # ReactiveRecord::Operations::Fetch.semaphore.synchronize do
208- # mount "WhileLoadingTester", {}, no_wait: true do
209- # class MyComponent < HyperComponent
210- # render do
211- # SPAN { 'loading...' }
212- # end
213- # end
214- # class WhileLoadingTester < HyperComponent
215- # render do
216- # DIV do
217- # User.find_by_first_name('Lily').last_name
218- # end
219- # .while_loading do
220- # MyComponent {}
221- # end
222- # end
223- # end
224- # end
225- # expect(page).to have_content('loading...')
226- # expect(page).not_to have_content('DaDog', wait: 0)
227- # end
228- # expect(page).to have_content('DaDog')
229- # expect(page).not_to have_content('loading...', wait: 0)
230- # end
231-
232198 it "while loading works when number of children changes (i.e. relationships)" do
233199 ReactiveRecord ::Operations ::Fetch . semaphore . synchronize do
234200 mount "WhileLoadingTester" , { } , no_wait : true do
0 commit comments