Added a helper function to get nationality display names.

master
Pacman Ghost 6 years ago
parent b095dee636
commit fe5bce72da
  1. 1
      conftest.py
  2. 7
      vasl_templates/webapp/static/main.js
  3. 9
      vasl_templates/webapp/static/snippets.js
  4. 8
      vasl_templates/webapp/static/utils.js
  5. 2
      vasl_templates/webapp/static/vo.js
  6. 13
      vasl_templates/webapp/tests/test_players.py
  7. 5
      vasl_templates/webapp/tests/test_scenario_persistence.py
  8. 13
      vasl_templates/webapp/tests/utils.py

@ -163,7 +163,6 @@ def webdriver( request ):
driver.set_window_size( int(words[0]), int(words[1]) )
# return the webdriver to the caller
utils._webdriver = driver #pylint: disable=protected-access
yield driver
# clean up

@ -430,9 +430,8 @@ function install_template_pack( data )
2: $("select[name='PLAYER_2']").val()
} ;
var buf = [] ;
var nationalities = gTemplatePack.nationalities ;
for ( var id in nationalities )
buf.push( "<option value='" + id + "'>" + nationalities[id].display_name + "</option>" ) ;
for ( var id in gTemplatePack.nationalities )
buf.push( "<option value='" + id + "'>" + get_nationality_display_name(id) + "</option>" ) ;
buf = buf.join( "" ) ;
for ( var player_no=1 ; player_no <= 2 ; ++player_no ) {
var $sel = $( "select[name='PLAYER_" + player_no + "']" ) ;
@ -511,7 +510,7 @@ function update_ob_tab_header( player_no )
{
// update the OB tab header for the specified player
var player_nat = $( "select[name='PLAYER_" + player_no + "']" ).val() ;
var display_name = gTemplatePack.nationalities[ player_nat ].display_name ;
var display_name = get_nationality_display_name( player_nat ) ;
var image_url = gImagesBaseUrl + "/flags/" + player_nat + ".png" ;
var $elem = $( "#tabs .ui-tabs-nav a[href='#tabs-ob" + player_no + "']" ) ;
$elem.html(

@ -43,16 +43,15 @@ function generate_snippet( $btn, extra_params )
unload_snippet_params( params, true ) ;
// set player-specific parameters
var nationalities = gTemplatePack.nationalities ;
var curr_tab = $("#tabs .ui-tabs-active a").attr( "href" ) ;
var colors ;
if ( curr_tab === "#tabs-ob1" ) {
params.PLAYER_NAME = nationalities[params.PLAYER_1].display_name ;
params.PLAYER_NAME = get_nationality_display_name( params.PLAYER_1 ) ;
colors = get_player_colors( 1 ) ;
params.OB_COLOR = colors[0] ;
params.OB_COLOR_2 = colors[1] ;
} else if ( curr_tab === "#tabs-ob2" ) {
params.PLAYER_NAME = nationalities[params.PLAYER_2].display_name ;
params.PLAYER_NAME = get_nationality_display_name( params.PLAYER_2 ) ;
colors = get_player_colors( 2 ) ;
params.OB_COLOR = colors[0] ;
params.OB_COLOR_2 = colors[1] ;
@ -79,8 +78,8 @@ function generate_snippet( $btn, extra_params )
}
// include the player display names
params.PLAYER_1_NAME = nationalities[params.PLAYER_1].display_name ;
params.PLAYER_2_NAME = nationalities[params.PLAYER_2].display_name ;
params.PLAYER_1_NAME = get_nationality_display_name( params.PLAYER_1 ) ;
params.PLAYER_2_NAME = get_nationality_display_name( params.PLAYER_2 ) ;
// generate PF parameters
if ( params.SCENARIO_YEAR < 1944 || (params.SCENARIO_YEAR == 1944 && params.SCENARIO_MONTH < 6) )

@ -1,4 +1,12 @@
// --------------------------------------------------------------------
function get_nationality_display_name( nat_id )
{
// get the nationality's display name
return gTemplatePack.nationalities[ nat_id ].display_name ;
}
function get_player_colors( player_no )
{
// get the colors for the specified player

@ -14,7 +14,7 @@ function add_vo( vo_type, player_no )
var nat = $( "select[name='PLAYER_" + player_no + "']" ).val() ;
var entries = gVehicleOrdnanceListings[vo_type][nat] ;
if ( entries === undefined ) {
showErrorMsg( "There are no " + gTemplatePack.nationalities[nat].display_name + " " + vo_type + " listings." ) ;
showErrorMsg( "There are no " + get_nationality_display_name(nat) + " " + vo_type + " listings." ) ;
return ;
}
var buf = [] ;

@ -2,7 +2,7 @@
from selenium.webdriver.support.ui import Select
from vasl_templates.webapp.tests.utils import get_nationalities, select_tab, find_child, \
from vasl_templates.webapp.tests.utils import get_nationality_display_name, select_tab, find_child, \
select_droplist_val, init_webapp, load_scenario_params, \
wait_for, get_sortable_entry_count, click_dialog_button
@ -14,7 +14,6 @@ def test_player_change( webapp, webdriver ):
# initialize
init_webapp( webapp, webdriver )
select_tab( "scenario" )
nationalities = get_nationalities( webapp )
player_sel = {
1: Select( find_child( "select[name='PLAYER_1']" ) ),
2: Select( find_child( "select[name='PLAYER_2']" ) )
@ -27,7 +26,7 @@ def test_player_change( webapp, webdriver ):
# make sure that the UI was updated correctly for the initial players
for player_no in [1,2]:
player_id = player_sel[player_no].first_selected_option.get_attribute( "value" )
expected = "{} OB".format( nationalities[player_id]["display_name"] )
expected = "{} OB".format( get_nationality_display_name(player_id) )
assert ob_tabs[player_no].text.strip() == expected
# check that we can change the player nationalities without being asked to confirm
@ -39,9 +38,9 @@ def test_player_change( webapp, webdriver ):
load_scenario_params( VO_WIDTHS )
select_tab( "scenario" )
select_droplist_val( player_sel[1], "russian" )
assert ob_tabs[1].text.strip() == "{} OB".format( nationalities["russian"]["display_name"] )
assert ob_tabs[1].text.strip() == "{} OB".format( get_nationality_display_name("russian") )
select_droplist_val( player_sel[2], "german" )
assert ob_tabs[2].text.strip() == "{} OB".format( nationalities["german"]["display_name"] )
assert ob_tabs[2].text.strip() == "{} OB".format( get_nationality_display_name("german") )
# load the OB tabs
SCENARIO_PARAMS = {
@ -72,7 +71,7 @@ def test_player_change( webapp, webdriver ):
# cancel the confirmation request and make sure nothing changed
click_dialog_button( "Cancel" )
nat_id = "russian" if player_no == 1 else "german"
assert ob_tabs[player_no].text.strip() == "{} OB".format( nationalities[nat_id]["display_name"] )
assert ob_tabs[player_no].text.strip() == "{} OB".format( get_nationality_display_name(nat_id) )
assert get_sortable_counts( player_no ) == \
[1,0,0,0] if player_no == 1 else [0,0,1,0]
@ -82,5 +81,5 @@ def test_player_change( webapp, webdriver ):
# confirm the request and make sure the OB tab was cleared
click_dialog_button( "OK" )
assert ob_tabs[player_no].text.strip() == "{} OB".format( nationalities["finnish"]["display_name"] )
assert ob_tabs[player_no].text.strip() == "{} OB".format( get_nationality_display_name("finnish") )
assert get_sortable_counts( player_no ) == [0,0,0,0]

@ -8,7 +8,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, load_scenario_params, select_tab, select_menu_option, \
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
# this table lists all parameters stored in a scenario
@ -40,14 +40,13 @@ def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-st
# initialize
init_webapp( webapp, webdriver, scenario_persistence=1 )
nationalities = get_nationalities( webapp )
def check_ob_tabs( *args ):
"""Check that the OB tabs have been set correctly."""
for player_no in [1,2]:
elem = find_child( "#tabs .ui-tabs-nav a[href='#tabs-ob{}']".format( player_no ) )
nat = args[ player_no-1 ]
assert elem.text.strip() == "{} OB".format( nationalities[nat]["display_name"] )
assert elem.text.strip() == "{} OB".format( get_nationality_display_name(nat) )
def check_window_title( expected ):
"""Check the window title."""

@ -29,12 +29,16 @@ _NAT_TEMPLATES = {
"british": [ "piat" ],
}
_webapp = None
_webdriver = None
# ---------------------------------------------------------------------
def init_webapp( webapp, webdriver, **options ):
"""Initialize the webapp."""
global _webapp, _webdriver
_webapp = webapp
_webdriver = webdriver
webdriver.get( webapp.url_for( "main", **options ) )
wait_for( 5, lambda: find_child("#_page-loaded_") is not None )
@ -176,6 +180,15 @@ def set_template_params( params ): #pylint: disable=too-many-branches
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_nationalities = None
def get_nationality_display_name( nat_id ):
"""Get the nationality's display name."""
global _nationalities
if not _nationalities:
_nationalities = get_nationalities( _webapp )
return _nationalities[ nat_id ]["display_name"]
def get_nationalities( webapp ):
"""Get the nationalities table."""
url = webapp.url_for( "get_template_pack" )

Loading…
Cancel
Save