Skip to content

Commit

Permalink
Merge branch 'master' into feat/disable-cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjae Lee authored Jan 11, 2021
2 parents c152d2c + 7502744 commit 8bbb98e
Show file tree
Hide file tree
Showing 35 changed files with 1,250 additions and 46 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# [4.10.0](https://github.com/algolia/instantsearch.js/compare/v4.9.2...v4.10.0) (2021-01-05)


### Features

* **index:** expose createURL ([#4603](https://github.com/algolia/instantsearch.js/issues/4603)) ([f57e9c5](https://github.com/algolia/instantsearch.js/commit/f57e9c5a46e927b8dd38f167ee5c467151334a08))
* **index:** expose scoped results getter ([#4609](https://github.com/algolia/instantsearch.js/issues/4609)) ([a41b1e4](https://github.com/algolia/instantsearch.js/commit/a41b1e46bb195e6ef1f9bdbdde64d9300246c22f))
* **reverseHighlight/reverseSnippet:** Implements reverseHighlight and reverseSnippet ([#4592](https://github.com/algolia/instantsearch.js/issues/4592)) ([718bf45](https://github.com/algolia/instantsearch.js/commit/718bf458152bb55bab1efb542adb8e31298c0c3c))



## [4.9.2](https://github.com/algolia/instantsearch.js/compare/v4.9.1...v4.9.2) (2020-12-15)


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "instantsearch.js",
"version": "4.9.2",
"version": "4.10.0",
"description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
"homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
"types": "es/index.d.ts",
Expand Down Expand Up @@ -143,7 +143,7 @@
"bundlesize": [
{
"path": "./dist/instantsearch.production.min.js",
"maxSize": "65.25 kB"
"maxSize": "65.5 kB"
},
{
"path": "./dist/instantsearch.development.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hierarchica
insightsMethod: 'clickedFilters',
payload: {
eventName: 'Filter Applied',
filters: ['category:"value"'],
filters: ['category:value'],
index: '',
},
widgetType: 'ais.hierarchicalMenu',
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/menu/__tests__/connectMenu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/menu/js/#co
insightsMethod: 'clickedFilters',
payload: {
eventName: 'Filter Applied',
filters: ['category:"value"'],
filters: ['category:value'],
index: '',
},
widgetType: 'ais.menu',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2864,7 +2864,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/refinement-
insightsMethod: 'clickedFilters',
payload: {
eventName: 'Filter Applied',
filters: ['category:"value"'],
filters: ['category:value'],
index: '',
},
widgetType: 'ais.refinementList',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const createSendEvent = ({ instantSearchInstance, attribute, on, helper }) => (
payload: {
eventName,
index: helper.getIndex(),
filters: on.map(value => `${attribute}:${JSON.stringify(value)}`),
filters: on.map(value => `${attribute}:${value}`),
},
});
}
Expand Down
203 changes: 203 additions & 0 deletions src/helpers/__tests__/reverseHighlight-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import reverseHighlight from '../reverseHighlight';

const NONE = 'none' as const;
const FULL = 'full' as const;

/* eslint-disable @typescript-eslint/camelcase */
const hit = {
name: 'Amazon - Fire TV Stick with Alexa Voice Remote - Black',
description:
'Enjoy smart access to videos, games and apps with this Amazon Fire TV stick. Its Alexa voice remote lets you deliver hands-free commands when you want to watch television or engage with other applications. With a quad-core processor, 1GB internal memory and 8GB of storage, this portable Amazon Fire TV stick works fast for buffer-free streaming.',
brand: 'Amazon',
categories: ['TV & Home Theater', 'Streaming Media Players'],
hierarchicalCategories: {
lvl0: 'TV & Home Theater',
lvl1: 'TV & Home Theater > Streaming Media Players',
},
type: 'Streaming - (media plyr)',
price: 39.99,
price_range: '1 - 50',
image: 'https://cdn-demo.algolia.com/bestbuy-0118/5477500_sb.jpg',
url: 'https://api.bestbuy.com/click/-/5477500/pdp',
free_shipping: false,
rating: 4,
popularity: 21469,
objectID: '5477500',
_highlightResult: {
name: {
value:
'<mark>Amazon</mark> - Fire TV Stick with Alexa Voice Remote - Black',
matchLevel: FULL,
fullyHighlighted: false,
matchedWords: ['amazon'],
},
description: {
value:
'Enjoy smart access to videos, games and apps with this <mark>Amazon</mark> Fire TV stick. Its Alexa voice remote lets you deliver hands-free commands when you want to watch television or engage with other applications. With a quad-core <mark>processor</mark>, <mark>1GB</mark> internal memory and 8GB of storage, this portable <mark>Amazon</mark> Fire TV stick works fast for buffer-free streaming.',
matchLevel: FULL,
fullyHighlighted: false,
matchedWords: ['amazon', 'processor', '1GB'],
},
brand: {
value: '<mark>Amazon</mark>',
matchLevel: FULL,
fullyHighlighted: true,
matchedWords: ['amazon'],
},
categories: [
{
value: 'TV & Home Theater',
matchLevel: NONE,
matchedWords: [],
},
{
value: 'Streaming Media Players',
matchLevel: NONE,
matchedWords: [],
},
],
type: {
value: '<mark>Streaming</mark> - (<mark>media</mark> plyr)',
matchLevel: FULL,
fullyHighlighted: false,
matchedWords: ['streaming', 'media'],
},
typeMissingSibling: {
value: 'Streaming - (<mark>media</mark> plyr)',
matchLevel: FULL,
fullyHighlighted: false,
matchedWords: ['media'],
},
typeFullMatch: {
value: '<mark>Streaming</mark> - (<mark>media</mark> <mark>plyr</mark>)',
matchLevel: FULL,
fullyHighlighted: false,
matchedWords: ['streaming', 'media', 'plyr'],
},
meta: {
name: {
value: 'Nested <mark>Amazon</mark> name',
matchLevel: NONE,
matchedWords: ['Amazon'],
},
},
},
};
/* eslint-enable @typescript-eslint/camelcase */

describe('reverseHighlight', () => {
test('with default tag name', () => {
expect(
reverseHighlight({
attribute: 'name',
hit,
})
).toMatchInlineSnapshot(
`"Amazon<mark class=\\"ais-ReverseHighlight-highlighted\\"> - Fire TV Stick with Alexa Voice Remote - Black</mark>"`
);
});

test('with full match', () => {
expect(
reverseHighlight({
attribute: 'typeFullMatch',
hit,
})
).toMatchInlineSnapshot(`"Streaming - (media plyr)"`);
});

test('with custom tag name', () => {
expect(
reverseHighlight({
attribute: 'description',
highlightedTagName: 'em',
hit,
})
).toMatchInlineSnapshot(
`"<em class=\\"ais-ReverseHighlight-highlighted\\">Enjoy smart access to videos, games and apps with this </em>Amazon<em class=\\"ais-ReverseHighlight-highlighted\\"> Fire TV stick. Its Alexa voice remote lets you deliver hands-free commands when you want to watch television or engage with other applications. With a quad-core </em>processor, 1GB<em class=\\"ais-ReverseHighlight-highlighted\\"> internal memory and 8GB of storage, this portable </em>Amazon<em class=\\"ais-ReverseHighlight-highlighted\\"> Fire TV stick works fast for buffer-free streaming.</em>"`
);
});

test('with custom highlighted class name', () => {
expect(
reverseHighlight({
attribute: 'description',
cssClasses: { highlighted: '__highlighted class' },
hit,
})
).toMatchInlineSnapshot(
`"<mark class=\\"ais-ReverseHighlight-highlighted __highlighted class\\">Enjoy smart access to videos, games and apps with this </mark>Amazon<mark class=\\"ais-ReverseHighlight-highlighted __highlighted class\\"> Fire TV stick. Its Alexa voice remote lets you deliver hands-free commands when you want to watch television or engage with other applications. With a quad-core </mark>processor, 1GB<mark class=\\"ais-ReverseHighlight-highlighted __highlighted class\\"> internal memory and 8GB of storage, this portable </mark>Amazon<mark class=\\"ais-ReverseHighlight-highlighted __highlighted class\\"> Fire TV stick works fast for buffer-free streaming.</mark>"`
);
});

test('with unknown attribute returns an empty string', () => {
expect(
reverseHighlight({
attribute: 'wrong-attribute',
hit,
})
).toMatchInlineSnapshot(`""`);
});

test('with nested attribute', () => {
expect(
reverseHighlight({
attribute: 'meta.name',
hit,
})
).toMatchInlineSnapshot(
`"<mark class=\\"ais-ReverseHighlight-highlighted\\">Nested </mark>Amazon<mark class=\\"ais-ReverseHighlight-highlighted\\"> name</mark>"`
);
});

test('with nested attribute as array', () => {
expect(
reverseHighlight({
attribute: ['meta', 'name'],
hit,
})
).toMatchInlineSnapshot(
`"<mark class=\\"ais-ReverseHighlight-highlighted\\">Nested </mark>Amazon<mark class=\\"ais-ReverseHighlight-highlighted\\"> name</mark>"`
);
});

test('with array attribute', () => {
expect(
reverseHighlight({
attribute: 'categories.1',
hit,
})
).toMatchInlineSnapshot(`"Streaming Media Players"`);
});

test('with array attribute as array', () => {
expect(
reverseHighlight({
attribute: ['categories', '1'],
hit,
})
).toMatchInlineSnapshot(`"Streaming Media Players"`);
});

test('with non-alphanumeric character with alphanumeric siblings matching highlight', () => {
expect(
reverseHighlight({
attribute: 'type',
hit,
})
).toMatchInlineSnapshot(
`"Streaming - (media<mark class=\\"ais-ReverseHighlight-highlighted\\"> plyr)</mark>"`
);
});

test('with non-alphanumeric character with different alphanumeric siblings highlight', () => {
expect(
reverseHighlight({
attribute: 'typeMissingSibling',
hit,
})
).toMatchInlineSnapshot(
`"<mark class=\\"ais-ReverseHighlight-highlighted\\">Streaming - (</mark>media<mark class=\\"ais-ReverseHighlight-highlighted\\"> plyr)</mark>"`
);
});
});
Loading

0 comments on commit 8bbb98e

Please sign in to comment.