|
|
|
@ -3,7 +3,8 @@ |
|
|
|
|
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, load_scenario_params, get_sortable_entry_count |
|
|
|
|
select_droplist_val, init_webapp, load_scenario_params, \ |
|
|
|
|
wait_for, get_sortable_entry_count, click_dialog_button |
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
@ -29,52 +30,57 @@ def test_player_change( webapp, webdriver ): |
|
|
|
|
expected = "{} OB".format( nationalities[player_id]["display_name"] ) |
|
|
|
|
assert ob_tabs[player_no].text.strip() == expected |
|
|
|
|
|
|
|
|
|
# check that we can change the player nationalities without being asked to confirm |
|
|
|
|
# nb: the frontend ignores the vehicle/ordnance snippet widths when deciding if to ask for confirmation |
|
|
|
|
VO_WIDTHS = { |
|
|
|
|
"ob1": { "VEHICLES_WIDTH_1": 123 }, |
|
|
|
|
"ob2": { "ORDNANCE_WIDTH_2": 456 }, |
|
|
|
|
} |
|
|
|
|
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"] ) |
|
|
|
|
select_droplist_val( player_sel[2], "german" ) |
|
|
|
|
assert ob_tabs[2].text.strip() == "{} OB".format( nationalities["german"]["display_name"] ) |
|
|
|
|
|
|
|
|
|
# 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", |
|
|
|
|
"VEHICLES_2": [ "a german vehicle" ], |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
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 ) ) |
|
|
|
|
def get_sortable_counts( player_no ): |
|
|
|
|
"""Get the contents of the player's OB tab.""" |
|
|
|
|
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 |
|
|
|
|
return [ get_sortable_entry_count(s) for s in sortables ] |
|
|
|
|
|
|
|
|
|
# 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 ) |
|
|
|
|
for player_no in [1,2]: |
|
|
|
|
|
|
|
|
|
# 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 ) |
|
|
|
|
# try to change the player's nationality |
|
|
|
|
select_droplist_val( player_sel[player_no], "finnish" ) |
|
|
|
|
wait_for( 2, lambda: find_child("#ask") ) |
|
|
|
|
|
|
|
|
|
# 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 get_sortable_counts( player_no ) == \ |
|
|
|
|
[1,0,0,0] if player_no == 1 else [0,0,1,0] |
|
|
|
|
|
|
|
|
|
# try to change the player's nationality |
|
|
|
|
select_droplist_val( player_sel[player_no], "finnish" ) |
|
|
|
|
wait_for( 2, lambda: find_child("#ask") ) |
|
|
|
|
|
|
|
|
|
# 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 get_sortable_counts( player_no ) == [0,0,0,0] |
|
|
|
|