Added an option to hide unavailable multi-applicable notes.

master
Pacman Ghost 5 years ago
parent 5c0136030e
commit 914e65ed3b
  1. 2
      vasl_templates/webapp/static/snippets.js
  2. 3
      vasl_templates/webapp/static/user_settings.js
  3. 4
      vasl_templates/webapp/templates/user-settings-dialog.html
  4. 4
      vasl_templates/webapp/tests/fixtures/data/vehicles/german.json
  5. 53
      vasl_templates/webapp/tests/test_user_settings.py
  6. 22
      vasl_templates/webapp/tests/test_vo_notes.py

@ -194,6 +194,8 @@ function make_snippet( $btn, params, extra_params, show_date_warnings )
key = key.substring( pos+1 ) ;
}
}
if ( ! ma_note && gUserSettings["hide-unavailable-ma-notes"] )
continue ;
params[ param_name ].push(
extn_marker +
"<span class='key'>" + key + ":" + "</span> " +

@ -2,6 +2,7 @@ gUserSettings = Cookies.getJSON( "user-settings" ) || {} ;
USER_SETTINGS = {
"date-format": "droplist",
"hide-unavailable-ma-notes": "checkbox",
"include-vasl-images-in-snippets": "checkbox",
"include-flags-in-snippets": "checkbox",
} ;
@ -43,7 +44,7 @@ function user_settings()
dialogClass: "user-settings",
modal: true,
width: 440,
height: 250,
height: 270,
resizable: false,
create: function() {
init_dialog( $(this), "OK", true ) ;

@ -7,6 +7,10 @@
<option value="yy-mm-dd">YYYY-MM-DD</option>
</select>
<div style="margin-top:0.5em;">
<input type="checkbox" name="hide-unavailable-ma-notes">&nbsp;Hide unavailable multi-applicable notes <br>
</div>
<fieldset> <legend> Provide services to VASL </legend>
<div class="run-as-server-note">
<img src="{{url_for('static',filename='images/info.gif')}}">

@ -26,6 +26,10 @@
"comments": [ "a comment", "another comment" ],
"id": "ge/v:993"
},
{ "name": "missing multi-applicable note",
"notes": [ "A", "Q" ],
"id": "ge/v:994"
},
{ "name": "name only",
"id": "ge/v:999"
}

@ -11,6 +11,7 @@ from vasl_templates.webapp.tests.utils import \
from vasl_templates.webapp.tests.test_vehicles_ordnance import add_vo
from vasl_templates.webapp.tests.test_scenario_persistence import save_scenario, load_scenario
from vasl_templates.webapp.tests.test_template_packs import upload_template_pack_file
from vasl_templates.webapp.tests.test_vo_notes import extract_ma_notes
# ---------------------------------------------------------------------
@ -178,6 +179,58 @@ def test_date_format( webapp, webdriver ):
# ---------------------------------------------------------------------
def test_hide_unavailable_ma_notes( webapp, webdriver ):
"""Test showing/hiding unavailable multi-applicable notes."""
# initialize
init_webapp( webapp, webdriver, scenario_persistence=1,
reset = lambda ct: ct.set_vo_notes_dir( dtype="test" )
)
# load the test vehicle
load_scenario( {
"PLAYER_1": "german",
"OB_VEHICLES_1": [
{ "name": "missing multi-applicable note" }
]
} )
select_tab( "ob1" )
def test_ma_notes( ma_note_q_present ): #pylint: disable=missing-docstring
expected = [ ( "A", 'German Multi-Applicable Vehicle Note "A".' ) ]
if ma_note_q_present:
expected.append( ( "Q", "Unavailable." ) )
btn = find_child( "button[data-id='ob_vehicles_ma_notes_1']" )
btn.click()
wait_for_clipboard( 2, expected, transform=extract_ma_notes )
# generate the multi-applicable notes
test_ma_notes( True )
# enable "hide unavailable multi-applicable notes"
select_menu_option( "user_settings" )
elem = find_child( ".ui-dialog.user-settings input[name='hide-unavailable-ma-notes']" )
assert not elem.is_selected()
elem.click()
click_dialog_button( "OK" )
_check_cookies( webdriver, "hide-unavailable-ma-notes", True )
# generate the multi-applicable notes
test_ma_notes( False )
# disable "hide unavailable multi-applicable notes"
select_menu_option( "user_settings" )
elem = find_child( ".ui-dialog.user-settings input[name='hide-unavailable-ma-notes']" )
assert elem.is_selected()
elem.click()
click_dialog_button( "OK" )
_check_cookies( webdriver, "hide-unavailable-ma-notes", False )
# generate the multi-applicable notes
test_ma_notes( True )
# ---------------------------------------------------------------------
def _check_cookies( webdriver, name, expected ):
"""Check that a user setting was stored in the cookies correctly."""
cookies = [ c for c in webdriver.get_cookies() if c["name"] == "user-settings" ]

@ -74,7 +74,7 @@ def test_ma_notes( webapp, webdriver ):
"button.generate[data-id='ob_{}_ma_notes_{}']".format( vo_type, player_no )
)
btn.click()
wait_for_clipboard( 2, expected, transform=_extract_ma_note_keys )
wait_for_clipboard( 2, expected, transform=extract_ma_note_keys )
# test multi-applicable notes for German vehicles
do_test( 1, "german", "vehicles",
@ -175,13 +175,13 @@ def test_extra_ma_notes( webapp, webdriver ):
wait_for_clipboard( 2, [
( "A", 'Dutch Multi-Applicable Vehicle Note "A".' ),
( "Du", 'Allied Minor Multi-Applicable Vehicle Note "Du".' ),
], transform=_extract_ma_notes )
], transform=extract_ma_notes )
btn = find_child( "button.generate[data-id='ob_ordnance_ma_notes_1']" )
btn.click()
wait_for_clipboard( 2, [
( "A", 'Dutch Multi-Applicable Ordnance Note "A".' ),
( "Du", 'Allied Minor Multi-Applicable Ordnance Note "Du".' ),
], transform=_extract_ma_notes )
], transform=extract_ma_notes )
# test Axis Minor vehicles/ordnance
select_tab( "ob2" )
@ -190,13 +190,13 @@ def test_extra_ma_notes( webapp, webdriver ):
wait_for_clipboard( 2, [
( "A", 'Romanian Multi-Applicable Vehicle Note "A".' ),
( "Ro", 'Axis Minor Multi-Applicable Vehicle Note "Ro".' ),
], transform=_extract_ma_notes )
], transform=extract_ma_notes )
btn = find_child( "button.generate[data-id='ob_ordnance_ma_notes_2']" )
btn.click()
wait_for_clipboard( 2, [
( "A", 'Romanian Multi-Applicable Ordnance Note "A".' ),
( "Ro", 'Axis Minor Multi-Applicable Ordnance Note "Ro".' ),
], transform=_extract_ma_notes )
], transform=extract_ma_notes )
# test Landing Craft
load_scenario( {
@ -214,7 +214,7 @@ def test_extra_ma_notes( webapp, webdriver ):
( "Y", "Unavailable." ),
"Landing Craft",
( "A", 'Landing Craft Multi-Applicable Note "A".' ),
], transform=_extract_ma_notes )
], transform=extract_ma_notes )
select_tab( "ob2" )
btn = find_child( "button.generate[data-id='ob_vehicles_ma_notes_2']" )
btn.click()
@ -222,7 +222,7 @@ def test_extra_ma_notes( webapp, webdriver ):
( "A", 'Japanese Multi-Applicable Vehicle Note "A".' ),
"Landing Craft",
( "B", 'Landing Craft Multi-Applicable Note "B".' ),
], transform=_extract_ma_notes )
], transform=extract_ma_notes )
# ---------------------------------------------------------------------
@ -343,10 +343,10 @@ def test_special_cases( webapp, webdriver ):
select_tab( "ob1" )
btn = find_child( "button.generate[data-id='ob_ordnance_ma_notes_1']" )
btn.click()
wait_for_clipboard( 2, ["N","<s>R</s>"], transform=_extract_ma_note_keys )
wait_for_clipboard( 2, ["N","<s>R</s>"], transform=extract_ma_note_keys )
btn = find_child( "button.generate[data-id='ob_vehicles_ma_notes_1']" )
btn.click()
wait_for_clipboard( 2, ["N","R"], transform=_extract_ma_note_keys )
wait_for_clipboard( 2, ["N","R"], transform=extract_ma_note_keys )
# ---------------------------------------------------------------------
@ -511,12 +511,12 @@ def _parse_report( buf ):
# ---------------------------------------------------------------------
def _extract_ma_note_keys( snippet ):
def extract_ma_note_keys( snippet ):
"""Extract the multi-applicable note keys in a snippet."""
matches = re.finditer( r"<span class='key'>(.+):</span>", snippet )
return [ mo.group(1) for mo in matches ]
def _extract_ma_notes( snippet ):
def extract_ma_notes( snippet ):
"""Extract the multi-applicable notes in a snippet."""
mo = re.search( "=== ([^=]+) ===", snippet )
if mo:

Loading…
Cancel
Save