|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use RT::IR::Test tests => undef, playwright => 1; |
| 5 | + |
| 6 | +my ( $url, $p ) = RT::Test->started_ok; |
| 7 | +$p->login(); |
| 8 | + |
| 9 | +# Set a realistic viewport so the Investigation section starts below |
| 10 | +# the fold. |
| 11 | +$p->{page}->setViewportSize( { width => 1280, height => 720 } ); |
| 12 | + |
| 13 | +$p->get_ok('/RTIR/Incident/Create.html?Lifecycle=incidents'); |
| 14 | +$p->wait_for_htmx; |
| 15 | + |
| 16 | +my $incident_section = $p->{page}->locator('#ticket-create-incident'); |
| 17 | +my $investigation_section = $p->{page}->locator('#ticket-create-investigation'); |
| 18 | + |
| 19 | +ok( $incident_section->isVisible, 'Incident section is visible above the fold' ); |
| 20 | +ok( $investigation_section->count > 0, 'Investigation section is rendered in the DOM' ); |
| 21 | + |
| 22 | +# Each widget is wrapped by HTMXLoadStart in a div with the |
| 23 | +# class="htmx-load-widget" and an hx-trigger attribute. The trigger |
| 24 | +# should be "...load" for eager (Incident half, above the fold) and |
| 25 | +# "...revealed" for lazy (Investigation half, below the fold). |
| 26 | +my $incident_widget = $incident_section->locator('.htmx-load-widget')->first; |
| 27 | +my $investigation_widget = $investigation_section->locator('.htmx-load-widget')->first; |
| 28 | + |
| 29 | +my $inc_trigger = $incident_widget->getAttribute('hx-trigger') // ''; |
| 30 | +my $inv_trigger = $investigation_widget->getAttribute('hx-trigger') // ''; |
| 31 | + |
| 32 | +like( $inc_trigger, qr/\bload\b/, |
| 33 | + "Incident widget triggers on load (hx-trigger='$inc_trigger')" ); |
| 34 | +like( $inv_trigger, qr/\brevealed\b/, |
| 35 | + "Investigation widget triggers on reveal (hx-trigger='$inv_trigger')" ); |
| 36 | + |
| 37 | +# Behavior check: an unloaded htmx widget still has a content placeholder |
| 38 | +# inside; once htmx fires and swaps in real content the placeholder is |
| 39 | +# gone. Investigation widget should still have the placeholder until the |
| 40 | +# user scrolls. |
| 41 | +my $placeholder = $investigation_widget->locator('.htmx-widget-content-placeholder'); |
| 42 | +ok( $placeholder->count > 0, |
| 43 | + 'Investigation widget content has not loaded yet (placeholder still present)' ); |
| 44 | + |
| 45 | +$investigation_widget->scrollIntoViewIfNeeded; |
| 46 | +$p->wait_for_htmx; |
| 47 | + |
| 48 | +is( $investigation_widget->locator('.htmx-widget-content-placeholder')->count, 0, |
| 49 | + 'Investigation widget content loaded after scrolling into view' ); |
| 50 | + |
| 51 | +$p->logout; |
| 52 | +done_testing; |
0 commit comments