parent
e997caacf4
commit
040292279b
@ -0,0 +1,2 @@ |
|||||||
|
player1=[{{PLAYER_1}}] ; ELR=[{{PLAYER_1_ELR}}] ; SAN=[{{PLAYER_1_SAN}}] |
||||||
|
player2=[{{PLAYER_2}}] ; ELR=[{{PLAYER_2_ELR}}] ; SAN=[{{PLAYER_2_SAN}}] |
@ -0,0 +1,35 @@ |
|||||||
|
[ |
||||||
|
|
||||||
|
{ "display_name": "German", |
||||||
|
"ob_colors": [ "OBCOL:german", "OBCOL2:german" ] |
||||||
|
}, |
||||||
|
|
||||||
|
{ "display_name": "Russian", |
||||||
|
"ob_colors": [ "OBCOL:russian", "OBCOL2:russian" ] |
||||||
|
}, |
||||||
|
|
||||||
|
{ "display_name": "American", |
||||||
|
"ob_colors": [ "OBCOL:american", "OBCOL2:american" ] |
||||||
|
}, |
||||||
|
|
||||||
|
{ "display_name": "British", |
||||||
|
"ob_colors": [ "OBCOL:british", "OBCOL2:british" ] |
||||||
|
}, |
||||||
|
|
||||||
|
{ "display_name": "French", |
||||||
|
"ob_colors": [ "OBCOL:french", "OBCOL2:french" ] |
||||||
|
}, |
||||||
|
|
||||||
|
{ "display_name": "Italian", |
||||||
|
"ob_colors": [ "OBCOL:italian", "OBCOL2:italian" ] |
||||||
|
}, |
||||||
|
|
||||||
|
{ "display_name": "Finnish", |
||||||
|
"ob_colors": [ "OBCOL:finns", "OBCOL2:finns" ] |
||||||
|
}, |
||||||
|
|
||||||
|
{ "display_name": "Japanese", |
||||||
|
"ob_colors": [ "OBCOL:japanese", "OBCOL2:japanese" ] |
||||||
|
} |
||||||
|
|
||||||
|
] |
@ -0,0 +1,69 @@ |
|||||||
|
// NOTE: These fields aren't mandatory in the sense that snippet generation will fail
|
||||||
|
// if they're not set, but they're really, really, really expected to be there.
|
||||||
|
var _MANDATORY_PARAMS = { |
||||||
|
scenario: { "SCENARIO_NAME": "scenario name", "SCENARIO_DATE": "scenario date" }, |
||||||
|
} ; |
||||||
|
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
function generate_snippet( $btn ) |
||||||
|
{ |
||||||
|
// collect all the template parameters
|
||||||
|
var params = {} ; |
||||||
|
add_param = function($elem) { params[ $elem.attr("name").toUpperCase() ] = $elem.val() ; } ; |
||||||
|
$("input[type='text'].param").each( function() { add_param($(this)) ; } ) ; |
||||||
|
$("textarea.param").each( function() { add_param($(this)) ; } ) ; |
||||||
|
$("select.param").each( function() { add_param($(this)) ; } ) ; |
||||||
|
|
||||||
|
// check for mandatory parameters
|
||||||
|
var template_id = $btn.data( "id" ) ; |
||||||
|
if ( template_id in _MANDATORY_PARAMS ) { |
||||||
|
var missing_params = [] ; |
||||||
|
for ( var param_id in _MANDATORY_PARAMS[template_id] ) { |
||||||
|
if ( ! (param_id in params && params[param_id].length > 0) ) |
||||||
|
missing_params.push( _MANDATORY_PARAMS[template_id][param_id] ) ; |
||||||
|
} |
||||||
|
if ( missing_params.length > 0 ) { |
||||||
|
var buf = [ "Missing parameters:<ul>" ] ; |
||||||
|
for ( var i=0 ; i < missing_params.length ; ++i ) |
||||||
|
buf.push( "<li>" + escapeHTML(missing_params[i]) ) ; |
||||||
|
buf.push( "</ul>" ) ; |
||||||
|
showWarningMsg( buf.join("") ) ; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// check that the players have different nationalities
|
||||||
|
if ( params.PLAYER_1 === params.PLAYER_2 ) |
||||||
|
showWarningMsg( "Both players have the same nationality!" ) ; |
||||||
|
|
||||||
|
// get the template to generate the snippet from
|
||||||
|
if ( ! (template_id in gDefaultTemplates) ) { |
||||||
|
showErrorMsg( "Unknown template: " + escapeHTML(template_id) ) ; |
||||||
|
return ; |
||||||
|
} |
||||||
|
var func, val ; |
||||||
|
try { |
||||||
|
func = jinja.compile( gDefaultTemplates[template_id] ).render ; |
||||||
|
} |
||||||
|
catch( ex ) { |
||||||
|
showErrorMsg( "Can't compile template:<pre>" + escapeHTML(ex) + "</pre>" ) ; |
||||||
|
return ; |
||||||
|
} |
||||||
|
|
||||||
|
// process the template
|
||||||
|
try { |
||||||
|
val = func( params ) ; |
||||||
|
} |
||||||
|
catch( ex ) { |
||||||
|
showErrorMsg( "Can't process template <em>\"" + template_id + "\"</em>:<pre>" + escapeHTML(ex) + "</pre>" ) ; |
||||||
|
return ; |
||||||
|
} |
||||||
|
try { |
||||||
|
copyToClipboard( val ) ; |
||||||
|
} |
||||||
|
catch( ex ) { |
||||||
|
showErrorMsg( "Can't copy to the clipboard:<pre>" + escapeHTML(ex) + "</pre>" ) ; |
||||||
|
return ; |
||||||
|
} |
||||||
|
showInfoMsg( "The HTML snippet has been copied to the clipboard." ) ; |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
""" Test how players are handled. """ |
||||||
|
|
||||||
|
from selenium.webdriver.support.ui import Select |
||||||
|
|
||||||
|
from vasl_templates.webapp.tests.utils import get_nationalities, find_child |
||||||
|
|
||||||
|
# --------------------------------------------------------------------- |
||||||
|
|
||||||
|
def _get_player( webdriver, player_id ): |
||||||
|
"""Get the nationality of the specified player.""" |
||||||
|
sel = Select( |
||||||
|
find_child( webdriver, "select[name='player_{}']".format( player_id ) ) |
||||||
|
) |
||||||
|
return sel.first_selected_option.get_attribute( "value" ) |
||||||
|
|
||||||
|
# --------------------------------------------------------------------- |
||||||
|
|
||||||
|
def test_player_change( webapp, webdriver ): |
||||||
|
"""Test changing players.""" |
||||||
|
|
||||||
|
# initialize |
||||||
|
webdriver.get( webapp.url_for( "main" ) ) |
||||||
|
nationalities = get_nationalities( webapp ) |
||||||
|
|
||||||
|
# make sure that the UI was updated correctly for the initial players |
||||||
|
for player_no in [1,2]: |
||||||
|
player_id = _get_player( webdriver, player_no ) |
||||||
|
elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-ob{}']".format( player_no ) ) |
||||||
|
assert elem.text == "{} OB".format( nationalities[player_id]["display_name"] ) |
||||||
|
|
||||||
|
# change player 1 |
||||||
|
sel = Select( |
||||||
|
find_child( webdriver, "select[name='player_1']" ) |
||||||
|
) |
||||||
|
sel.select_by_value( "finnish" ) |
||||||
|
elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-ob1']" ) |
||||||
|
assert elem.text == "{} OB".format( nationalities["finnish"]["display_name"] ) |
||||||
|
|
||||||
|
# change player 2 |
||||||
|
sel = Select( |
||||||
|
find_child( webdriver, "select[name='player_2']" ) |
||||||
|
) |
||||||
|
sel.select_by_value( "japanese" ) |
||||||
|
elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-ob2']" ) |
||||||
|
assert elem.text == "{} OB".format( nationalities["japanese"]["display_name"] ) |
Loading…
Reference in new issue