diff --git a/vasl_templates/webapp/static/css/sortable.css b/vasl_templates/webapp/static/css/sortable.css index 5a414b2..f44b8c2 100644 --- a/vasl_templates/webapp/static/css/sortable.css +++ b/vasl_templates/webapp/static/css/sortable.css @@ -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 ; } diff --git a/vasl_templates/webapp/static/css/tabs-ob.css b/vasl_templates/webapp/static/css/tabs-ob.css index a322f7c..8c4ab5e 100644 --- a/vasl_templates/webapp/static/css/tabs-ob.css +++ b/vasl_templates/webapp/static/css/tabs-ob.css @@ -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 ; } diff --git a/vasl_templates/webapp/static/css/tabs-scenario.css b/vasl_templates/webapp/static/css/tabs-scenario.css index 3e32bd7..56d5950 100644 --- a/vasl_templates/webapp/static/css/tabs-scenario.css +++ b/vasl_templates/webapp/static/css/tabs-scenario.css @@ -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 ; } diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 6bcdbc7..9737b9d 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -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 ) ) ; + } } // -------------------------------------------------------------------- diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index eb60185..9aa6d74 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -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 ; } diff --git a/vasl_templates/webapp/static/vo.js b/vasl_templates/webapp/static/vo.js index bae11fd..60bb3f8 100644 --- a/vasl_templates/webapp/static/vo.js +++ b/vasl_templates/webapp/static/vo.js @@ -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 = "" + vo_entry.name + "" ), + var buf = [ div_tag, + "", + "
", + "
", + "
", + "
", + "" ] ; + 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] = "" + capabilities[i] + "" ; + $content.find( "div.vo-capabilities" ).html( capabilities.join("") ) ; } // -------------------------------------------------------------------- diff --git a/vasl_templates/webapp/static/vo2.js b/vasl_templates/webapp/static/vo2.js index 1f5f863..c30ccdb 100644 --- a/vasl_templates/webapp/static/vo2.js +++ b/vasl_templates/webapp/static/vo2.js @@ -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" ) ; }, diff --git a/vasl_templates/webapp/templates/tabs-ob1.html b/vasl_templates/webapp/templates/tabs-ob1.html index 355ea71..5bb6a92 100644 --- a/vasl_templates/webapp/templates/tabs-ob1.html +++ b/vasl_templates/webapp/templates/tabs-ob1.html @@ -46,7 +46,7 @@
Vehicles -
+
@@ -64,8 +64,8 @@
-
Ordnance -
+
Ordnance +
diff --git a/vasl_templates/webapp/templates/vo-report.html b/vasl_templates/webapp/templates/vo-report.html index 4d2ef0b..df9749b 100644 --- a/vasl_templates/webapp/templates/vo-report.html +++ b/vasl_templates/webapp/templates/vo-report.html @@ -68,9 +68,9 @@ function load_vo_listings( objs ) continue ; buf.push( "" ) ; buf.push( "", 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( "", 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( "", listval(capabilities) ) ; buf.push( "", "" + fmtval(obj.note_number) + "" ) ; buf.push( "", listval(obj.notes) ) ; diff --git a/vasl_templates/webapp/tests/test_capabilities.py b/vasl_templates/webapp/tests/test_capabilities.py index 9db9be2..90e330b 100644 --- a/vasl_templates/webapp/tests/test_capabilities.py +++ b/vasl_templates/webapp/tests/test_capabilities.py @@ -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, [ + [ + [ "A4152", "sD6", "CS 4" ], + [ "A51", "HE7", "CS 3" ] + ], + [ [ "NT", "QSU", "A41524334", "H6[9]\u2020" ] ], + [ [ "D6J475†", "HE7F384+\u2020", "sD64+", "sM8\u2020", "CS 7" ] ], #pylint: disable=line-too-long + [ [ "NT", "QSU", "A42536475" ] ] + ] ) + + # 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" ], + [ "A51", "HE7", "CS 3", "foo!" ] + ], + [ [ "NT", "QSU", "H6[9]\u2020" ] ], + [ [ "sM8\u2020", "CS 7" ] ], + [ [ "NT", "QSU" ] ] + ] ) + check_capabilities( "01/01/1941", [ + [ + [ "A4", "sD6", "CS 4" ] , + [ "A51", "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" ], + [ "A51", "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" ], + [ "A51", "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" ], + [ "A51", "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" ], + [ "A51", "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 diff --git a/vasl_templates/webapp/tests/test_scenario_persistence.py b/vasl_templates/webapp/tests/test_scenario_persistence.py index 78b9a50..896cad1 100644 --- a/vasl_templates/webapp/tests/test_scenario_persistence.py +++ b/vasl_templates/webapp/tests/test_scenario_persistence.py @@ -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"] # --------------------------------------------------------------------- diff --git a/vasl_templates/webapp/tests/test_vehicles_ordnance.py b/vasl_templates/webapp/tests/test_vehicles_ordnance.py index 9583685..f898f92 100644 --- a/vasl_templates/webapp/tests/test_vehicles_ordnance.py +++ b/vasl_templates/webapp/tests/test_vehicles_ordnance.py @@ -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 diff --git a/vasl_templates/webapp/tests/utils.py b/vasl_templates/webapp/tests/utils.py index feff613..d7e530b 100644 --- a/vasl_templates/webapp/tests/utils.py +++ b/vasl_templates/webapp/tests/utils.py @@ -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 )