This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX #113 : let the user change the tags for highlighting
- Loading branch information
Alexandre Stanislawski
committed
Jun 23, 2015
1 parent
e393120
commit 7c352a0
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
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(); | ||
} ); | ||
} ); | ||
|