Skip to content

Commit 7f5b095

Browse files
cbrandtbuffalosunnavy
authored andcommitted
Add tests to confirm Investigation lazy load on create
1 parent e191a05 commit 7f5b095

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

t/playwright/incident_create.t

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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/, "Incident widget triggers on load (hx-trigger='$inc_trigger')" );
33+
like( $inv_trigger, qr/\brevealed\b/, "Investigation widget triggers on reveal (hx-trigger='$inv_trigger')" );
34+
35+
# Behavior check: an unloaded htmx widget still has a content placeholder
36+
# inside; once htmx fires and swaps in real content the placeholder is
37+
# gone. Investigation widget should still have the placeholder until the
38+
# user scrolls.
39+
my $placeholder = $investigation_widget->locator('.htmx-widget-content-placeholder');
40+
ok( $placeholder->count > 0, 'Investigation widget content has not loaded yet (placeholder still present)' );
41+
42+
$investigation_widget->scrollIntoViewIfNeeded;
43+
$p->wait_for_htmx;
44+
45+
is( $investigation_widget->locator('.htmx-widget-content-placeholder')->count,
46+
0, 'Investigation widget content loaded after scrolling into view' );
47+
48+
$p->logout;
49+
done_testing;

0 commit comments

Comments
 (0)