Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loading indicator to the test liveview #6023

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion assets/javascripts/running.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,16 @@ var last_event;
function loadCanvas(canvas, dataURL) {
var context = canvas.getContext('2d');

// load image from data url
// load image from data URL
var scrn = new Image();
scrn.onload = function () {
canvas.width = this.width;
canvas.height = this.height;
context.clearRect(0, 0, this.width, this.width);
context.drawImage(this, 0, 0);

// hide loading animation after the first image is loaded
document.getElementById('liveview-loading').style.display = 'none';
};
scrn.src = dataURL;
}
Expand Down
34 changes: 34 additions & 0 deletions t/ui/18-tests-details.t
r-richardson marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,40 @@ subtest 'running job' => sub {
# waiting for the periodic call anyways
$driver->execute_script('window.enableStatusUpdates = false');

subtest 'liveview loading animation is displayed' => sub {
$driver->find_element_by_link_text('Details')->click();
like current_tab, qr/details/i, 'switched to details tab';
$driver->find_element_by_link_text('Live View')->click();
like current_tab, qr/live/i, 'switched back to live tab';
my $loading_element = $driver->find_element('#liveview-loading');
ok $loading_element, 'liveview-loading element exists after tab switch';
ok $loading_element->is_displayed(), 'liveview-loading is visible after tab switch';
};
subtest 'liveview loading animation hides after live view starts' => sub {
my $loading_element = $driver->find_element('#liveview-loading');
ok $loading_element->is_displayed(), 'liveview-loading is initially visible';
# simulate the live view starting
r-richardson marked this conversation as resolved.
Show resolved Hide resolved
$driver->execute_script(
q{
var canvas = document.getElementById('livestream');
var dataURL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=';
loadCanvas(canvas, dataURL);
}
);
wait_until sub {
!$loading_element->is_displayed();
}, 'liveview-loading is hidden after live view starts', 5;
my $canvas = $driver->find_element('#livestream');
ok $canvas->is_displayed(), 'livestream canvas is displayed';
$driver->find_element_by_link_text('Details')->click();
like current_tab, qr/details/i, 'switched to details tab';
$driver->find_element_by_link_text('Live View')->click();
like current_tab, qr/live/i, 'switched back to live tab';
$loading_element = $driver->find_element('#liveview-loading');
ok $loading_element, 'liveview-loading element exists after tab switch';
ok !$loading_element->is_displayed(), 'liveview-loading is still hidden after tab switch';
};

subtest 'info panel contents' => sub {
like(
$driver->find_element('#assigned-worker')->get_text,
Expand Down
7 changes: 7 additions & 0 deletions templates/webapi/test/live.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@
</div>

<div id="canholder">
<div id="liveview-loading">
<div class="d-flex justify-content-center">
<i class="fa fa-circle-o-notch fa-spin fa-4x" role="status">
<span class="sr-only">Loading…</span>
</i>
</div>
</div>
<canvas id="livestream" data-url="/liveviewhandler/tests/<%= $testid %>/streaming">
</canvas>
</div>
Expand Down
Loading