-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request algolia/algoliasearch-helper-js#117 from algolia/f…
…ix/113 FIX algolia/algoliasearch-helper-js#113 : let the user change the tags for highlighting
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/algoliasearch-helper/test/integration-spec/helper.highlight.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"use strict"; | ||
|
||
var test = require( "tape" ); | ||
var algoliasearchHelper = require( "../../index" ); | ||
var setup = require( "../integration-utils.js" ).setup; | ||
|
||
test( "[INT][HIGHLIGHT] The highlight should be consistent with the parameters", function( t ) { | ||
var indexName = "helper_highlight"; | ||
|
||
setup( indexName, function( client, index ) { | ||
return index.addObjects( [ | ||
{ facet : [ "f1", "f2" ] }, | ||
{ facet : [ "f1", "f3" ] }, | ||
{ facet : [ "f2", "f3" ] } | ||
] ) | ||
.then( function() { | ||
return index.setSettings( { | ||
attributesToIndex : [ "facet" ], | ||
attributesForFaceting : [ "facet" ] | ||
} ); | ||
} ) | ||
.then( function( content ) { | ||
return index.waitTask( content.taskID ); | ||
} ).then( function() { | ||
return client; | ||
} ); | ||
} ).then( function( client ) { | ||
var helper = algoliasearchHelper( client, indexName, { | ||
attributesToHighlight : ["facet"], | ||
facets : [ "facet" ] | ||
} ); | ||
|
||
var calls = 0; | ||
helper.on( "result", function( content ) { | ||
calls++; | ||
if( calls === 1 ) { | ||
t.equal( content.hits[0]._highlightResult.facet[0].value, | ||
"<em>f1</em>", | ||
"should be hightlighted with em (default)" ); | ||
t.equal( content.hits[1]._highlightResult.facet[0].value, | ||
"<em>f1</em>", | ||
"should be hightlighted with em (default)" ); | ||
} | ||
else if( calls === 2 ) { | ||
t.equal( content.hits[0]._highlightResult.facet[0].value, | ||
"<strong>f1</strong>", | ||
"should be hightlighted with strong (setting)" ); | ||
t.equal( content.hits[1]._highlightResult.facet[0].value, | ||
"<strong>f1</strong>", | ||
"should be hightlighted with strong (setting)" ); | ||
t.end(); | ||
} | ||
} ); | ||
|
||
helper.setQuery( "f1" ) | ||
.search() | ||
.setQueryParameter( "highlightPostTag", "</strong>" ) | ||
.setQueryParameter( "highlightPreTag", "<strong>" ) | ||
.search(); | ||
} ); | ||
} ); | ||
|