Allow the webapp to startup with a search query.

master
Pacman Ghost 3 years ago
parent 23698718dd
commit a8a5c97153
  1. 11
      asl_rulebook2/webapp/static/SearchPane.js
  2. 30
      asl_rulebook2/webapp/tests/test_search.py
  3. 20
      asl_rulebook2/webapp/tests/utils.py

@ -1,4 +1,4 @@
import { gMainApp, gAppConfig, gEventBus } from "./MainApp.js" ;
import { gMainApp, gAppConfig, gUrlParams, gEventBus } from "./MainApp.js" ;
import { gUserSettings, saveUserSettings } from "./UserSettings.js" ;
import { postURL, findTargets, getPrimaryTarget, linkifyAutoRuleids, fixupSearchHilites, hideFootnotes } from "./utils.js" ;
@ -72,9 +72,12 @@ gMainApp.component( "search-box", {
} ) ;
gEventBus.on( "app-loaded", () => {
// check if we should start off with a query (for debugging porpoises)
if ( gAppConfig.WEBAPP_INITIAL_QUERY_STRING )
gEventBus.emit( "search-for", gAppConfig.WEBAPP_INITIAL_QUERY_STRING ) ;
// check if we should start off with a query
let queryString = gUrlParams.get( "query" ) || gUrlParams.get( "q" ) || gAppConfig.WEBAPP_INITIAL_QUERY_STRING ;
if ( window.location.hash != "" )
queryString = window.location.hash.substring( 1 ) ;
if ( queryString != null && queryString != undefined )
gEventBus.emit( "search-for", queryString ) ;
} ) ;
gEventBus.on( "tab-activated", (tabbedPages, tabId) => {

@ -6,8 +6,9 @@ from selenium.webdriver.common.keys import Keys
from asl_rulebook2.webapp.search import load_search_config, _make_fts_query_string
from asl_rulebook2.webapp.startup import StartupMsgs
from asl_rulebook2.webapp.tests.utils import init_webapp, select_tabbed_page, get_curr_target, get_classes, \
wait_for, find_child, find_children, unload_elem, unload_sr_text
from asl_rulebook2.webapp.tests.utils import init_webapp, make_webapp_main_url, \
select_tabbed_page, get_curr_target, get_classes, \
wait_for, wait_for_elem, find_child, find_children, unload_elem, unload_sr_text
# ---------------------------------------------------------------------
@ -209,6 +210,31 @@ def test_bad_sr_highlights( webapp, webdriver ):
# ---------------------------------------------------------------------
def test_startup_search_query( webapp, webdriver ):
"""Test starting up with a search query."""
# initialize
webapp.control_tests.set_data_dir( "full" )
# test starting up with a query
init_webapp( webapp, webdriver, q="cc" )
wait_for( 2, lambda: len( unload_search_results() ) > 0 )
# test starting up with a query
init_webapp( webapp, webdriver, query="wp" )
wait_for_elem( 2,"#rule-info" )
find_child( ".close-rule-info" ).click()
assert len( unload_search_results() ) > 0
# test starting up with a query
url = make_webapp_main_url( {} )
assert "#" not in url
url += "#bu"
webdriver.get( url )
wait_for( 2, lambda: len( unload_search_results() ) > 0 )
# ---------------------------------------------------------------------
def test_make_fts_query_string():
"""Test generating the FTS query string."""

@ -36,14 +36,7 @@ def init_webapp( webapp, webdriver, **options ):
# load the webapp
webapp.control_tests.set_app_config_val( "BLOCKING_FIXUP_CONTENT", True )
if get_pytest_option("webdriver") == "chrome" and get_pytest_option("headless"):
# FUDGE! Headless Chrome doesn't want to show the PDF in the browser,
# it downloads the file and saves it in the current directory :wtf:
options["no-content"] = 1
options["store-msgs"] = 1 # nb: so that we can retrive notification messages
options["no-animations"] = 1
options["reload"] = 1 # nb: force the webapp to reload
webdriver.get( webapp.url_for( "main", **options ) )
webdriver.get( make_webapp_main_url( options ) )
_wait_for_webapp()
# make sure there were no errors or warnings
@ -61,6 +54,17 @@ def init_webapp( webapp, webdriver, **options ):
# reset the user settings
webdriver.delete_all_cookies()
def make_webapp_main_url( options ):
"""Generate the webapp URL."""
if get_pytest_option("webdriver") == "chrome" and get_pytest_option("headless"):
# FUDGE! Headless Chrome doesn't want to show the PDF in the browser,
# it downloads the file and saves it in the current directory :wtf:
options["no-content"] = 1
options["store-msgs"] = 1 # nb: so that we can retrive notification messages
options["no-animations"] = 1
options["reload"] = 1 # nb: force the webapp to reload
return _webapp.url_for( "main", **options )
def refresh_webapp( webdriver ):
"""Refresh the webapp."""
webdriver.refresh()

Loading…
Cancel
Save