diff --git a/vasl_templates/webapp/tests/fixtures/data/default-template-pack/scenario_note.j2 b/vasl_templates/webapp/tests/fixtures/data/default-template-pack/scenario_note.j2
new file mode 100644
index 0000000..3bb3777
--- /dev/null
+++ b/vasl_templates/webapp/tests/fixtures/data/default-template-pack/scenario_note.j2
@@ -0,0 +1 @@
+[{{SCENARIO_NOTE}}]{%if SCENARIO_NOTE_WIDTH%} (width=[{{SCENARIO_NOTE_WIDTH}}]){%endif%}
diff --git a/vasl_templates/webapp/tests/fixtures/template-packs/full/scenario_note.j2 b/vasl_templates/webapp/tests/fixtures/template-packs/full/scenario_note.j2
new file mode 100644
index 0000000..7da615d
--- /dev/null
+++ b/vasl_templates/webapp/tests/fixtures/template-packs/full/scenario_note.j2
@@ -0,0 +1 @@
+Customized SCENARIO_NOTE.
diff --git a/vasl_templates/webapp/tests/fixtures/template-packs/new-default/scenario_note.j2 b/vasl_templates/webapp/tests/fixtures/template-packs/new-default/scenario_note.j2
new file mode 100644
index 0000000..0576639
--- /dev/null
+++ b/vasl_templates/webapp/tests/fixtures/template-packs/new-default/scenario_note.j2
@@ -0,0 +1 @@
+New default SCENARIO_NOTE.
diff --git a/vasl_templates/webapp/tests/test_ob.py b/vasl_templates/webapp/tests/test_ob.py
index f27d56e..2ac7c64 100644
--- a/vasl_templates/webapp/tests/test_ob.py
+++ b/vasl_templates/webapp/tests/test_ob.py
@@ -65,9 +65,9 @@ def _do_test_ob_entries( webapp, webdriver, ob_type ):
return len(elems)
select_tab( "ob1" )
assert count_entries(1) == 2
- elem = find_child( "#{}-sortable_1 li[2]".format( ob_type ) )
+ elems = find_children( "#{}-sortable_1 li".format( ob_type ) )
trash = find_child( "#{}-trash_1".format( ob_type ) )
- ActionChains(webdriver).drag_and_drop( elem, trash ).perform()
+ ActionChains(webdriver).drag_and_drop( elems[1], trash ).perform()
assert count_entries(1) == 1
# delete an OB setup/note by emptying its caption
@@ -214,6 +214,7 @@ def edit_ob_setup( webdriver, player_id, entry_no, caption, width ):
def _do_edit_ob_entry( webdriver, player_id, ob_type, entry_no, caption, width ):
"""Edit an OB setup/note."""
+
# locate the requested entry and start editing it
if entry_no is not None:
select_tab( "ob{}".format( player_id ) )
diff --git a/vasl_templates/webapp/tests/test_scenario_persistence.py b/vasl_templates/webapp/tests/test_scenario_persistence.py
index 9aef60f..5cd878d 100644
--- a/vasl_templates/webapp/tests/test_scenario_persistence.py
+++ b/vasl_templates/webapp/tests/test_scenario_persistence.py
@@ -30,6 +30,7 @@ def test_scenario_persistence( webapp, webdriver ):
"PLAYER_1": "russian", "PLAYER_1_ELR": "1", "PLAYER_1_SAN": "2",
"PLAYER_2": "german", "PLAYER_2_ELR": "3", "PLAYER_2_SAN": "4",
"VICTORY_CONDITIONS": "just do it!", "VICTORY_CONDITIONS_WIDTH": "102",
+ "SCENARIO_NOTES": [ { "caption": "note #1", "width": "" }, { "caption": "note #2", "width": "100px" } ],
"SSR": [ "This is an SSR.", "This is another SSR." ],
"SSR_WIDTH": "103",
},
@@ -83,6 +84,8 @@ def test_scenario_persistence( webapp, webdriver ):
for tab_id in scenario_params:
select_tab( tab_id )
for field,val in scenario_params[tab_id].items():
+ if field == "SCENARIO_NOTES":
+ continue # nb: this requires special handling, we do it below
if field == "SSR":
continue # nb: this requires special handling, we do it below
if field in ("OB_SETUPS_1","OB_SETUPS_2"):
@@ -99,6 +102,9 @@ def test_scenario_persistence( webapp, webdriver ):
assert Select(elem).first_selected_option.get_attribute("value") == val
else:
assert elem.get_attribute("value") == val
+ select_tab( "scenario" )
+ scenario_notes = [ c.text for c in find_children("#scenario_notes-sortable li") ]
+ assert scenario_notes == [ sn["caption"] for sn in scenario_params["scenario"]["SCENARIO_NOTES"] ]
ssrs = _get_ssrs()
assert ssrs == scenario_params["scenario"]["SSR"]
assert _get_ob_entries("ob_setups",1) == [ obs["caption"] for obs in scenario_params["ob1"]["OB_SETUPS_1"] ]
diff --git a/vasl_templates/webapp/tests/test_snippets.py b/vasl_templates/webapp/tests/test_snippets.py
index 5832aa6..1395716 100644
--- a/vasl_templates/webapp/tests/test_snippets.py
+++ b/vasl_templates/webapp/tests/test_snippets.py
@@ -1,11 +1,12 @@
""" Test HTML snippet generation. """
from selenium.webdriver.common.keys import Keys
+from selenium.webdriver.common.action_chains import ActionChains
from vasl_templates.webapp.tests.test_ob import add_ob_setup, add_ob_note
from vasl_templates.webapp.tests.utils import select_tab, set_template_params, get_clipboard
-from vasl_templates.webapp.tests.utils import get_stored_msg, dismiss_notifications, find_child
-from vasl_templates.webapp.tests.utils import for_each_template, wait_for
+from vasl_templates.webapp.tests.utils import get_stored_msg, dismiss_notifications, find_child, find_children
+from vasl_templates.webapp.tests.utils import for_each_template, wait_for, click_dialog_button
# ---------------------------------------------------------------------
@@ -93,6 +94,68 @@ def test_vc_snippets( webapp, webdriver ):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+def test_scenario_notes_snippets( webapp, webdriver ):
+ """Test HTML snippet generation."""
+
+ # initialize
+ webdriver.get( webapp.url_for( "main", store_msgs=1 ) )
+ select_tab( "scenario" )
+
+ # add some scenario notes and check their snippets
+ def check_snippet( entry_no, expected ):
+ """Check the snippet for a scenario note."""
+ elems = find_children( "#scenario_notes-sortable li input[type='button']" )
+ elems[entry_no].click()
+ assert get_clipboard() == expected
+ _add_scenario_note( webdriver, "scenario note #1", None )
+ _add_scenario_note( webdriver, "scenario note #2", "100px" )
+ check_snippet( 0, "[scenario note #1]" )
+ check_snippet( 1, "[scenario note #2] (width=[100px])" )
+
+ # delete a scenario note by dragging it into the trash
+ def count_entries():
+ """Count the number of scenario notes."""
+ elems = find_children( "#scenario_notes-sortable li" )
+ return len(elems)
+ assert count_entries() == 2
+ elems = find_children( "#scenario_notes-sortable li" )
+ trash = find_child( "#scenario_notes-trash" )
+ ActionChains(webdriver).drag_and_drop( elems[0], trash ).perform()
+ assert count_entries() == 1
+
+ # delete scenario note by emptying its caption
+ _edit_scenario_note( webdriver, 0, "", None )
+ click_dialog_button( "OK" ) # nb: confirm the deletion
+ assert count_entries() == 0
+
+def _add_scenario_note( webdriver, caption, width ): #FIXME! move to utils
+ """Add a new scenario note."""
+ elem = find_child( "#scenario_notes-add" )
+ elem.click()
+ _edit_scenario_note( webdriver, None, caption, width )
+
+def _edit_scenario_note( webdriver, entry_no, caption, width ): #FIXME! move to utils
+ """Edit a scenario note."""
+
+ # locate the requested entry and start editing it
+ if entry_no is not None:
+ elems = find_children( "#scenario_notes-sortable li" )
+ elem = elems[ entry_no ]
+ ActionChains(webdriver).double_click( elem ).perform()
+
+ # edit the scenario note
+ if caption is not None:
+ elem = find_child( "#edit-simple_note textarea" )
+ elem.clear()
+ elem.send_keys( caption )
+ if width is not None:
+ elem = find_child( "#edit-simple_note input[type='text']" )
+ elem.clear()
+ elem.send_keys( width )
+ click_dialog_button( "OK" )
+
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
def test_players_snippets( webapp, webdriver ):
"""Test HTML snippet generation."""
@@ -172,7 +235,7 @@ def test_edit_templates( webapp, webdriver ):
elem.send_keys( Keys.ESCAPE )
def test_template( template_id, orig_template_id ):
"""Test editing a template."""
- if template_id in("ob_setup","ob_note"):
+ if template_id in("scenario_note","ob_setup","ob_note"):
return # nb: these require special handling (done below)
# edit the template
elem = find_child( "a.edit-template-link[data-id='{}']".format( template_id ) )
@@ -187,6 +250,18 @@ def test_edit_templates( webapp, webdriver ):
)
for_each_template( test_template )
+ # customize the SCENARIO NOTE template
+ select_tab( "scenario" )
+ elem = find_child( "input[type='button'][data-id='scenario_note']" )
+ elem.click()
+ edit_template( "scenario_note" )
+
+ # check that the new template is being used
+ _add_scenario_note( webdriver, "scenario note (ignored)", None )
+ elem = find_child( "#scenario_notes-sortable li input[type='button']" )
+ elem.click()
+ assert get_clipboard() == "EDITED TEMPLATE: scenario_note"
+
# customize the OB SETUP template
select_tab( "ob1" )
elem = find_child( "#tabs-ob1 input[type='button'][data-id='ob_setup']" )
diff --git a/vasl_templates/webapp/tests/test_template_packs.py b/vasl_templates/webapp/tests/test_template_packs.py
index 41ed60c..f5e170d 100644
--- a/vasl_templates/webapp/tests/test_template_packs.py
+++ b/vasl_templates/webapp/tests/test_template_packs.py
@@ -26,7 +26,13 @@ def test_individual_files( webapp, webdriver ):
"""Test uploading a customized version of the template."""
# make sure generating a snippet returns something
dismiss_notifications()
- if template_id in ("ob_setup","ob_note"):
+ if template_id == "scenario_note":
+ from vasl_templates.webapp.tests.test_snippets import _add_scenario_note
+ select_tab( "scenario" )
+ _add_scenario_note( webdriver, "test scenario note", None )
+ elems = find_children( "#scenario_notes-sortable li input[type='button']" )
+ elem = elems[0]
+ elif template_id in ("ob_setup","ob_note"):
select_tab( "ob1" )
func = getattr( test_ob, "add_"+template_id )
func( webdriver, 1, "test {}".format(template_id), None )
@@ -156,7 +162,14 @@ def _check_snippets( webdriver, expected ):
def test_template( template_id, orig_template_id ):
"""Test each template."""
dismiss_notifications()
- if template_id in ("ob_setup","ob_note"):
+ # FIXME! this code is duplicated above
+ if template_id == "scenario_note":
+ from vasl_templates.webapp.tests.test_snippets import _add_scenario_note
+ select_tab( "scenario" )
+ _add_scenario_note( webdriver, "test scenario note", None )
+ elems = find_children( "#scenario_notes-sortable li input[type='button']" )
+ elem = elems[0]
+ elif template_id in ("ob_setup","ob_note"):
select_tab( "ob1" )
func = getattr( test_ob, "add_"+template_id )
func( webdriver, 1, "test {}".format(template_id), None )
diff --git a/vasl_templates/webapp/tests/utils.py b/vasl_templates/webapp/tests/utils.py
index b058bde..e8e4d93 100644
--- a/vasl_templates/webapp/tests/utils.py
+++ b/vasl_templates/webapp/tests/utils.py
@@ -12,7 +12,7 @@ from selenium.common.exceptions import NoSuchElementException, StaleElementRefer
# standard templates
_STD_TEMPLATES = {
- "scenario": [ "scenario", "players", "victory_conditions", "ssr" ],
+ "scenario": [ "scenario", "players", "victory_conditions", "scenario_notes", "ssr" ],
"ob1": [ "ob_setup_1", "ob_note_1", "vehicles_1", "ordnance_1" ],
"ob2": [ "ob_setup_2", "ob_note_2", "vehicles_2", "ordnance_2" ],
}
@@ -29,7 +29,7 @@ _webdriver = None
# ---------------------------------------------------------------------
-def for_each_template( func ):
+def for_each_template( func ): #pylint: disable=too-many-branches
"""Test each template."""
# generate a list of all the templates we need to test
@@ -45,7 +45,9 @@ def for_each_template( func ):
for tab_id,template_ids in _STD_TEMPLATES.items():
for template_id in template_ids:
select_tab( tab_id )
- if template_id.startswith( "ob_setup_" ):
+ if template_id == "scenario_notes":
+ template_id2 = "scenario_note"
+ elif template_id.startswith( "ob_setup_" ):
template_id2 = "ob_setup"
elif template_id.startswith( "ob_note_" ):
template_id2 = "ob_note"
@@ -95,6 +97,14 @@ def set_template_params( params ): #pylint: disable=too-many-branches
for key,val in params.items():
+ # check for scenario notes (these require special handling)
+ if key == "SCENARIO_NOTES":
+ # add them in (nb: we don't consider any existing scenario notes)
+ from vasl_templates.webapp.tests.test_snippets import _add_scenario_note #pylint: disable=cyclic-import
+ for entry in val:
+ _add_scenario_note( _webdriver, entry.get("caption",""), entry.get("width","") )
+ continue
+
# check for SSR's (these require special handling)
if key == "SSR":
# add them in (nb: we don't consider any existing SSR's)