Make the "see also" fields clickable.

master
Pacman Ghost 3 years ago
parent d6cb63adea
commit 9ae6864262
  1. 23
      asl_rulebook2/webapp/static/SearchResult.js
  2. 3
      asl_rulebook2/webapp/static/css/SearchResult.css
  3. 13
      asl_rulebook2/webapp/tests/fixtures/see-also/see-also.index
  4. 52
      asl_rulebook2/webapp/tests/test_search.py

@ -26,7 +26,12 @@ gMainApp.component( "index-sr", {
:title="expandRulerefs ? 'Hide non-matching rule references. ': 'Show all rule references.'"
/>
<div v-if=sr.content class="content" v-html=sr.content />
<div v-if=makeSeeAlso v-html=makeSeeAlso class="see-also" />
<div v-if=sr.see_also class="see-also" > See also:
<span v-for="(sa, sa_no) in sr.see_also" >
{{sa_no == 0 ? "" : ", "}}
<a @click=onSeeAlso(sa) title="Search for this" > {{sa}} </a>
</span>
</div>
<div v-if=sr.ruleids class="ruleids" >
<ruleid v-for="rid in sr.ruleids" :csetId=sr.cset_id :ruleId=rid :key=rid />
</div>
@ -65,23 +70,21 @@ gMainApp.component( "index-sr", {
},
computed: {
makeSeeAlso() {
// generate the "see also" text
if ( this.sr.see_also )
return "See also: " + this.sr.see_also.join( ", " ) ;
return null ;
},
getToggleRulerefsImageUrl() {
// return the image URL for the "toggle ruleref's" button
return gImagesBaseUrl + (this.expandRulerefs ? "collapse" : "expand") + "-rulerefs.png" ; //eslint-disable-line no-undef
},
},
methods: {
onSeeAlso( see_also ) {
// search for the specified text
if ( see_also.indexOf( " " ) >= 0 )
see_also = '"' + see_also + '"' ;
gEventBus.emit( "search-for", see_also ) ;
},
onClickIcon() {
// open the search result's primary target
let target = getPrimaryTarget( this.sr ) ;

@ -6,7 +6,8 @@
#search-results .index-sr .subtitle { padding: 2px 5px ; font-weight: normal ; font-size: 80% ; font-style: italic ; }
#search-results .index-sr .body { padding: 2px 5px 0 5px ; }
#search-results .index-sr .content { color: #444 ; }
#search-results .index-sr .see-also { color: #444 ; }
#search-results .index-sr .see-also { color: #444 ; font-style: italic ; cursor: pointer ; }
#search-results .index-sr .see-also a { border-bottom: 1px dotted #888 ; }
#search-results .index-sr img.toggle-rulerefs { float: right ; margin: 0 0 0.25em 0.25em ; height: 1.25em ; cursor: pointer ; }
#search-results .index-sr ul.rulerefs { margin-left: 1.2em ; }
#search-results .index-sr ul.rulerefs .caption { padding-right: 0.5em ; }

@ -0,0 +1,13 @@
[
{ "title": "Foo",
"see_also": [ "Bar", "Baz Baz" ]
},
{ "title": "Bar"
},
{ "title": "Baz"
}
]

@ -167,6 +167,46 @@ def test_target_search( webapp, webdriver ):
# ---------------------------------------------------------------------
def test_see_also( webapp, webdriver ):
"""Test searching for "see also" fields."""
# initialize
webapp.control_tests.set_data_dir( "see-also" )
init_webapp( webapp, webdriver )
# do a search
results = do_search( "foo" )
assert results == [ {
"sr_type": "index",
"title": "((Foo))",
"see_also": [ "Bar", "Baz Baz" ]
} ]
def click_see_also( caption ):
elems = {
e.text: e
for e in find_children( "#search-results .see-also a" )
}
assert len(elems) == 2
elems[ caption ].click()
expected = '"{}"'.format( caption ) if " " in caption else caption
wait_for( 2, lambda: find_child( "input#query-string" ).get_attribute( "value" ) == expected )
return _unload_search_results()
# click on the "Bar" link and check that it gets searched for
results = click_see_also( "Bar" )
assert results == [ {
"sr_type": "index",
"title": "((Bar))"
} ]
# search for "foo" again, and click on the "Baz Baz" link
do_search( "foo" )
results = click_see_also( "Baz Baz" )
assert results is None
# ---------------------------------------------------------------------
def test_bad_sr_highlights( webapp, webdriver ):
"""Test fixing up highlight markers that have been incorrectly inserted into search result content."""
@ -287,6 +327,12 @@ def do_search( query_string ):
# unload the results
wait_for( 2, lambda: get_seq_no() > seq_no )
return _unload_search_results()
def _unload_search_results():
"""Unload the search results."""
# check if there were any search results
elem = find_child( "#search-results .error" )
if elem:
return elem.text # nb: string = error message
@ -294,12 +340,6 @@ def do_search( query_string ):
if elem:
assert elem.text == "Nothing was found."
return None # nb: None = no results
results = _unload_search_results()
assert isinstance( results, list ) # nb: list = search results
return results
def _unload_search_results():
"""Unload the search results."""
def unload_ruleids( result, key, parent ):
"""Unload a list of ruleid's."""

Loading…
Cancel
Save