|
257 | 257 | let(:headers) do
|
258 | 258 | {
|
259 | 259 | 'X-Inertia' => true,
|
260 |
| - 'X-Inertia-Partial-Data' => 'nested,nested_lazy', |
| 260 | + 'X-Inertia-Partial-Data' => 'nested,nested_optional', |
261 | 261 | 'X-Inertia-Partial-Except' => 'nested',
|
262 | 262 | 'X-Inertia-Partial-Component' => 'TestComponent',
|
263 | 263 | }
|
|
268 | 268 | it 'returns listed props without excepted' do
|
269 | 269 | expect(response.parsed_body['props']).to eq(
|
270 | 270 | 'always' => 'always prop',
|
271 |
| - 'nested_lazy' => { 'first' => 'first nested lazy param' }, |
| 271 | + 'nested_optional' => { 'first' => 'first nested optional param' }, |
272 | 272 | )
|
273 | 273 | end
|
274 | 274 |
|
|
282 | 282 | it 'returns all regular and partial props except excepted' do
|
283 | 283 | expect(response.parsed_body['props']).to eq(
|
284 | 284 | 'flat' => 'flat param',
|
285 |
| - 'lazy' => 'lazy param', |
| 285 | + 'optional' => 'optional param', |
286 | 286 | 'always' => 'always prop',
|
287 |
| - 'nested_lazy' => { 'first' => 'first nested lazy param' }, |
| 287 | + 'nested_optional' => { 'first' => 'first nested optional param' }, |
288 | 288 | )
|
289 | 289 | end
|
290 | 290 | end
|
291 | 291 |
|
292 | 292 | context 'when except always prop' do
|
293 | 293 | let(:headers) {{
|
294 | 294 | 'X-Inertia' => true,
|
295 |
| - 'X-Inertia-Partial-Data' => 'nested_lazy', |
| 295 | + 'X-Inertia-Partial-Data' => 'nested_optional', |
296 | 296 | 'X-Inertia-Partial-Except' => 'always_prop',
|
297 | 297 | 'X-Inertia-Partial-Component' => 'TestComponent',
|
298 | 298 | }}
|
299 | 299 |
|
300 | 300 | it 'returns always prop anyway' do
|
301 | 301 | expect(response.parsed_body['props']).to eq(
|
302 | 302 | 'always' => 'always prop',
|
303 |
| - 'nested_lazy' => { 'first' => 'first nested lazy param' }, |
| 303 | + 'nested_optional' => { 'first' => 'first nested optional param' }, |
304 | 304 | )
|
305 | 305 | end
|
306 | 306 | end
|
|
309 | 309 | let(:headers) do
|
310 | 310 | {
|
311 | 311 | 'X-Inertia' => true,
|
312 |
| - 'X-Inertia-Partial-Data' => 'nested_lazy', |
| 312 | + 'X-Inertia-Partial-Data' => 'nested_optional', |
313 | 313 | 'X-Inertia-Partial-Except' => 'unknown',
|
314 | 314 | 'X-Inertia-Partial-Component' => 'TestComponent',
|
315 | 315 | }
|
|
318 | 318 | it 'returns props' do
|
319 | 319 | expect(response.parsed_body['props']).to eq(
|
320 | 320 | 'always' => 'always prop',
|
321 |
| - 'nested_lazy' => { 'first' => 'first nested lazy param' }, |
| 321 | + 'nested_optional' => { 'first' => 'first nested optional param' }, |
322 | 322 | )
|
323 | 323 | end
|
324 | 324 | end
|
|
327 | 327 | let(:headers) do
|
328 | 328 | {
|
329 | 329 | 'X-Inertia' => true,
|
330 |
| - 'X-Inertia-Partial-Data' => 'nested,nested_lazy', |
331 |
| - 'X-Inertia-Partial-Except' => 'nested.first,nested_lazy.first', |
| 330 | + 'X-Inertia-Partial-Data' => 'nested,nested_optional', |
| 331 | + 'X-Inertia-Partial-Except' => 'nested.first,nested_optional.first', |
332 | 332 | 'X-Inertia-Partial-Component' => 'TestComponent',
|
333 | 333 | }
|
334 | 334 | end
|
|
337 | 337 | expect(response.parsed_body['props']).to eq(
|
338 | 338 | 'always' => 'always prop',
|
339 | 339 | 'nested' => { 'second' => 'second nested param' },
|
340 |
| - 'nested_lazy' => { 'first' => 'first nested lazy param' }, |
| 340 | + 'nested_optional' => { 'first' => 'first nested optional param' }, |
341 | 341 | )
|
342 | 342 | end
|
343 | 343 | end
|
|
372 | 372 | end
|
373 | 373 | end
|
374 | 374 |
|
| 375 | + context 'optional prop rendering' do |
| 376 | + context 'on first load' do |
| 377 | + let(:page) { |
| 378 | + InertiaRails::Renderer.new('TestComponent', controller, request, response, '', props: { regular: 1}).send(:page) |
| 379 | + } |
| 380 | + before { get optional_props_path } |
| 381 | + |
| 382 | + it { is_expected.to include inertia_div(page) } |
| 383 | + end |
| 384 | + |
| 385 | + context 'with a partial reload' do |
| 386 | + let(:page) { |
| 387 | + InertiaRails::Renderer.new('TestComponent', controller, request, response, '', props: { regular: 1, optional: 1}).send(:page) |
| 388 | + } |
| 389 | + let(:headers) {{ |
| 390 | + 'X-Inertia' => true, |
| 391 | + 'X-Inertia-Partial-Data' => 'optional', |
| 392 | + 'X-Inertia-Partial-Component' => 'TestComponent', |
| 393 | + }} |
| 394 | + |
| 395 | + before { get optional_props_path, headers: headers } |
| 396 | + |
| 397 | + it { is_expected.to eq page.to_json } |
| 398 | + end |
| 399 | + end |
| 400 | + |
375 | 401 | context 'always prop rendering' do
|
376 | 402 | let(:headers) { { 'X-Inertia' => true } }
|
377 | 403 |
|
|
384 | 410 | context 'with a partial reload' do
|
385 | 411 | let(:headers) {{
|
386 | 412 | 'X-Inertia' => true,
|
387 |
| - 'X-Inertia-Partial-Data' => 'lazy', |
| 413 | + 'X-Inertia-Partial-Data' => 'optional', |
388 | 414 | 'X-Inertia-Partial-Component' => 'TestComponent',
|
389 | 415 | }}
|
390 | 416 |
|
391 | 417 | it "returns listed and always props" do
|
392 |
| - expect(response.parsed_body["props"]).to eq({"always" => 'always prop', "lazy" => 'lazy prop' }) |
| 418 | + expect(response.parsed_body["props"]).to eq({"always" => 'always prop', "optional" => 'optional prop' }) |
393 | 419 | end
|
394 | 420 | end
|
395 | 421 | end
|
|
0 commit comments