From 187faa112b45529772702ca55db2d01a4a1ffec7 Mon Sep 17 00:00:00 2001 From: Taka Date: Mon, 6 May 2019 14:26:13 +0000 Subject: [PATCH] Added an extras template to generate snippets for Victory Points. --- .../extras/victory-points.j2 | 7 +++ vasl_templates/webapp/static/extras.js | 48 +++++++++++++------ .../default-template-pack/extras/droplist.j2 | 3 ++ .../webapp/tests/test_extras_templates.py | 37 ++++++++++++-- 4 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 vasl_templates/webapp/data/default-template-pack/extras/victory-points.j2 create mode 100644 vasl_templates/webapp/tests/fixtures/data/default-template-pack/extras/droplist.j2 diff --git a/vasl_templates/webapp/data/default-template-pack/extras/victory-points.j2 b/vasl_templates/webapp/data/default-template-pack/extras/victory-points.j2 new file mode 100644 index 0000000..55f79ee --- /dev/null +++ b/vasl_templates/webapp/data/default-template-pack/extras/victory-points.j2 @@ -0,0 +1,7 @@ + + + + + + +
{{TYPE:Victory Points::Casualty VP::Exit VP|Type}}: 0 diff --git a/vasl_templates/webapp/static/extras.js b/vasl_templates/webapp/static/extras.js index d8a623e..fa6f4c4 100644 --- a/vasl_templates/webapp/static/extras.js +++ b/vasl_templates/webapp/static/extras.js @@ -76,20 +76,29 @@ function _show_extra_template( template_id ) buf.push( "" ) ; var display_name = template_info.params[i].caption || template_info.params[i].name ; buf.push( "", escapeHTML(display_name)+":" ) ; - buf.push( "", "" ) ; + buf.push( "" ) ; + if ( template_info.params[i].type === "input" ) { + buf.push( "" ) ; + } else if ( template_info.params[i].type === "select" ) { + buf.push( "" ) ; + } } buf.push( "" ) ; } buf.push( "" ) ; buf.push( "
" ) ; var $form = $( buf.join("") ) ; + $form.find( "select" ).select2( { minimumResultsForSearch: -1 } ) ; fixup_external_links( $form ) ; // initialize the "generate" button @@ -124,13 +133,24 @@ function _parse_extra_template( template_id, template ) var pos = param.name.indexOf( ":" ) ; if ( pos === -1 ) continue ; - param.default = param.name.substr( pos+1 ) ; + var val = param.name.substr( pos+1 ) ; param.name = param.name.substr( 0, pos ) ; - // extract the field width - pos = param.default.indexOf( "/" ) ; - if ( pos !== -1 ) { - param.width = param.default.substr( pos+1 ) ; - param.default = param.default.substr( 0, pos ) ; + // figure out what type of parameter we have + if ( val.indexOf( "::" ) !== -1 ) { + // we have a + param.type = "input" ; + // extract the default value and field width + pos = val.indexOf( "/" ) ; + if ( pos === -1 ) + param.default = val ; + else { + param.default = val.substr( 0, pos ) ; + param.width = val.substr( pos+1 ) ; + } } // extract the caption and description if ( words.length >= 2 ) diff --git a/vasl_templates/webapp/tests/fixtures/data/default-template-pack/extras/droplist.j2 b/vasl_templates/webapp/tests/fixtures/data/default-template-pack/extras/droplist.j2 new file mode 100644 index 0000000..2bda330 --- /dev/null +++ b/vasl_templates/webapp/tests/fixtures/data/default-template-pack/extras/droplist.j2 @@ -0,0 +1,3 @@ + + +Selected: {{DROPLIST:item 1::item 2::item 3|Value}} diff --git a/vasl_templates/webapp/tests/test_extras_templates.py b/vasl_templates/webapp/tests/test_extras_templates.py index 2af8eab..7706be9 100644 --- a/vasl_templates/webapp/tests/test_extras_templates.py +++ b/vasl_templates/webapp/tests/test_extras_templates.py @@ -1,9 +1,10 @@ """ Test the extras templates. """ +from selenium.webdriver.support.ui import Select from selenium.webdriver.common.keys import Keys -from vasl_templates.webapp.tests.utils import \ - init_webapp, find_child, find_children, wait_for, wait_for_clipboard, select_tab +from vasl_templates.webapp.tests.utils import init_webapp, select_tab, get_droplist_vals, select_droplist_val, \ + find_child, find_children, wait_for, wait_for_clipboard from vasl_templates.webapp.tests.test_template_packs import make_zip_from_files, upload_template_pack_zip # --------------------------------------------------------------------- @@ -18,7 +19,8 @@ def test_extras_templates( webapp, webdriver ): # check that the extras templates were loaded correctly assert _get_extras_template_index() == [ ( "extras/minimal", None ), - ( "Full template", "This is the caption." ) + ( "Full template", "This is the caption." ), + ( "select", None ), ] # check that the "full" template was loaded correctly @@ -60,6 +62,31 @@ def test_extras_templates( webapp, webdriver ): # --------------------------------------------------------------------- +def test_droplists( webapp, webdriver ): + """Test droplist's in extras templates.""" + + # initialize + init_webapp( webapp, webdriver ) + select_tab( "extras" ) + + # load the "droplist" template + _select_extras_template( webdriver, "extras/droplist" ) + content = find_child( "#tabs-extras .right-panel" ) + params = find_children( "tr", content ) + assert len(params) == 1 + sel = Select( find_child( "td.value select", params[0] ) ) + vals = get_droplist_vals( sel ) + assert vals == [ ("item 1","item 1"), ("item 2","item 2"), ("item 3","item 3") ] + + # generate the snippet for each droplist choice + for i in range(1,3+1): + select_droplist_val( sel, "item {}".format(i) ) + snippet_btn = find_child( "button.generate", content ) + snippet_btn.click() + wait_for_clipboard( 2, "Selected: item {}".format(i) ) + +# --------------------------------------------------------------------- + def test_template_pack( webapp, webdriver ): """Test uploading a template pack that contains extras templates.""" @@ -70,7 +97,8 @@ def test_template_pack( webapp, webdriver ): # check that the extras templates were loaded correctly assert _get_extras_template_index() == [ ( "extras/minimal", None ), - ( "Full template", "This is the caption." ) + ( "Full template", "This is the caption." ), + ( "select", None ), ] # upload the template pack @@ -82,6 +110,7 @@ def test_template_pack( webapp, webdriver ): ( "extras/minimal", None ), ( "Full template (modified)", "This is the caption (modified)." ), ( "New template", None ), + ( "select", None ), ] # check that the modified "full" template is being used