From 7aa523310a05d5ff75251f7c34d547a04440569a Mon Sep 17 00:00:00 2001 From: Taka Date: Sat, 29 Sep 2018 14:14:08 +0000 Subject: [PATCH] Use V/O ID's to figure out which vehicles/ordnance have already been added to a player's OB. --- vasl_templates/webapp/static/vo.js | 25 ++++---- .../fixtures/data/ordnance/american.json | 12 ++-- .../tests/fixtures/data/ordnance/german.json | 9 ++- .../tests/fixtures/data/ordnance/russian.json | 9 ++- .../fixtures/data/vehicles/american.json | 6 +- .../tests/fixtures/data/vehicles/german.json | 9 ++- .../tests/fixtures/data/vehicles/russian.json | 15 +++-- .../webapp/tests/test_vehicles_ordnance.py | 60 +++++++++++++++++++ 8 files changed, 113 insertions(+), 32 deletions(-) diff --git a/vasl_templates/webapp/static/vo.js b/vasl_templates/webapp/static/vo.js index aa16916..1485636 100644 --- a/vasl_templates/webapp/static/vo.js +++ b/vasl_templates/webapp/static/vo.js @@ -7,8 +7,9 @@ function add_vo( vo_type, player_no ) var $sortable2 = $( "#ob_" + vo_type + "-sortable_" + player_no ) ; var vo_present = []; $sortable2.children("li").each( function() { - vo_present.push( $(this).text() ) ; - } ); + var vo_entry = $(this).data( "sortable2-data" ).vo_entry ; + vo_present.push( vo_entry._id_ ) ; + } ) ; // load the available vehicles/ordnance var nat = $( "select[name='PLAYER_" + player_no + "']" ).val() ; @@ -19,21 +20,21 @@ function add_vo( vo_type, player_no ) } var buf = [] ; for ( var i=0 ; i < entries.length ; ++i ) { - if ( vo_present.indexOf( entries[i].name ) !== -1 ) + if ( vo_present.indexOf( entries[i]._id_ ) !== -1 ) continue ; - // TODO: It'd be nice to be able to use HTML in the option text (e.g. PzKpfw IVF 1/2) buf.push( "" ) ; } function format_vo_entry( opt ) { if ( ! opt.id ) return opt.text ; + var vo_entry = entries[opt.id] ; var div_class = "vo-entry" ; - if ( is_small_vasl_piece( entries[opt.id] ) ) + if ( is_small_vasl_piece( vo_entry ) ) div_class += " small-piece" ; var buf2 = ["
", - "", - opt.text, - entries[opt.id].type ? " ("+entries[opt.id].type+")" : "", + "", + vo_entry.name, + vo_entry.type ? " ("+vo_entry.type+")" : "", "
" ] ; return $( buf2.join("") ) ; @@ -99,7 +100,7 @@ function add_vo( vo_type, player_no ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function do_add_vo( vo_type, player_no, entry ) +function do_add_vo( vo_type, player_no, vo_entry ) { // add the specified vehicle/ordnance // NOTE: We set a fixed height for the sortable2 entries (based on the CSS settings in tabs-ob.css), @@ -107,14 +108,14 @@ function do_add_vo( vo_type, player_no, entry ) var $sortable2 = $( "#ob_" + vo_type + "-sortable_" + player_no ) ; var div_tag = "" + entry.name + "" ), - data: { caption: entry.name, vo_entry: entry, fixed_height: fixed_height }, + content: $( div_tag + "" + vo_entry.name + "" ), + data: { caption: vo_entry.name, vo_entry: vo_entry, fixed_height: fixed_height }, } ) ; } diff --git a/vasl_templates/webapp/tests/fixtures/data/ordnance/american.json b/vasl_templates/webapp/tests/fixtures/data/ordnance/american.json index b5190d0..53a7cf2 100644 --- a/vasl_templates/webapp/tests/fixtures/data/ordnance/american.json +++ b/vasl_templates/webapp/tests/fixtures/data/ordnance/american.json @@ -4,27 +4,31 @@ "capabilities": [ "NT" ], "capabilities2": { "H": 6, "s": 7, "WP": 8, "C": [ [7,"4+P"], "\u20201" ] }, "note_number": "14\u2020", - "notes": [ "C\u20201", "N" ] + "notes": [ "C\u20201", "N" ], + "_id_": "am/o:013" }, { "name": "M3 105mm Howitzer", "capabilities": [ "NT" ], "capabilities2": { "H": 7, "s": 7, "WP": 8, "C": [ [7,"P"], "\u20201" ] }, "note_number": "15\u2020", - "notes": [ "C\u20201" ] + "notes": [ "C\u20201" ], + "_id_": "am/o:014" }, { "name": "M3A1 37mm AT Gun", "capabilities": [ "NT", "QSU" ], "capabilities2": { "C": [ [7,"A2+"], "\u20201" ] }, "note_number": "6\u2020", - "notes": [ "C\u20201", "N" ] + "notes": [ "C\u20201", "N" ], + "_id_": "am/o:005" }, { "name": "M1 57mm AT Gun", "capabilities": [ "NT", "QSU" ], "capabilities2": { "HE": [ [7,"J4E"], [7,5], "\u2020" ], "D": [ [4,"J4+E"], "\u2020" ] }, - "note_number": "7\u2020" + "note_number": "7\u2020", + "_id_": "am/o:006" } ] diff --git a/vasl_templates/webapp/tests/fixtures/data/ordnance/german.json b/vasl_templates/webapp/tests/fixtures/data/ordnance/german.json index 10bec0c..3f29a4b 100644 --- a/vasl_templates/webapp/tests/fixtures/data/ordnance/german.json +++ b/vasl_templates/webapp/tests/fixtures/data/ordnance/german.json @@ -5,13 +5,16 @@ "capabilities2": { "A": 1, "H": 2 }, "capabilities_other": [ "can do other stuff" ], "note_number": "1", - "notes": [ "A", "B\u2020" ] + "notes": [ "A", "B\u2020" ], + "_id_": "ge/o:990" }, { "name": "another german ordnance", "capabilities": [ "QSU" ], - "note_number": "2" + "note_number": "2", + "_id_": "ge/o:991" }, -{ "name": "name only" +{ "name": "name only", + "_id_": "ge/o:992" } ] diff --git a/vasl_templates/webapp/tests/fixtures/data/ordnance/russian.json b/vasl_templates/webapp/tests/fixtures/data/ordnance/russian.json index faa4cba..13d1631 100644 --- a/vasl_templates/webapp/tests/fixtures/data/ordnance/russian.json +++ b/vasl_templates/webapp/tests/fixtures/data/ordnance/russian.json @@ -5,13 +5,16 @@ "capabilities2": { "s": 1, "sN": 2 }, "capabilities_other": [ "twerking" ], "note_number": "1", - "notes": [ "X", "Y\u2020" ] + "notes": [ "X", "Y\u2020" ], + "_id_": "ru/o:990" }, { "name": "another russian ordnance", "capabilities": [ "RFNM" ], - "note_number": "2" + "note_number": "2", + "_id_": "ru/o:991" }, -{ "name": "name only" +{ "name": "name only", + "_id_": "ru/o:992" } ] diff --git a/vasl_templates/webapp/tests/fixtures/data/vehicles/american.json b/vasl_templates/webapp/tests/fixtures/data/vehicles/american.json index 1f475ac..c71484c 100644 --- a/vasl_templates/webapp/tests/fixtures/data/vehicles/american.json +++ b/vasl_templates/webapp/tests/fixtures/data/vehicles/american.json @@ -4,13 +4,15 @@ "CS#": 7, "capabilities2": { "A": [ [5,"A4E"], [6,"5E"], "\u20201" ], "s": [ [5,5] ], "sP": 5 }, "note_number": "23\u2020", - "notes": [ "A\u20201", "N", "Y" ] + "notes": [ "A\u20201", "N", "Y" ], + "_id_": "am/v:024" }, { "name": "M18 GMC", "CS#": 6, "capabilities2": { "A": [ [5,"4E"], [6,"5E"], "\u20201" ], "s": [ [5,5] ], "sP": 5 }, "note_number": "24\u2020", - "notes": [ "A\u20201" ] + "notes": [ "A\u20201" ], + "_id_": "am/v:025" } ] diff --git a/vasl_templates/webapp/tests/fixtures/data/vehicles/german.json b/vasl_templates/webapp/tests/fixtures/data/vehicles/german.json index 428af63..9cf08e5 100644 --- a/vasl_templates/webapp/tests/fixtures/data/vehicles/german.json +++ b/vasl_templates/webapp/tests/fixtures/data/vehicles/german.json @@ -6,14 +6,17 @@ "capabilities_other": [ "can do other stuff" ], "CS#": 5, "note_number": "1", - "notes": [ "A", "B\u2020" ] + "notes": [ "A", "B\u2020" ], + "_id_": "ge/v:990" }, { "name": "another german vehicle", "capabilities": [ "QSU" ], "cs#": "4:brewup", - "note_number": "2" + "note_number": "2", + "_id_": "ge/v:991" }, -{ "name": "name only" +{ "name": "name only", + "_id_": "ge/v:992" } ] diff --git a/vasl_templates/webapp/tests/fixtures/data/vehicles/russian.json b/vasl_templates/webapp/tests/fixtures/data/vehicles/russian.json index 7ce190a..86772f6 100644 --- a/vasl_templates/webapp/tests/fixtures/data/vehicles/russian.json +++ b/vasl_templates/webapp/tests/fixtures/data/vehicles/russian.json @@ -6,27 +6,32 @@ "capabilities_other": [ "twerking" ], "CS#": 3, "note_number": "1", - "notes": [ "X", "Y\u2020" ] + "notes": [ "X", "Y\u2020" ], + "_id_": "ru/v:990" }, { "name": "another russian vehicle", "capabilities": [ "RFNM" ], "cs#": 4, - "note_number": "2" + "note_number": "2", + "_id_": "ru/v:991" }, -{ "name": "name only" +{ "name": "name only", + "_id_": "ru/v:992" }, { "name": "Churchill III(b)", "CS#": 7, "capabilities2": { "D": [ [6,"J4"], [7,5], "\u2020" ], "HE": [ [7,"F3"], [8,"4+"], "\u2020" ], "sD": [ [6,"4+"] ], "sM": "8\u2020" }, "note_number": "53\u2020", - "notes": [ "N", "LL" ] + "notes": [ "N", "LL" ], + "_id_": "ru/v:081" }, { "name": "Sherman III(a)", "CS#": "5:brewup", "capabilities2": { "s": 8, "WP": [ [6,"J4+"], "\u2020" ] }, "note_number": "50\u2020", - "notes": [ "N", "O", "R\u20201", "LL" ] + "notes": [ "N", "O", "R\u20201", "LL" ], + "_id_": "ru/v:076" } ] diff --git a/vasl_templates/webapp/tests/test_vehicles_ordnance.py b/vasl_templates/webapp/tests/test_vehicles_ordnance.py index b3105ab..3d23bc4 100644 --- a/vasl_templates/webapp/tests/test_vehicles_ordnance.py +++ b/vasl_templates/webapp/tests/test_vehicles_ordnance.py @@ -3,10 +3,12 @@ import re from selenium.webdriver.common.action_chains import ActionChains +from selenium.webdriver.common.keys import Keys from vasl_templates.webapp.tests.utils import \ init_webapp, select_tab, set_template_params, find_child, find_children, \ wait_for_clipboard, click_dialog_button +from vasl_templates.webapp.config.constants import DATA_DIR as REAL_DATA_DIR # --------------------------------------------------------------------- @@ -211,6 +213,64 @@ def test_variable_capabilities( webapp, webdriver ): # --------------------------------------------------------------------- +def test_html_names( webapp, webdriver, monkeypatch ): + """Test handling of vehicles/ordnance that have HTML in their name.""" + + # initialize + monkeypatch.setitem( webapp.config, "DATA_DIR", REAL_DATA_DIR ) + init_webapp( webapp, webdriver ) + + def get_available_ivfs(): + """Get the PzKw IVF's available for selection.""" + entries = find_children( "#select-vo .select2-results li" ) + entries = [ e.text for e in entries ] + return [ e for e in entries if "IVF" in e ] + + # start to add a vehicle - make sure the two PzKw IVF's are available + select_tab( "ob{}".format( 1 ) ) + add_vehicle_btn = find_child( "#ob_vehicles-add_1" ) + add_vehicle_btn.click() + assert get_available_ivfs() == [ "PzKpfw IVF\n1\n (MT)", "PzKpfw IVF\n2\n (MT)" ] + + # add the PzKw IVF2 + elem = find_child( ".ui-dialog .select2-search__field" ) + elem.send_keys( "IVF2" ) + elem.send_keys( Keys.RETURN ) + + # make sure it was added to the player's OB + entries = find_children( "#ob_vehicles-sortable_1 li" ) + entries = [ e.text for e in entries ] + assert entries == [ "PzKpfw IVF2" ] + + # start to add another vehicle - make sure only the PzKw IVF1 is present + add_vehicle_btn.click() + assert get_available_ivfs() == [ "PzKpfw IVF\n1\n (MT)" ] + + # add the PzKw IVF1 + elem = find_child( ".ui-dialog .select2-search__field" ) + elem.send_keys( "IVF1" ) + elem.send_keys( Keys.RETURN ) + + # make sure it was added to the player's OB + entries = find_children( "#ob_vehicles-sortable_1 li" ) + entries = [ e.text for e in entries ] + assert entries == [ "PzKpfw IVF2", "PzKpfw IVF1" ] + + # start to add another vehicle - make sure there are no PzKw IVF's present + add_vehicle_btn.click() + assert not get_available_ivfs() + elem = find_child( ".ui-dialog .select2-search__field" ) + elem.send_keys( Keys.ESCAPE ) + + # delete the PzKw IVF2 + delete_vo( "vehicles", 1, "PzKpfw IVF2" , webdriver ) + + # start to add another vehicle - make sure the PzKw IVF2 is available again + add_vehicle_btn.click() + assert get_available_ivfs() == [ "PzKpfw IVF\n2\n (MT)" ] + +# --------------------------------------------------------------------- + def add_vo( webdriver, vo_type, player_no, name ): """Add a vehicle/ordnance."""