""" 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, select_tab, set_player, \ set_template_params, 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 # --------------------------------------------------------------------- def test_extras_templates( webapp, webdriver ): """Test the extras templates.""" # initialize init_webapp( webapp, webdriver ) select_tab( "extras" ) # check that the extras templates were loaded correctly assert _get_extras_template_index() == [ ( "extras/minimal", None ), ( "Full template", "This is the caption." ), ( "select", None ), ] # check that the "full" template was loaded correctly _select_extras_template( webdriver, "extras/full" ) content = find_child( "#tabs-extras .right-panel" ) assert find_child( "div.name", content ).text == "Full template" assert find_child( "div.caption", content ).text == "This is the caption." assert find_child( "div.description", content ).text == "This is the description." params = find_children( "tr", content ) assert len(params) == 1 assert find_child( "td.caption", params[0] ).text == "The parameter:" textbox = find_child( "td.value input", params[0] ) assert textbox.get_attribute( "value" ) == "default-val" assert textbox.get_attribute( "size" ) == "10" assert textbox.get_attribute( "title" ) == "This is the parameter description." # generate the snippet snippet_btn = find_child( "button.generate", content ) snippet_btn.click() clipboard = wait_for_clipboard( 2, "param = default-val", contains=True ) assert "vasl-templates:comment" not in clipboard # nb: check that the comment was removed # check that the "minimal" template was loaded correctly _select_extras_template( webdriver, "extras/minimal" ) assert find_child( "div.name", content ).text == "extras/minimal" assert find_child( "div.caption", content ) is None assert find_child( "div.description", content ) is None params = find_children( "tr", content ) assert len(params) == 1 assert find_child( "td.caption", params[0] ).text == "PARAM:" textbox = find_child( "td.value input", params[0] ) assert textbox.get_attribute( "value" ) == "" # generate the snippet textbox.send_keys( "boo!" ) snippet_btn = find_child( "button.generate", content ) snippet_btn.click() clipboard = wait_for_clipboard( 2, "param = boo!", contains=True ) # --------------------------------------------------------------------- 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.""" # initialize init_webapp( webapp, webdriver, template_pack_persistence=1 ) select_tab( "extras" ) # check that the extras templates were loaded correctly assert _get_extras_template_index() == [ ( "extras/minimal", None ), ( "Full template", "This is the caption." ), ( "select", None ), ] # upload the template pack zip_data = make_zip_from_files( "extras" ) upload_template_pack_zip( zip_data, False ) # check that the templates were updated correctly assert _get_extras_template_index() == [ ( "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 _select_extras_template( webdriver, "extras/full" ) content = find_child( "#tabs-extras .right-panel" ) assert find_child( "div.name", content ).text == "Full template (modified)" assert find_child( "div.caption", content ).text == "This is the caption (modified)." params = find_children( "tr", content ) assert len(params) == 2 assert find_child( "td.caption", params[0] ).text == "The modified parameter:" textbox = find_child( "td.value input", params[0] ) assert textbox.get_attribute( "value" ) == "modified-default-val" assert textbox.get_attribute( "size" ) == "10" assert textbox.get_attribute( "title" ) == "This is the modified parameter description." assert find_child( "td.caption", params[1] ).text == "NEW-PARAM:" textbox = find_child( "td.value input", params[1] ) # --------------------------------------------------------------------- def test_edit_extras_template( webapp, webdriver ): """Test editing an extras templates.""" # initialize init_webapp( webapp, webdriver ) select_tab( "extras" ) # edit the "minimal" template _select_extras_template( webdriver, "extras/minimal" ) content = find_child( "#tabs-extras .right-panel" ) assert find_child( "div.caption", content ) is None webdriver.execute_script( "edit_template('extras/minimal')", content ) textarea = find_child( "#edit-template textarea" ) template = textarea.get_attribute( "value" ) \ .replace( "", "\n" ) \ .replace( "