Reset the OB tab correctly when changing a player's nationality.

master
Pacman Ghost 6 years ago
parent 366eedca48
commit 7957d6603f
  1. 5
      vasl_templates/webapp/static/main.js
  2. 6
      vasl_templates/webapp/static/snippets.js
  3. 44
      vasl_templates/webapp/tests/test_players.py
  4. 6
      vasl_templates/webapp/tests/test_scenario_persistence.py
  5. 6
      vasl_templates/webapp/tests/utils.py

@ -431,6 +431,8 @@ function install_template_pack( data )
function on_player_change( $select )
{
// FIXME! We should really ask the user to confirm this operation.
// figure out which player was changed
var name = $select.attr( "name" ) ;
var player_no = name.substring( name.length-1 ) ;
@ -448,8 +450,9 @@ function on_player_change( $select )
}
// reset the OB params
$("textarea[name='OB_SETUP_"+player_no+"']").val( "" ) ;
$( "#ob_setups-sortable_" + player_no ).sortable2( "delete-all" ) ;
$("input[name='OB_SETUP_WIDTH_"+player_no+"']").val( "" ) ;
$( "#ob_notes-sortable_" + player_no ).sortable2( "delete-all" ) ;
$( "#vehicles-sortable_" + player_no ).sortable2( "delete-all" ) ;
$("input[name='VEHICLES_WIDTH_"+player_no+"']").val( "" ) ;
$( "#ordnance-sortable_" + player_no ).sortable2( "delete-all" ) ;

@ -741,12 +741,6 @@ function reset_scenario()
// reset all the template parameters
$("#scenario_notes-sortable").sortable2( "delete-all" ) ;
$("#ssr-sortable").sortable2( "delete-all" ) ;
for ( player_no=1 ; player_no <= 2 ; ++player_no ) {
$( "#ob_setups-sortable_" + player_no ).sortable2( "delete-all" ) ;
$( "#ob_notes-sortable_" + player_no ).sortable2( "delete-all" ) ;
$( "#vehicles-sortable_" + player_no ).sortable2( "delete-all" ) ;
$( "#ordnance-sortable_" + player_no ).sortable2( "delete-all" ) ;
}
}
// --------------------------------------------------------------------

@ -3,7 +3,7 @@
from selenium.webdriver.support.ui import Select
from vasl_templates.webapp.tests.utils import get_nationalities, select_tab, find_child, \
select_droplist_val, init_webapp
select_droplist_val, init_webapp, load_scenario_params, get_sortable_entry_count
# ---------------------------------------------------------------------
@ -29,10 +29,52 @@ def test_player_change( webapp, webdriver ):
expected = "{} OB".format( nationalities[player_id]["display_name"] )
assert ob_tabs[player_no].text.strip() == expected
# load the OB tabs
SCENARIO_PARAMS = {
"ob1": {
"OB_SETUPS_1": [ { "caption": "an ob setup", "width": "" } ],
"OB_NOTES_1": [ { "caption": "an ob note", "width": "" } ],
"VEHICLES_1": [ "a german vehicle" ],
"VEHICLES_WIDTH_1": "101",
"ORDNANCE_1": [ "a german ordnance" ],
"ORDNANCE_WIDTH_1": "102",
},
"ob2": {
"OB_SETUPS_2": [ { "caption": "another ob setup", "width": "" } ],
"OB_NOTES_2": [ { "caption": "another ob note", "width": "" } ],
"VEHICLES_2": [ "a russian vehicle" ],
"VEHICLES_WIDTH_2": "201",
"ORDNANCE_2": [ "a russian ordnance" ],
"ORDNANCE_WIDTH_2": "202",
},
}
load_scenario_params( SCENARIO_PARAMS )
def is_ob_tab_empty( player_no ):
"""Check if an OB tab is empty."""
select_tab( "ob{}".format( player_no ) )
sortables = [
find_child( "#{}-sortable_{}".format( key, player_no ) )
for key in ["ob_setups","ob_notes","vehicles","ordnance"]
]
if any( get_sortable_entry_count(s) > 0 for s in sortables ):
return False
widths = [
find_child( "input[name='{}_WIDTH_{}']".format( key, player_no ) )
for key in ["VEHICLES","ORDNANCE"]
]
if any( w.get_attribute("value") for w in widths ):
return False
return True
# change player 1
select_tab( "scenario" )
select_droplist_val( player_sel[1], "finnish" )
assert ob_tabs[1].text.strip() == "{} OB".format( nationalities["finnish"]["display_name"] )
assert is_ob_tab_empty( 1 )
# change player 2
select_tab( "scenario" )
select_droplist_val( player_sel[2], "japanese" )
assert ob_tabs[2].text.strip() == "{} OB".format( nationalities["japanese"]["display_name"] )
assert is_ob_tab_empty( 2 )

@ -7,7 +7,7 @@ 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_nationalities, set_template_params, select_tab, select_menu_option, \
init_webapp, get_nationalities, 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
# this table lists all parameters stored in a scenario
@ -97,9 +97,7 @@ def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-st
"ORDNANCE_WIDTH_2": "303",
},
}
for tab_id,fields in SCENARIO_PARAMS.items():
select_tab( tab_id )
set_template_params( fields )
load_scenario_params( SCENARIO_PARAMS )
check_window_title( "my test scenario" )
check_ob_tabs( "russian", "german" )

@ -105,6 +105,12 @@ def select_menu_option( menu_id ):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def load_scenario_params( params ):
"""Load a full set of template parameters."""
for tab_id,fields in params.items():
select_tab( tab_id )
set_template_params( fields )
def set_template_params( params ): #pylint: disable=too-many-branches
"""Set template parameters."""

Loading…
Cancel
Save