Show vehicle/ordnance capabilities in the UI.

master
Pacman Ghost 6 years ago
parent c316489ab0
commit e1f2ccd3a2
  1. 1
      vasl_templates/webapp/static/css/sortable.css
  2. 16
      vasl_templates/webapp/static/css/tabs-ob.css
  3. 3
      vasl_templates/webapp/static/css/tabs-scenario.css
  4. 42
      vasl_templates/webapp/static/snippets.js
  5. 15
      vasl_templates/webapp/static/utils.js
  6. 54
      vasl_templates/webapp/static/vo.js
  7. 10
      vasl_templates/webapp/static/vo2.js
  8. 6
      vasl_templates/webapp/templates/tabs-ob1.html
  9. 4
      vasl_templates/webapp/templates/vo-report.html
  10. 135
      vasl_templates/webapp/tests/test_capabilities.py
  11. 11
      vasl_templates/webapp/tests/test_scenario_persistence.py
  12. 14
      vasl_templates/webapp/tests/test_vehicles_ordnance.py
  13. 6
      vasl_templates/webapp/tests/utils.py

@ -1,7 +1,6 @@
button.sortable-add { vertical-align: top ; height: 30px ; padding: 4px 10px ; }
img.sortable-add { vertical-align: middle ; height: 15px ; margin-right: 0.25em ; }
.sortable { font-size: 80% ; }
.sortable { list-style-type: none ; margin: 0 ; padding: 0 ; }
.sortable li { margin-bottom: 2px ; padding: 5px ; }

