-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow scheduling a (example) product via the web UI
Related ticket: https://progress.opensuse.org/issues/166658
- Loading branch information
Showing
11 changed files
with
307 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function getNonEmptyFormParams(form) { | ||
const formData = new FormData(form); | ||
const queryParams = new URLSearchParams(); | ||
for (const [key, value] of formData) { | ||
if (value.length > 0) { | ||
queryParams.append(key, value); | ||
} | ||
} | ||
return queryParams; | ||
} | ||
|
||
function setupAceEditor(elementID, mode) { | ||
const element = document.getElementById(elementID); | ||
const initialValue = element.textContent; | ||
const editor = ace.edit(element, { | ||
mode: mode, | ||
maxLines: Infinity, | ||
tabSize: 2, | ||
useSoftTabs: true | ||
}); | ||
editor.session.setUseWrapMode(true); | ||
editor.initialValue = initialValue; | ||
return editor; | ||
} | ||
|
||
function setupCreateTestsForm() { | ||
window.scenarioDefinitionsEditor = setupAceEditor('create-tests-scenario-definitions', 'ace/mode/yaml'); | ||
window.settingsEditor = setupAceEditor('create-tests-settings', 'ace/mode/ini'); | ||
} | ||
|
||
function resetCreateTestsForm() { | ||
window.scenarioDefinitionsEditor.setValue(window.scenarioDefinitionsEditor.initialValue, -1); | ||
window.settingsEditor.setValue(window.settingsEditor.initialValue, -1); | ||
} | ||
|
||
function createTests(form) { | ||
event.preventDefault(); | ||
|
||
const scenarioDefinitions = window.scenarioDefinitionsEditor.getValue(); | ||
const queryParams = getNonEmptyFormParams(form); | ||
window.settingsEditor | ||
.getValue() | ||
.split('\n') | ||
.map(line => line.split('=', 2)) | ||
.forEach(setting => queryParams.append(setting[0].trim(), (setting[1] ?? '').trim())); | ||
queryParams.append('async', true); | ||
if (scenarioDefinitions.length > 0) { | ||
queryParams.append('SCENARIO_DEFINITIONS_YAML', scenarioDefinitions); | ||
} | ||
$.ajax({ | ||
url: form.dataset.postUrl, | ||
method: form.method, | ||
data: queryParams.toString(), | ||
success: function (response) { | ||
const id = response.scheduled_product_id; | ||
const url = `${form.dataset.productlogUrl}?id=${id}`; | ||
addFlash('info', `Tests have been scheduled, checkout the <a href="${url}">product log</a> for details.`); | ||
}, | ||
error: function (xhr, ajaxOptions, thrownError) { | ||
addFlash('danger', 'Unable to create tests: ' + (xhr.responseJSON?.error ?? xhr.responseText ?? thrownError)); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
t/data/openqa/share/tests/example/scenario-definitions.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
products: | ||
example: | ||
distri: "example" | ||
flavor: "DVD" | ||
arch: "x86_64" | ||
version: '0' | ||
job_templates: | ||
simple_boot: | ||
product: "example" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env perl | ||
# Copyright 2024 SUSE LLC | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
use Test::Most; | ||
|
||
use FindBin; | ||
use Test::Mojo; | ||
use Test::Warnings ':report_warnings'; | ||
use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../external/os-autoinst-common/lib"; | ||
use OpenQA::Test::TimeLimit '15'; | ||
use OpenQA::Test::Case; | ||
use OpenQA::SeleniumTest; | ||
|
||
my $schema = OpenQA::Test::Case->new->init_data; | ||
my $scheduled_products = $schema->resultset('ScheduledProducts'); | ||
|
||
driver_missing unless my $driver = call_driver; | ||
my $url = 'http://localhost:' . OpenQA::SeleniumTest::get_mojoport; | ||
|
||
subtest 'navigation to form' => sub { | ||
$driver->get("$url/login"); | ||
$driver->find_element_by_id('create-tests-action')->click; | ||
$driver->find_element_by_link_text('Example test')->click; | ||
$driver->title_is('openQA: Create example test', 'on page to create example test'); | ||
}; | ||
|
||
subtest 'form is pre-filled' => sub { | ||
my $flash_messages = $driver->find_element_by_id('flash-messages'); | ||
like $flash_messages->get_text, qr/create.*example test.*pre-filled/i, 'note about example present'; | ||
$driver->find_element('#flash-messages button')->click; # dismiss | ||
my %expected_values = ( | ||
'create-tests-distri' => 'example', | ||
'create-tests-version' => '0', | ||
'create-tests-flavor' => 'DVD', | ||
'create-tests-arch' => 'x86_64', | ||
'create-tests-build' => 'openqa', | ||
'create-tests-test' => 'simple_boot', | ||
'create-tests-casedir' => 'https://github.com/os-autoinst/os-autoinst-distri-example.git', | ||
'create-tests-needlesdir' => '', | ||
); | ||
is element_prop($_), $expected_values{$_}, "$_ is pre-filled" for keys %expected_values; | ||
}; | ||
|
||
subtest 'form can be submitted' => sub { | ||
$driver->find_element('#create-tests-settings-container textarea')->send_keys("_PRIORITY=42\nISO=foo.iso"); | ||
$driver->find_element('#create-tests-form button[type="submit"]')->click; | ||
wait_for_ajax msg => 'test creation'; | ||
my $flash_messages = $driver->find_element_by_id('flash-messages'); | ||
like $flash_messages->get_text, qr/scheduled.*product log/i, 'note about success'; | ||
}; | ||
|
||
subtest 'settings shown in product log' => sub { | ||
$driver->find_element_by_link_text('product log')->click; | ||
$driver->title_is('openQA: Scheduled products log', 'on product log details page'); | ||
|
||
my $settings = $driver->find_element('.settings-table')->get_text; | ||
like $settings, qr/ARCH x86_64/, 'ARCH present'; | ||
like $settings, qr/BUILD openqa/, 'BUILD present'; | ||
like $settings, qr/CASEDIR http.*\.git/, 'CASEDIR present'; | ||
like $settings, qr/DISTRI example/, 'DISTRI present'; | ||
like $settings, qr/FLAVOR DVD/, 'FLAVOR present'; | ||
like $settings, qr/SCENARIO_DEFINITIONS_YAML ---.*products:.*job_templates:/s, 'SCENARIO_DEFINITIONS_YAML present'; | ||
like $settings, qr/TEST simple_boot/, 'TEST present'; | ||
like $settings, qr/VERSION 0/, 'VERSION present'; | ||
like $settings, qr/_PRIORITY 42/, '_PRIORITY present'; | ||
like $settings, qr/ISO foo.iso/, 'ISO present'; | ||
}; | ||
|
||
subtest 'preset not found' => sub { | ||
$driver->get("$url/tests/create?preset=foo"); | ||
my $flash_messages = $driver->find_element_by_id('flash-messages'); | ||
like $flash_messages->get_text, qr/'foo' does not exist/i, 'error if preset does not exist'; | ||
}; | ||
|
||
kill_driver; | ||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.