Handle ETO/PTO-only capabilities.

master
Pacman Ghost 6 years ago
parent 4693a7531f
commit 4b13100c45
  1. 18
      vasl_templates/webapp/static/snippets.js
  2. 2
      vasl_templates/webapp/templates/index.html
  3. 17
      vasl_templates/webapp/tests/fixtures/data/ordnance/american.json
  4. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/ordnance/american/1940.txt
  5. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/ordnance/american/1941.txt
  6. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/ordnance/american/1942.txt
  7. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/ordnance/american/1943.txt
  8. 4
      vasl_templates/webapp/tests/fixtures/vo-reports/ordnance/american/1944.txt
  9. 4
      vasl_templates/webapp/tests/fixtures/vo-reports/ordnance/american/1945.txt
  10. 55
      vasl_templates/webapp/tests/test_capabilities.py
  11. 35
      vasl_templates/webapp/tests/utils.py

@ -300,7 +300,7 @@ function make_capabilities( entry, scenario_theater, scenario_year, scenario_mon
capabilities.push( make_raw_capability( key, entry.capabilities2[key] ) ) ;
}
else {
var cap = select_capability_by_date( entry.capabilities2[key], scenario_year, scenario_month ) ;
var cap = select_capability_by_date( entry.capabilities2[key], scenario_theater, scenario_year, scenario_month ) ;
if ( ! cap )
continue ;
if ( cap == "<invalid>" ) {
@ -358,7 +358,7 @@ function make_raw_capability( name, capability )
return buf.join( "" ) ;
}
function select_capability_by_date( capabilities, scenario_year, scenario_month )
function select_capability_by_date( capabilities, scenario_theater, scenario_year, scenario_month )
{
var MONTH_NAMES = { F:2, J:6, A:8 } ;
@ -368,10 +368,16 @@ function select_capability_by_date( capabilities, scenario_year, scenario_month
// check for a ETO/PTO-only flag
var cap = capabilities[i][1].toString() ;
if ( cap.substring( cap.length-1 ) === "E" )
cap = cap.substring( 0, cap.length-1 ) ; // FIXME! handle this properly
if ( cap.substring( cap.length-1 ) === "P" )
cap = cap.substring( 0, cap.length-1 ) ; // FIXME! handle this properly
if ( cap.substring( cap.length-1 ) === "E" ) {
if ( scenario_theater != "ETO" )
return null ;
cap = cap.substring( 0, cap.length-1 ) ;
}
if ( cap.substring( cap.length-1 ) === "P" ) {
if ( scenario_theater != "PTO" )
return null ;
cap = cap.substring( 0, cap.length-1 ) ;
}
// remove any trailing "+" (FIXME! What does it even mean? Doesn't make sense :-/)
if ( cap.substring( cap.length-1 ) == "+" )
cap = cap.substring( 0, cap.length-1 ) ;

@ -62,7 +62,7 @@
<select name="SCENARIO_THEATER" class="param" title="Scenario theater">
<option value="ETO">ETO</option>
<option value="PTO">PTO</option>
<option value="">other</option>
<option value="other">other</option>
</select>
</div>
<div class='row'>

@ -0,0 +1,17 @@
[
{ "name": "M2A1 105mm Howitzer",
"capabilities": [ "NT" ],
"capabilities2": { "H": 6, "s": 7, "WP": 8, "C": [ [7,"4+P"], "\u2020<sup>1</sup>" ] },
"note_number": "14\u2020",
"notes": [ "C\u2020<sup>1</sup>", "N" ]
},
{ "name": "M3 105mm Howitzer",
"capabilities": [ "NT" ],
"capabilities2": { "H": 7, "s": 7, "WP": 8, "C": [ [7,"P"], "\u2020<sup>1</sup>" ] },
"note_number": "15\u2020",
"notes": [ "C\u2020<sup>1</sup>" ]
}
]

@ -16,7 +16,7 @@ M20 75mm Recoilless Rifle 5PP crewed†[1] H7 WP7 5PP crew
M1A1 75mm Pack Howitzer NT QSU C4[4+]†[1] H7 WP8 NT QSU H7 WP8 12† C†<sup>1</sup> F
M1897A2 75mm Gun NT QSU WP8 NT QSU WP8 13 P
M2A1 105mm Howitzer NT C7[4+P]†[1] H6 WP8 s7 NT H6 WP8 s7 14† C†<sup>1</sup> N
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT C7†[1] H7 WP8 s7 15† C†<sup>1</sup>
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT H7 WP8 s7 15† C†<sup>1</sup>
M1 4.5-in. Gun NT NT 16† <s>P</s>
M1918 155mm Howitzer NT WP8 s7[3+] NT WP8 17† N
M1 155mm Howitzer NT WP8 s7 NT WP8 s7 18† N

@ -16,7 +16,7 @@ M20 75mm Recoilless Rifle 5PP crewed†[1] H7 WP7 5PP crew
M1A1 75mm Pack Howitzer NT QSU C4[4+]†[1] H7 WP8 NT QSU H7 WP8 12† C†<sup>1</sup> F
M1897A2 75mm Gun NT QSU WP8 NT QSU WP8 13 P
M2A1 105mm Howitzer NT C7[4+P]†[1] H6 WP8 s7 NT H6 WP8 s7 14† C†<sup>1</sup> N
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT C7†[1] H7 WP8 s7 15† C†<sup>1</sup>
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT H7 WP8 s7 15† C†<sup>1</sup>
M1 4.5-in. Gun NT NT 16† <s>P</s>
M1918 155mm Howitzer NT WP8 s7[3+] NT WP8 17† N
M1 155mm Howitzer NT WP8 s7 NT WP8 s7 18† N

@ -16,7 +16,7 @@ M20 75mm Recoilless Rifle 5PP crewed†[1] H7 WP7 5PP crew
M1A1 75mm Pack Howitzer NT QSU C4[4+]†[1] H7 WP8 NT QSU H7 WP8 12† C†<sup>1</sup> F
M1897A2 75mm Gun NT QSU WP8 NT QSU WP8 13 P
M2A1 105mm Howitzer NT C7[4+P]†[1] H6 WP8 s7 NT H6 WP8 s7 14† C†<sup>1</sup> N
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT C7†[1] H7 WP8 s7 15† C†<sup>1</sup>
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT H7 WP8 s7 15† C†<sup>1</sup>
M1 4.5-in. Gun NT NT 16† <s>P</s>
M1918 155mm Howitzer NT WP8 s7[3+] NT WP8 17† N
M1 155mm Howitzer NT WP8 s7 NT WP8 s7 18† N

@ -16,7 +16,7 @@ M20 75mm Recoilless Rifle 5PP crewed†[1] H7 WP7 5PP crew
M1A1 75mm Pack Howitzer NT QSU C4[4+]†[1] H7 WP8 NT QSU H7 WP8 12† C†<sup>1</sup> F
M1897A2 75mm Gun NT QSU WP8 NT QSU WP8 13 P
M2A1 105mm Howitzer NT C7[4+P]†[1] H6 WP8 s7 NT H6 WP8 s7 14† C†<sup>1</sup> N
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT C7†[1] H7 WP8 s7 15† C†<sup>1</sup>
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT H7 WP8 s7 15† C†<sup>1</sup>
M1 4.5-in. Gun NT NT 16† <s>P</s>
M1918 155mm Howitzer NT WP8 s7[3+] NT WP8 s7 17† N
M1 155mm Howitzer NT WP8 s7 NT WP8 s7 18† N

@ -15,8 +15,8 @@ M18 57mm Recoilless Rifle 3PP crewed†[1] H7 WP6 3PP crew
M20 75mm Recoilless Rifle 5PP crewed†[1] H7 WP7 5PP crewed†[1] H7 WP7 11 D†<sup>1</sup> E†
M1A1 75mm Pack Howitzer NT QSU C4[4+]†[1] H7 WP8 NT QSU C4†[1] H7 WP8 12† C†<sup>1</sup> F
M1897A2 75mm Gun NT QSU WP8 NT QSU WP8 13 P
M2A1 105mm Howitzer NT C7[4+P]†[1] H6 WP8 s7 NT C7†[1] H6 WP8 s7 14† C†<sup>1</sup> N
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT C7†[1] H7 WP8 s7 15† C†<sup>1</sup>
M2A1 105mm Howitzer NT C7[4+P]†[1] H6 WP8 s7 NT H6 WP8 s7 14† C†<sup>1</sup> N
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT H7 WP8 s7 15† C†<sup>1</sup>
M1 4.5-in. Gun NT NT 16† <s>P</s>
M1918 155mm Howitzer NT WP8 s7[3+] NT WP8 s7 17† N
M1 155mm Howitzer NT WP8 s7 NT WP8 s7 18† N

@ -15,8 +15,8 @@ M18 57mm Recoilless Rifle 3PP crewed†[1] H7 WP6 3PP crew
M20 75mm Recoilless Rifle 5PP crewed†[1] H7 WP7 5PP crewed†[1] H7 WP7 11 D†<sup>1</sup> E†
M1A1 75mm Pack Howitzer NT QSU C4[4+]†[1] H7 WP8 NT QSU C4†[1] H7 WP8 12† C†<sup>1</sup> F
M1897A2 75mm Gun NT QSU WP8 NT QSU WP8 13 P
M2A1 105mm Howitzer NT C7[4+P]†[1] H6 WP8 s7 NT C7†[1] H6 WP8 s7 14† C†<sup>1</sup> N
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT C7†[1] H7 WP8 s7 15† C†<sup>1</sup>
M2A1 105mm Howitzer NT C7[4+P]†[1] H6 WP8 s7 NT H6 WP8 s7 14† C†<sup>1</sup> N
M3 105mm Howitzer NT C7[P]†[1] H7 WP8 s7 NT H7 WP8 s7 15† C†<sup>1</sup>
M1 4.5-in. Gun NT NT 16† <s>P</s>
M1918 155mm Howitzer NT WP8 s7[3+] NT WP8 s7 17† N
M1 155mm Howitzer NT WP8 s7 NT WP8 s7 18† N

@ -0,0 +1,55 @@
""" Test snippet generation for capabilities. """
from vasl_templates.webapp.tests.utils import \
init_webapp, select_tab, new_scenario, load_scenario_params, \
find_child, wait_for_clipboard
# ---------------------------------------------------------------------
def test_scenario_theater( webapp, webdriver ):
"""Test ETO/PTO-only capabilities."""
# initialize
init_webapp( webapp, webdriver )
def do_test( scenario_theater, scenario_date, expected ):
"""Test snippet generation."""
load_scenario_params( {
"scenario": {
"SCENARIO_THEATER": scenario_theater,
"SCENARIO_DATE": scenario_date,
}
} )
select_tab( "ob1" )
btn = find_child( "button.generate[data-id='ob_ordnance_1']" )
btn.click()
wait_for_clipboard( 2, "capabilities: {}".format(expected), contains=True )
# M2A1 105mm Howitzer: C7(4+P)†1
load_scenario_params( {
"scenario": {
"PLAYER_1": "american",
},
"ob1": {
"OB_ORDNANCE_1": [ "M2A1 105mm Howitzer" ],
}
} )
do_test( "ETO", "01/01/1940", '"NT" "H6" "WP8" "s7"')
do_test( "ETO", "01/01/1944", '"NT" "H6" "WP8" "s7"')
do_test( "ETO", "01/01/1945", '"NT" "H6" "WP8" "s7"')
do_test( "PTO", "01/01/1940", '"NT" "H6" "WP8" "s7"')
do_test( "PTO", "01/01/1944", '"NT" "C7" "H6" "WP8" "s7"')
do_test( "PTO", "01/01/1945", '"NT" "C7" "H6" "WP8" "s7"')
# M3 105mm Howitzer: C7(P)†1
new_scenario()
load_scenario_params( {
"scenario": {
"PLAYER_1": "american",
},
"ob1": {
"OB_ORDNANCE_1": [ "M3 105mm Howitzer" ],
}
} )
do_test( "ETO", "01/01/1940", '"NT" "H7" "WP8" "s7"')
do_test( "PTO", "01/01/1940", '"NT" "C7" "H7" "WP8" "s7"')

@ -110,6 +110,14 @@ def select_menu_option( menu_id ):
# FUDGE! Work-around weird "is not clickable" errors because the PopMenu is still around :-/
time.sleep( 0.25 )
def new_scenario():
"""Reset the scenario."""
select_menu_option( "new_scenario" )
# check if the webapp is asking for confirmation
if find_child( "#ask" ):
# yup - make it so
click_dialog_button( "OK" )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def load_scenario_params( params ):
@ -275,6 +283,8 @@ def set_stored_msg( msg_type, val ):
def set_stored_msg_marker( msg_type ):
"""Store marker text in the message buffer (so we can tell if the front-end changes it)."""
# NOTE: Care should taken when using this function with "_clipboard_",
# since the tests might be using the real clipboard!
marker = "marker:{}:{}".format( msg_type, uuid.uuid4() )
set_stored_msg( msg_type, marker )
return marker
@ -316,10 +326,13 @@ def _do_select_droplist( sel, val ):
elem = find_child( "#{}-button .ui-selectmenu-icon".format( sel_id ) )
elem.click()
# select the requested option (nb: clicking on the child option doesn't work :shrug:)
elem = find_child( "#{}-button".format( sel_id ) )
elem.send_keys( val )
elem.send_keys( Keys.RETURN )
# select the requested option
elems = [
e for e in find_children( "#{}-menu.ui-menu .ui-menu-item-wrapper".format( sel_id ) )
if e.text == val
]
assert len(elems) == 1
ActionChains(_webdriver).click( elems[0] ).perform()
def get_droplist_vals_index( sel ):
"""Get the value/text for each option in a droplist."""
@ -392,6 +405,20 @@ def wait_for_elem( timeout, elem_id, parent=None ):
wait_for( timeout, check_elem )
return args["elem"]
def wait_for_clipboard( timeout, expected, contains=False ):
"""Wait for the clipboard to hold an expected value."""
args = { "last-clipboard": "" }
def check_clipboard(): #pylint: disable=missing-docstring
args["last-clipboard"] = get_clipboard()
return expected in args["last-clipboard"] if contains else expected == args["last-clipboard"]
try:
wait_for( timeout, check_clipboard )
except AssertionError:
print( "Timed out waiting for the clipboard:" )
print( "- Expecting:", expected )
print( "- Got:", args["last-clipboard"] )
raise
# ---------------------------------------------------------------------
_IE_HTML_TAGS = [ "<i>" ]

Loading…
Cancel
Save