Use V/O ID's to figure out which vehicles/ordnance have already been added to a player's OB.

master
Pacman Ghost 6 years ago
parent 2609ce1357
commit 7aa523310a
  1. 25
      vasl_templates/webapp/static/vo.js
  2. 12
      vasl_templates/webapp/tests/fixtures/data/ordnance/american.json
  3. 9
      vasl_templates/webapp/tests/fixtures/data/ordnance/german.json
  4. 9
      vasl_templates/webapp/tests/fixtures/data/ordnance/russian.json
  5. 6
      vasl_templates/webapp/tests/fixtures/data/vehicles/american.json
  6. 9
      vasl_templates/webapp/tests/fixtures/data/vehicles/german.json
  7. 15
      vasl_templates/webapp/tests/fixtures/data/vehicles/russian.json
  8. 60
      vasl_templates/webapp/tests/test_vehicles_ordnance.py

@ -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( "<option value='" + i + "'>" + entries[i].name + "</option>" ) ;
}
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 = ["<div class='" + div_class + "'>",
"<img src='" + _get_vo_image_url(entries[opt.id]) + "'>",
opt.text,
entries[opt.id].type ? "&nbsp;<span class='vo-type'>("+entries[opt.id].type+")</span>" : "",
"<img src='" + _get_vo_image_url(vo_entry) + "'>",
vo_entry.name,
vo_entry.type ? "&nbsp;<span class='vo-type'>("+vo_entry.type+")</span>" : "",
"</div>"
] ;
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 = "<div" ;
var fixed_height = 3.25 * gEmSize ;
if ( is_small_vasl_piece( entry ) ) {
if ( is_small_vasl_piece( vo_entry ) ) {
div_tag += " class='small-piece'" ;
fixed_height = 2.25 * gEmSize ;
}
div_tag += ">" ;
$sortable2.sortable2( "add", {
content: $( div_tag + "<img src='"+_get_vo_image_url(entry)+"'>" + entry.name + "</div>" ),
data: { caption: entry.name, vo_entry: entry, fixed_height: fixed_height },
content: $( div_tag + "<img src='"+_get_vo_image_url(vo_entry)+"'>" + vo_entry.name + "</div>" ),
data: { caption: vo_entry.name, vo_entry: vo_entry, fixed_height: fixed_height },
} ) ;
}

@ -4,27 +4,31 @@
"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" ]
"notes": [ "C\u2020<sup>1</sup>", "N" ],
"_id_": "am/o:013"
},
{ "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>" ]
"notes": [ "C\u2020<sup>1</sup>" ],
"_id_": "am/o:014"
},
{ "name": "M3A1 37mm AT Gun",
"capabilities": [ "NT", "QSU" ],
"capabilities2": { "C": [ [7,"A2+"], "\u2020<sup>1</sup>" ] },
"note_number": "6\u2020",
"notes": [ "C\u2020<sup>1</sup>", "N" ]
"notes": [ "C\u2020<sup>1</sup>", "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"
}
]

@ -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"
}
]

@ -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"
}
]

@ -4,13 +4,15 @@
"CS#": 7,
"capabilities2": { "A": [ [5,"A4E"], [6,"5E"], "\u2020<sup>1</sup>" ], "s": [ [5,5] ], "sP": 5 },
"note_number": "23\u2020",
"notes": [ "A\u2020<sup>1</sup>", "N", "Y" ]
"notes": [ "A\u2020<sup>1</sup>", "N", "Y" ],
"_id_": "am/v:024"
},
{ "name": "M18 GMC",
"CS#": 6,
"capabilities2": { "A": [ [5,"4E"], [6,"5E"], "\u2020<sup>1</sup>" ], "s": [ [5,5] ], "sP": 5 },
"note_number": "24\u2020",
"notes": [ "A\u2020<sup>1</sup>" ]
"notes": [ "A\u2020<sup>1</sup>" ],
"_id_": "am/v:025"
}
]

@ -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"
}
]

@ -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\u2020<sup>1</sup>", "LL" ]
"notes": [ "N", "O", "R\u2020<sup>1</sup>", "LL" ],
"_id_": "ru/v:076"
}
]

@ -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."""

Loading…
Cancel
Save