From 1151ba606e68c36f75172b99af66d59c7a3d512c Mon Sep 17 00:00:00 2001 From: Taka Date: Mon, 28 Jan 2019 16:21:55 +0000 Subject: [PATCH] Remove duplicate multi-applicable notes. --- vasl_templates/webapp/static/snippets.js | 25 +++++- .../webapp/tests/test_vasl_extensions.py | 77 ++++++++++++++++--- 2 files changed, 92 insertions(+), 10 deletions(-) diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 8f32dff..f69c9e3 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -489,8 +489,31 @@ function get_ma_notes_keys( nat, vo_entries, vo_type ) } } + // delete duplicate keys e.g. if we have notes "X" and "Fr X", we want to include "X" but not "Fr X" + // *if* the player is French, otherwise we want to include both. + var keys0 = sort_ma_notes_keys( nat, Object.keys(keys[0]) ) ; + var keys0a = null ; + if ( keys0 ) { + var std_keys = {} ; + for ( i=0 ; i < keys0.length ; ++i ) { + if ( keys0[i].match( /^[A-Za-z]{1,2}$/ ) ) + std_keys[ keys0[i] ] = true ; + } + keys0a = [] ; + for ( i=0 ; i < keys0.length ; ++i ) { + var pos = keys0[i].indexOf( ":" ) ; + if ( pos > 0 ) { + var val = keys0[i].substr( pos+1 ) ; + pos = val.indexOf( " " ) ; + if ( BFP_MA_NOTE_REDIRECTS[ val.substr(0,pos) ] == nat && val.substr(pos+1) in std_keys ) + continue ; + } + keys0a.push( keys0[i] ) ; + } + } + return [ - sort_ma_notes_keys( nat, Object.keys(keys[0]) ), + keys0a, sort_ma_notes_keys( nat, Object.keys(keys[1]) ), extra_notes_info[0], extra_notes_info[1], unrecognized diff --git a/vasl_templates/webapp/tests/test_vasl_extensions.py b/vasl_templates/webapp/tests/test_vasl_extensions.py index 6b7731c..d54fc29 100644 --- a/vasl_templates/webapp/tests/test_vasl_extensions.py +++ b/vasl_templates/webapp/tests/test_vasl_extensions.py @@ -10,7 +10,7 @@ from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from vasl_templates.webapp.utils import TempFile -from vasl_templates.webapp.tests.utils import init_webapp, set_player, select_tab, \ +from vasl_templates.webapp.tests.utils import init_webapp, set_player, select_tab, new_scenario, \ find_child, find_children, wait_for_clipboard from vasl_templates.webapp.tests.test_scenario_persistence import load_scenario from vasl_templates.webapp.tests.test_vehicles_ordnance import add_vo @@ -90,6 +90,73 @@ def test_vasl_extension_info( webapp, webdriver ): # --------------------------------------------------------------------- +@pytest.mark.skipif( + not pytest.config.option.vasl_extensions, #pylint: disable=no-member + reason = "--vasl-extensions not specified" +) +def test_dedupe_ma_notes( webapp, webdriver ): + """Test deduping multi-applicable notes.""" + + # initialize + init_webapp( webapp, webdriver, + reset = lambda ct: + ct.set_data_dir( dtype="real" ) \ + .set_vasl_mod( vmod="random", extns_dtype="real" ) \ + .set_vo_notes_dir( dtype="real" ) + ) + + def do_test( vehicles, expected ): #pylint: disable=missing-docstring + # add the specified vehicles + new_scenario() + set_player( 1, "japanese" ) + for veh in vehicles: + add_vo( webdriver, "vehicles", 1, veh ) + # get the multi-applicable notes + btn = find_child( "button.generate[data-id='ob_vehicles_ma_notes_1']" ) + btn.click() + wait_for_clipboard( 2, expected, transform=_extract_extn_ma_notes ) + + # NOTE: The vehicles used in this test have the following multi-applicable notes: + # - Type 92A: A + # - M3(a): adf:A ; adf:B ; adf:C ; adf:Jp A ; adf:US B + # - Type 98 MCT: adf:Br H ; adf:Ge A + + # do the tests + do_test( [ "Type 92A (Tt)", "M3(a) (LT)" ], [ + ( False, "A", "The MA and alland alland alland all