@ -2,6 +2,7 @@
.panel-ob_setups { height: 100% ; display: flex ; flex-direction: column ; }
.panel-ob_setups .content { flex-grow: 1 ; }
.panel-ob_setups .sortable { font-size: 90% ; }
.panel-ob_setups .footer { margin-top: 0.5em ; display: flex ; align-items: center ; }
/* -------------------------------------------------------------------- */
@ -14,17 +15,20 @@
.panel-ob_vehicles { height: 100% ; display: flex ; flex-direction: column ; }
.panel-ob_vehicles .content { flex-grow: 1 ; }
.panel-ob_vehicles .sortable { font-size: 90% ; }
.panel-ob_vehicles .footer { margin-top: 0.5em ; display: flex ; align-items: center ; }
.panel-ob_vehicles .sortable { font-size: 90% ; }
.panel-ob_vehicles .sortable img { display: inline-block ; vertical-align: middle ; height: 3.5em ; margin-right: 0.5em ; }
/* nb: the following CSS is shared by vehicles and ordnance */
.panel-ob_vo .sortable .vo-entry { display: flex ; font-size: 90% ; }
.panel-ob_vo .sortable .vo-entry img.vasl-image { display: inline-block ; vertical-align: middle ; height: 3.5em ; margin-right: 0.5em ; }
.panel-ob_vo .sortable .vo-entry.small-piece img.vasl-image { height: 2.5em ; margin-left: 0.5em ; margin-right: 1em ; }
.panel-ob_vo .sortable .vo-entry .detail { flex-grow: 1 ; display: flex ; flex-direction: column ; justify-content: center ; }
.panel-ob_vo .sortable .vo-entry .detail .vo-name { font-size: 110% ; }
.panel-ob_vo .sortable .vo-entry .detail .vo-capabilities { max-height: 2.5em ; overflow: hidden ; font-size: 90% ; font-style: italic ; }
.panel-ob_vo .sortable .vo-entry .detail .vo-capability { margin-right: 0.5em ; color: #444 ; }
/* -------------------------------------------------------------------- */
.panel-ob_ordnance { height: 100% ; display: flex ; flex-direction: column ; }
.panel-ob_ordnance .content { flex-grow: 1 ; }
.panel-ob_ordnance .footer { margin-top: 0.5em ; display: flex ; align-items: center ; }
.panel-ob_ordnance .sortable { font-size: 90% ; }
.panel-ob_ordnance .sortable img { display: inline-block ; vertical-align: middle ; height: 3.5em ; margin-right: 0.5em ; }
.panel-ob_ordnance .sortable .small-piece img { height: 2.5em ; margin-left: 0.5em ; margin-right: 1em ; }

@ -24,11 +24,12 @@
#panel-scenario_notes { height: 100% ; display: flex ; flex-direction: column ; }
#panel-scenario_notes .content { flex-grow: 1 ; }
#panel-scenario_notes .sortable { font-size: 90% ; }
#panel-scenario_notes .footer { margin-top: 0.5em ; display: flex ; }
/* -------------------------------------------------------------------- */
#panel-ssr { height: 100% ; display: flex ; flex-direction: column ; }
#panel-ssr .content { flex-grow: 1 ; }
#panel-ssr .sortable { font-size: 90% ; }
#panel-ssr .footer { margin-top: 0.5em ; display: flex ; align-items: center ; }

@ -24,7 +24,7 @@ function generate_snippet( $btn, extra_params )
{
// unload the template parameters
var template_id = $btn.data( "id" ) ;
var params = unload_snippet_params( true ) ;
var params = unload_snippet_params( true, true ) ;
// set player-specific parameters
var curr_tab = $("#tabs .ui-tabs-active a").attr( "href" ) ;
@ -176,12 +176,12 @@ function generate_snippet( $btn, extra_params )
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function unload_snippet_params( check_date_capabilities )
function unload_snippet_params( unpack_scenario_date, show_warnings )
{
var params = {} ;
// extract the scenario date components
if ( check_date_capabilities ) {
if ( unpack_scenario_date ) {
var scenario_date = $( "input[name='SCENARIO_DATE']" ).datepicker( "getDate" ) ;
if ( scenario_date ) {
params.SCENARIO_DAY_OF_MONTH = scenario_date.getDate() ;
@ -241,22 +241,22 @@ function unload_snippet_params( check_date_capabilities )
obj.capabilities = capabilities ;
obj.custom_capabilities = capabilities.slice() ;
} else {
// NOTE: We don't show warnings here; if there's something wrong,
// we will show the warnings when we make the raw capabilities.
capabilities = make_capabilities(
vo_entry,
nat,
params.SCENARIO_THEATER,
params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities,
false,
vo_entry, nat,
params.SCENARIO_THEATER, params.SCENARIO_YEAR, params.SCENARIO_MONTH,
false
) ;
if ( capabilities )
obj.capabilities = capabilities ;
}
capabilities = make_capabilities(
vo_entry,
nat,
params.SCENARIO_THEATER,
params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities,
true
true,
vo_entry, nat,
params.SCENARIO_THEATER, params.SCENARIO_YEAR, params.SCENARIO_MONTH,
show_warnings
) ;
if ( capabilities )
obj.raw_capabilities = capabilities ;
@ -275,7 +275,7 @@ function unload_snippet_params( check_date_capabilities )
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function make_capabilities( vo_entry, nat, scenario_theater, scenario_year, scenario_month, check_date_capabilities, raw )
function make_capabilities( raw, vo_entry, nat, scenario_theater, scenario_year, scenario_month, show_warnings )
{
var capabilities = [] ;
@ -347,7 +347,7 @@ function make_capabilities( vo_entry, nat, scenario_theater, scenario_year, scen
}
}
// check if there were any capabilities not set
if ( check_date_capabilities && indeterminate_caps.length > 0 ) {
if ( show_warnings && indeterminate_caps.length > 0 ) {
showWarningMsg( makeBulletListMsg(
"Can't determine capabilities without a scenario year:",
indeterminate_caps
@ -893,7 +893,7 @@ function unload_params_for_save()
}
// unload the template parameters
var params = unload_snippet_params( false ) ;
var params = unload_snippet_params( false, false ) ;
params.SCENARIO_NOTES = $("#scenario_notes-sortable").sortable2( "get-entry-data" ) ;
params.OB_SETUPS_1 = $("#ob_setups-sortable_1").sortable2( "get-entry-data" ) ;
params.OB_SETUPS_2 = $("#ob_setups-sortable_2").sortable2( "get-entry-data" ) ;
@ -1173,7 +1173,6 @@ function is_atmm_available() { return _is_scenario_after( 0, 1944 ) ; }
function on_scenario_date_change()
{
// update the UI
// NOTE: We update the visual appearance of the buttons to indicate whether
// the support weapons are available, but leave the buttons active since
// the date restrictions are not strict, and the SW are sometimes available
@ -1189,6 +1188,17 @@ function on_scenario_date_change()
update_ui( "psk", is_psk_available() ) ;
update_ui( "baz", is_baz_available() ) ;
update_ui( "atmm", is_atmm_available() ) ;
var snippet_params = unload_snippet_params( true, false ) ;
function update_vo( $sortable2 ) {
$sortable2.children( "li" ).each( function() {
update_vo_sortable2_entry( $(this), snippet_params ) ;
} ) ;
}
for ( var player_no=1 ; player_no <= 2 ; ++player_no ) {
update_vo( $( "#ob_vehicles-sortable_" + player_no ) ) ;
update_vo( $( "#ob_ordnance-sortable_" + player_no ) ) ;
}
}
// --------------------------------------------------------------------

@ -15,12 +15,21 @@ function get_player_colors( player_no )
}
function get_player_colors_for_element( $elem )
{
// get the player colors (if any) for the specified element
var player_no = get_player_no_for_element( $elem ) ;
if ( player_no === null )
return null ;
return get_player_colors( player_no ) ;
}
function get_player_no_for_element( $elem )
{
// get the player colors (if any) for the specified element
if ( $.contains( $("#tabs-ob1")[0], $elem[0] ) )
return get_player_colors( 1 ) ;
else if ( $.contains( $("#tabs-ob2")[0], $elem[0] ) )
return get_player_colors( 2 ) ;
return 1 ;
if ( $.contains( $("#tabs-ob2")[0], $elem[0] ) )
return 2 ;
return null ;
}

@ -127,14 +127,13 @@ function do_add_vo( vo_type, player_no, vo_entry, vo_image_id, custom_capabiliti
// NOTE: We set a fixed height for the sortable2 entries (based on the CSS settings in tabs-ob.css),
// so that the vehicle/ordnance images won't get truncated if there are a lot of them.
var $sortable2 = $( "#ob_" + vo_type + "-sortable_" + player_no ) ;
var div_tag = "<div" ;
var fixed_height = "3.75em" ;
var div_tag = "<div class='vo-entry" ;
var fixed_height = "3.25em" ;
if ( is_small_vasl_piece( vo_entry ) ) {
div_tag += " class='small-piece'" ;
fixed_height = "2.5em" ;
div_tag += " small-piece" ;
fixed_height = "2.25em" ;
}
div_tag += ">" ;
var url = get_vo_image_url( vo_entry, vo_image_id, true ) ;
div_tag += "'>" ;
var data = {
caption: vo_entry.name,
vo_entry: vo_entry,
@ -143,10 +142,49 @@ function do_add_vo( vo_type, player_no, vo_entry, vo_image_id, custom_capabiliti
} ;
if ( custom_capabilities )
data.custom_capabilities = custom_capabilities ;
$sortable2.sortable2( "add", {
content: $( div_tag + "<img src='"+url+"' class='vasl-image'>" + vo_entry.name + "</div>" ),
var buf = [ div_tag,
"<img class='vasl-image'>",
"<div class='detail'>",
"<div class='vo-name'></div>",
"<div class='vo-capabilities'></div>",
"</div>",
"</div>" ] ;
var $entry = $sortable2.sortable2( "add", {
content: $( buf.join("") ),
data: data,
} ) ;
update_vo_sortable2_entry( $entry ) ;
}
function update_vo_sortable2_entry( $entry, snippet_params )
{
// initialize
if ( ! snippet_params )
snippet_params = unload_snippet_params( true, false ) ;
var vo_entry = $entry.data( "sortable2-data" ).vo_entry ;
var vo_image_id = $entry.data( "sortable2-data" ).vo_image_id ;
var capabilities = $entry.data( "sortable2-data" ).custom_capabilities ;
if ( capabilities )
capabilities = capabilities.slice() ;
else {
var player_no = get_player_no_for_element( $entry ) ;
capabilities = make_capabilities(
false,
vo_entry,
snippet_params[ "PLAYER_"+player_no ],
snippet_params.SCENARIO_THEATER, snippet_params.SCENARIO_YEAR, snippet_params.SCENARIO_MONTH,
false
) ;
}
// update the vehicle/ordnance's sortable2 entry
var url = get_vo_image_url( vo_entry, vo_image_id, true ) ;
var $content = $entry.children( ".vo-entry" ) ;
$content.find( "img.vasl-image" ).attr( "src", url ) ;
$content.find( "div.vo-name" ).html( vo_entry.name ) ;
for ( var i=0 ; i < capabilities.length ; ++i )
capabilities[i] = "<span class='vo-capability'>" + capabilities[i] + "</span>" ;
$content.find( "div.vo-capabilities" ).html( capabilities.join("") ) ;
}
// --------------------------------------------------------------------

@ -7,14 +7,14 @@ function edit_ob_ordnance( $entry, player_no ) { _do_edit_ob_vo( $entry, player_
function _do_edit_ob_vo( $entry, player_no, vo_type )
{
// get the vehicle/ordnance's capabilities
var params = unload_snippet_params( true ) ;
var params = unload_snippet_params( true, false ) ;
var vo_entry = $entry.data( "sortable2-data" ).vo_entry ;
var default_capabilities = make_capabilities(
false,
vo_entry,
params[ "PLAYER_"+player_no ],
params.SCENARIO_THEATER,
params.SCENARIO_YEAR, params.SCENARIO_MONTH, false,
false
params.SCENARIO_THEATER, params.SCENARIO_YEAR, params.SCENARIO_MONTH,
true
) ;
var capabilities = $entry.data( "sortable2-data" ).custom_capabilities ;
if ( ! capabilities )
@ -124,7 +124,7 @@ function _do_edit_ob_vo( $entry, player_no, vo_type )
delete $entry.data( "sortable2-data" ).custom_capabilities ;
}
// update the original V/O entry to reflect the changes
$entry.find( "img.vasl-image" ).attr( "src", $img.attr("src") ) ;
update_vo_sortable2_entry( $entry ) ;
$(this).dialog( "close" ) ;
},
Cancel: function() { $(this).dialog( "close" ) ; },

@ -46,7 +46,7 @@
<div class="right">
<fieldset name="ob_vehicles_1" class="tr"> <legend>Vehicles</legend>
<div id="panel-ob_vehicles_1" class="panel-ob_vehicles">
<div id="panel-ob_vehicles_1" class="panel-ob_vehicles panel-ob_vo">
<div class="content">
<div id="ob_vehicles-hint_1" class="sortable-hint"></div>
<ul id="ob_vehicles-sortable_1" class="sortable" style="display:none;"></ul>
@ -64,8 +64,8 @@
</div>
</fieldset>
<fieldset name="ob_vehicles_1" class="br"> <legend>Ordnance</legend>
<div id="panel-ob_ordnance_1" class="panel-ob_ordnance">
<fieldset name="ob_ordnance_1" class="br"> <legend>Ordnance</legend>
<div id="panel-ob_ordnance_1" class="panel-ob_ordnance panel-ob_vo">
<div class="content">
<div id="ob_ordnance-hint_1" class="sortable-hint"></div>
<ul id="ob_ordnance-sortable_1" class="sortable" style="display:none;"></ul>

@ -68,9 +68,9 @@ function load_vo_listings( objs )
continue ;
buf.push( "<tr>" ) ;
buf.push( "<td>", fmtval(obj.name) ) ;
var capabilities = make_capabilities( obj, nat, theater, year, month, true, true ) ;
var capabilities = make_capabilities( true, obj, nat, theater, year, month, true ) ;
buf.push( "<td>", listval(capabilities) ) ;
var capabilities = make_capabilities( obj, nat, theater, year, month, true, false ) ;
var capabilities = make_capabilities( false, obj, nat, theater, year, month, true ) ;
buf.push( "<td>", listval(capabilities) ) ;
buf.push( "<td>", "<span class='val'>" + fmtval(obj.note_number) + "</span>" ) ;
buf.push( "<td>", listval(obj.notes) ) ;

@ -8,10 +8,11 @@ from selenium.webdriver.common.keys import Keys
from vasl_templates.webapp.tests.utils import \
init_webapp, select_menu_option, select_tab, click_dialog_button, \
find_child, find_children, wait_for_clipboard
load_vasl_mod, find_child, find_children, wait_for_clipboard
from vasl_templates.webapp.tests.test_vo_reports import get_vo_report
from vasl_templates.webapp.tests.test_vehicles_ordnance import add_vo
from vasl_templates.webapp.tests.test_scenario_persistence import save_scenario, load_scenario
from vasl_templates.webapp.config.constants import DATA_DIR as REAL_DATA_DIR
# ---------------------------------------------------------------------
@ -534,6 +535,138 @@ def test_custom_capabilities( webapp, webdriver ): #pylint: disable=too-many-sta
# ---------------------------------------------------------------------
@pytest.mark.skipif(
not pytest.config.option.vasl_mods, #pylint: disable=no-member
reason = "--vasl-mods not specified"
) #pylint: disable=too-many-statements
def test_capability_updates_in_ui( webapp, webdriver, monkeypatch ):
"""Ensure that capabilities are updated in the UI correctly."""
# initialize
monkeypatch.setitem( webapp.config, "DATA_DIR", REAL_DATA_DIR )
load_vasl_mod( REAL_DATA_DIR, monkeypatch )
init_webapp( webapp, webdriver, scenario_persistence=1 )
# load the scenario
scenario_data = {
"PLAYER_1": "german",
"OB_VEHICLES_1": [ { "name": "PzKpfw 38(t)A" } ], # A4[1]/5[2] ; sD6 ; CS 4
"OB_ORDNANCE_1": [ { "name": "3.7cm PaK 35/36" } ], # NT ; QSU ; A4[1]/5[2]/4[3]/3[4] ; H6[9]†
"PLAYER_2": "russian",
"OB_VEHICLES_2": [ { "name": "Churchill III(b)" } ], # D6[J4]/7[5]† ; HE7[F3]/8[4+]† ; sD6[4+] ; sM8† ; CS 7
"OB_ORDNANCE_2": [ { "name": "45mm PTP obr. 32" } ], # NT ; QSU ; A4[2]/5[3]/6[4]/7[5]
}
scenario_data["OB_VEHICLES_1"].append( { "name": "PzJg I" } ) # A5[1]; HE7 ; CS 3
load_scenario( scenario_data )
sortables = [
find_child( "#ob_vehicles-sortable_1" ),
find_child( "#ob_ordnance-sortable_1" ),
find_child( "#ob_vehicles-sortable_2" ),
find_child( "#ob_ordnance-sortable_2" ),
]
def check_capabilities( scenario_date, expected ):
"""Get the vehicle/ordnance capabilities from the UI."""
# set the scenario date
if scenario_date:
elem = find_child( "input[name='SCENARIO_DATE']" )
elem.clear()
elem.send_keys( scenario_date )
elem.send_keys( Keys.TAB )
# check the vehicle/ordnance capabilities
results = []
for sortable in sortables:
results.append( [] )
vo_entries = find_children( "li", sortable )
for vo_entry in vo_entries:
capabilities = find_children( "span.vo-capability", vo_entry )
results[-1].append( [ c.get_attribute("innerHTML") for c in capabilities ] )
assert results == expected
# no scenario date => we should be showing the raw capabilities
check_capabilities( None, [
[
[ "A4<sup>1</sup>5<sup>2</sup>", "sD6", "CS 4" ],
[ "A5<sup>1</sup>", "HE7", "CS 3" ]
],
[ [ "NT", "QSU", "A4<sup>1</sup>5<sup>2</sup>4<sup>3</sup>3<sup>4</sup>", "H6[9]\u2020" ] ],
[ [ "D6<sup>J4</sup>7<sup>5</sup>†", "HE7<sup>F3</sup>8<sup>4+</sup>\u2020", "sD6<sup>4+</sup>", "sM8\u2020", "CS 7" ] ], #pylint: disable=line-too-long
[ [ "NT", "QSU", "A4<sup>2</sup>5<sup>3</sup>6<sup>4</sup>7<sup>5</sup>" ] ]
] )
# edit the PzJg I's capabilities (nb: this locks them in, and they should not change
# regardless of what the scenario date is set to)
select_tab( "ob1" )
vehicles_sortable = find_child( "#ob_vehicles-sortable_1" )
elems = find_children( "li", vehicles_sortable )
assert len(elems) == 2
ActionChains(webdriver).double_click( elems[1] ).perform()
elem = find_child( "#vo_capabilities-add" )
elem.click()
elems = find_children( "#vo_capabilities-sortable input[type='text']" )
assert len(elems) == 4
elems[3].send_keys( "foo!" )
click_dialog_button( "OK" )
# change the scenario date, check the capabilities
select_tab( "scenario" )
check_capabilities( "01/01/1940", [
[
[ "sD6", "CS 4" ],
[ "A5<sup>1</sup>", "HE7", "CS 3", "foo!" ]
],
[ [ "NT", "QSU", "H6[9]\u2020" ] ],
[ [ "sM8\u2020", "CS 7" ] ],
[ [ "NT", "QSU" ] ]
] )
check_capabilities( "01/01/1941", [
[
[ "A4", "sD6", "CS 4" ] ,
[ "A5<sup>1</sup>", "HE7", "CS 3", "foo!" ]
],
[ [ "NT", "QSU", "A4", "H6[9]\u2020" ] ],
[ [ "sM8\u2020", "CS 7" ] ],
[ [ "NT", "QSU" ] ]
] )
check_capabilities( "01/01/1942", [
[
[ "A5", "sD6", "CS 4" ],
[ "A5<sup>1</sup>", "HE7", "CS 3", "foo!" ]
],
[ [ "NT", "QSU", "A5", "H6[9]\u2020" ] ],
[ [ "sM8\u2020", "CS 7" ] ],
[ [ "NT", "QSU", "A4" ] ]
] )
check_capabilities( "01/01/1943", [
[
[ "A5", "sD6", "CS 4" ],
[ "A5<sup>1</sup>", "HE7", "CS 3", "foo!" ]
],
[ [ "NT", "QSU", "A4", "H6[9]\u2020" ] ],
[ [ "sM8\u2020", "CS 7" ] ],
[ [ "NT", "QSU", "A5" ] ]
] )
check_capabilities( "01/01/1944", [
[
[ "A5", "sD6", "CS 4" ],
[ "A5<sup>1</sup>", "HE7", "CS 3", "foo!" ]
],
[ [ "NT", "QSU", "A3", "H6[9]\u2020" ] ],
[ [ "HE8\u2020", "sD6", "sM8\u2020", "CS 7" ] ],
[ [ "NT", "QSU", "A6" ] ]
] )
check_capabilities( "01/01/1945", [
[
[ "A5", "sD6", "CS 4" ],
[ "A5<sup>1</sup>", "HE7", "CS 3", "foo!" ]
],
[ [ "NT", "QSU", "A3", "H6[9]\u2020" ] ],
[ [ "D7\u2020", "HE8\u2020", "sD6", "sM8\u2020", "CS 7" ] ],
[ [ "NT", "QSU", "A7" ] ]
] )
# ---------------------------------------------------------------------
def _check_capabilities( webdriver, webapp,
nat, vo_type, vo_name, scenario_theater, scenario_date,
expected, row=None

@ -9,7 +9,8 @@ from selenium.webdriver.support.ui import Select
from vasl_templates.webapp.config.constants import APP_NAME
from vasl_templates.webapp.tests.utils import \
init_webapp, get_nationality_display_name, load_scenario_params, select_tab, select_menu_option, \
get_sortable_entry_text, get_stored_msg, set_stored_msg, set_stored_msg_marker, find_child, find_children, wait_for
get_sortable_entry_text, get_sortable_vo_names, get_stored_msg, set_stored_msg, set_stored_msg_marker, \
find_child, find_children, wait_for
# this table lists all parameters stored in a scenario
ALL_SCENARIO_PARAMS = {
@ -181,13 +182,13 @@ def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-st
assert get_sortable_entry_text(ob_setups1) == [ obs["caption"] for obs in SCENARIO_PARAMS["ob1"]["OB_SETUPS_1"] ]
assert get_sortable_entry_text(ob_notes1) == [ obs["caption"] for obs in SCENARIO_PARAMS["ob1"]["OB_NOTES_1"] ]
# NOTE: We deleted the "id" fields above, so we rely on the legacy handling of loading by name :-/
assert get_sortable_entry_text(vehicles1) == SCENARIO_PARAMS["ob1"]["OB_VEHICLES_1"]
assert get_sortable_entry_text(ordnance1) == SCENARIO_PARAMS["ob1"]["OB_ORDNANCE_1"]
assert get_sortable_vo_names(vehicles1) == SCENARIO_PARAMS["ob1"]["OB_VEHICLES_1"]
assert get_sortable_vo_names(ordnance1) == SCENARIO_PARAMS["ob1"]["OB_ORDNANCE_1"]
select_tab( "ob2" )
assert get_sortable_entry_text(ob_setups2) == [ obs["caption"] for obs in SCENARIO_PARAMS["ob2"]["OB_SETUPS_2"] ]
assert get_sortable_entry_text(ob_notes2) == [ obs["caption"] for obs in SCENARIO_PARAMS["ob2"]["OB_NOTES_2"] ]
assert get_sortable_entry_text(vehicles2) == SCENARIO_PARAMS["ob2"]["OB_VEHICLES_2"]
assert get_sortable_entry_text(ordnance2) == SCENARIO_PARAMS["ob2"]["OB_ORDNANCE_2"]
assert get_sortable_vo_names(vehicles2) == SCENARIO_PARAMS["ob2"]["OB_VEHICLES_2"]
assert get_sortable_vo_names(ordnance2) == SCENARIO_PARAMS["ob2"]["OB_ORDNANCE_2"]
# ---------------------------------------------------------------------

@ -14,7 +14,7 @@ from vasl_templates.webapp.tests.test_scenario_persistence import load_scenario,
from vasl_templates.webapp.tests.utils import \
init_webapp, load_vasl_mod, get_nationalities, select_tab, set_template_params, find_child, find_children, \
wait_for_clipboard, click_dialog_button, select_menu_option, select_droplist_val, \
set_stored_msg_marker, get_stored_msg
set_stored_msg_marker, get_stored_msg, get_sortable_vo_names
from vasl_templates.webapp.config.constants import DATA_DIR as REAL_DATA_DIR
# ---------------------------------------------------------------------
@ -255,9 +255,8 @@ def test_html_names( webapp, webdriver, monkeypatch ):
elem.send_keys( Keys.RETURN )
# make sure it was added to the player's OB
entries = find_children( "#ob_vehicles-sortable_1 li" )
entries = [ e.text for e in entries ]
assert entries == [ "PzKpfw IVF2" ]
vehicles_sortable = find_child( "#ob_vehicles-sortable_1" )
assert get_sortable_vo_names( vehicles_sortable ) == [ "PzKpfw IVF2" ]
# start to add another vehicle - make sure only the PzKw IVF1 is present
add_vehicle_btn.click()
@ -269,9 +268,7 @@ def test_html_names( webapp, webdriver, monkeypatch ):
elem.send_keys( Keys.RETURN )
# make sure it was added to the player's OB
entries = find_children( "#ob_vehicles-sortable_1 li" )
entries = [ e.text for e in entries ]
assert entries == [ "PzKpfw IVF2", "PzKpfw IVF1" ]
assert get_sortable_vo_names( vehicles_sortable ) == [ "PzKpfw IVF2", "PzKpfw IVF1" ]
# start to add another vehicle - make sure there are no PzKw IVF's present
add_vehicle_btn.click()
@ -736,8 +733,9 @@ def delete_vo( vo_type, player_no, name, webdriver ):
# delete the vehicle/ordnance
select_tab( "ob{}".format( player_no ) )
sortable = find_child( "#ob_{}-sortable_{}".format( vo_type, player_no ) )
elems = [
c for c in find_children( "#ob_{}-sortable_{} li".format( vo_type, player_no ) )
c for c in find_children( "li .vo-name", sortable )
if c.text == name
]
assert len(elems) == 1

@ -203,7 +203,7 @@ def set_template_params( params ): #pylint: disable=too-many-branches
if val:
elem.send_keys( val )
if key == "SCENARIO_DATE":
elem.send_keys( Keys.ESCAPE ) # nb: force the calendar popup to close :-/
elem.send_keys( Keys.TAB ) # nb: force the calendar popup to close :-/
wait_for( 5, lambda: find_child("#ui-datepicker-div").value_of_css_property("display") == "none" )
time.sleep( 0.25 )
@ -267,6 +267,10 @@ def get_sortable_entry_count( sortable ):
"""Return the number of entries in a sortable."""
return len( find_children( "li", sortable ) )
def get_sortable_vo_names( sortable ):
"""Return the vehicle/ordnance names from a sortable."""
return [ c.text for c in find_children("li .vo-name",sortable) ]
def generate_sortable_entry_snippet( sortable, entry_no ):
"""Generate the snippet for a sortable entry."""
elems = find_children( "li img.snippet", sortable )

Loading…
Cancel
Save