Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8623d6e
feat(infinite-hits): implement `transformItems`
francoischalifour Jul 20, 2018
56da733
feat(hits): implement `transformItems`
francoischalifour Jul 20, 2018
85033ec
feat(breadcrumb): implement `transformItems`
francoischalifour Jul 20, 2018
f5aec2e
feat(hierarchical-menu): implement `transformItems`
francoischalifour Jul 20, 2018
e9b2d4c
feat(menu): implement `transformItems`
francoischalifour Jul 20, 2018
e55dba2
feat(menu-select): implement `transformItems`
francoischalifour Jul 20, 2018
1818edb
feat(refinement-list): implement `transformItems`
francoischalifour Jul 23, 2018
526d308
feat(geo-search): implement `transformItems`
francoischalifour Jul 23, 2018
c898c4a
feat(sort-by): implement `transformItems`
francoischalifour Jul 23, 2018
ee19dd7
feat(hits-per-page): implement `transformItems`
francoischalifour Jul 23, 2018
93e7af4
feat(current-refined-values): implement `transformItems`
francoischalifour Jul 23, 2018
b0f8611
feat(numeric-refinement-list): implement `transformItems`
francoischalifour Jul 23, 2018
63840dc
feat(numeric-selector): implement `transformItems`
francoischalifour Jul 23, 2018
01e3bb4
refactor(hits): use default identity function for `transformItems`
francoischalifour Jul 27, 2018
ca82ede
refactor(infinite-hits): use default identity function for `transform…
francoischalifour Jul 27, 2018
547f028
test(hits-per-page): migrate to Jest
francoischalifour Jul 30, 2018
b23df37
test(menu): migrate to Jest
francoischalifour Jul 30, 2018
7ffc09b
test(numeric-refinement-list): migrate to Jest
francoischalifour Jul 30, 2018
d74fe50
test(sort-by-selector): migrate to Jest
francoischalifour Jul 30, 2018
9dd9064
test(infinite-hits): migrate to Jest
francoischalifour Jul 30, 2018
54b30cf
test(refinement-list): migrate to Jest
francoischalifour Jul 30, 2018
80ad6e5
test(hits): migrate to Jest
francoischalifour Jul 30, 2018
a8e58b3
test(hierarchical-menu): migrate to Jest
francoischalifour Jul 30, 2018
dcaf3ca
test(current-refined-values): migrate to Jest and remove Lodash imports
francoischalifour Jul 30, 2018
4be30e9
Merge branch 'develop' into feat/transform-items
bobylito Jul 30, 2018
7c10a17
test(refinement-list): update snapshots
francoischalifour Jul 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(hierarchical-menu): migrate to Jest
  • Loading branch information
francoischalifour committed Jul 30, 2018
commit a8e58b34f22c85e7933c53c2d08ae27275396098
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sinon from 'sinon';

import jsHelper from 'algoliasearch-helper';
const SearchResults = jsHelper.SearchResults;
const SearchParameters = jsHelper.SearchParameters;
Expand Down Expand Up @@ -65,7 +63,7 @@ describe('connectHierarchicalMenu', () => {
it('Renders during init and render', () => {
// test that the dummyRendering is called with the isFirstRendering
// flag set accordingly
const rendering = sinon.stub();
const rendering = jest.fn();
const makeWidget = connectHierarchicalMenu(rendering);
const widget = makeWidget({
attributes: ['category', 'sub_category'],
Expand All @@ -86,10 +84,10 @@ describe('connectHierarchicalMenu', () => {
});

// test if widget is not rendered yet at this point
expect(rendering.callCount).toBe(0);
expect(rendering).toHaveBeenCalledTimes(0);

const helper = jsHelper({}, '', config);
helper.search = sinon.stub();
helper.search = jest.fn();

widget.init({
helper,
Expand All @@ -99,12 +97,14 @@ describe('connectHierarchicalMenu', () => {
});

// test that rendering has been called during init with isFirstRendering = true
expect(rendering.callCount).toBe(1);
expect(rendering).toHaveBeenCalledTimes(1);
// test if isFirstRendering is true during init
expect(rendering.lastCall.args[1]).toBe(true);
expect(rendering.lastCall.args[0].widgetParams).toEqual({
attributes: ['category', 'sub_category'],
});
expect(rendering).toHaveBeenLastCalledWith(
expect.objectContaining({
widgetParams: { attributes: ['category', 'sub_category'] },
}),
true
);

widget.render({
results: new SearchResults(helper.state, [{}]),
Expand All @@ -114,22 +114,24 @@ describe('connectHierarchicalMenu', () => {
});

// test that rendering has been called during init with isFirstRendering = false
expect(rendering.callCount).toBe(2);
expect(rendering.lastCall.args[1]).toBe(false);
expect(rendering.lastCall.args[0].widgetParams).toEqual({
attributes: ['category', 'sub_category'],
});
expect(rendering).toHaveBeenCalledTimes(2);
expect(rendering).toHaveBeenLastCalledWith(
expect.objectContaining({
widgetParams: { attributes: ['category', 'sub_category'] },
}),
false
);
});

it('Provide a function to clear the refinements at each step', () => {
const rendering = sinon.stub();
const rendering = jest.fn();
const makeWidget = connectHierarchicalMenu(rendering);
const widget = makeWidget({
attributes: ['category', 'sub_category'],
});

const helper = jsHelper({}, '', widget.getConfiguration({}));
helper.search = sinon.stub();
helper.search = jest.fn();

helper.toggleRefinement('category', 'value');

Expand All @@ -140,7 +142,7 @@ describe('connectHierarchicalMenu', () => {
onHistoryChange: () => {},
});

const firstRenderingOptions = rendering.lastCall.args[0];
const firstRenderingOptions = rendering.mock.calls[0][0];
const { refine } = firstRenderingOptions;
refine('value');
expect(helper.hasRefinements('category')).toBe(false);
Expand All @@ -154,7 +156,7 @@ describe('connectHierarchicalMenu', () => {
createURL: () => '#',
});

const secondRenderingOptions = rendering.lastCall.args[0];
const secondRenderingOptions = rendering.mock.calls[1][0];
const { refine: renderToggleRefinement } = secondRenderingOptions;
renderToggleRefinement('value');
expect(helper.hasRefinements('category')).toBe(false);
Expand All @@ -163,14 +165,14 @@ describe('connectHierarchicalMenu', () => {
});

it('provides the correct facet values', () => {
const rendering = sinon.stub();
const rendering = jest.fn();
const makeWidget = connectHierarchicalMenu(rendering);
const widget = makeWidget({
attributes: ['category', 'subCategory'],
});

const helper = jsHelper({}, '', widget.getConfiguration({}));
helper.search = sinon.stub();
helper.search = jest.fn();

helper.toggleRefinement('category', 'Decoration');

Expand All @@ -181,11 +183,15 @@ describe('connectHierarchicalMenu', () => {
onHistoryChange: () => {},
});

const firstRenderingOptions = rendering.lastCall.args[0];
// During the first rendering there are no facet values
// The function get an empty array so that it doesn't break
// over null-ish values.
expect(firstRenderingOptions.items).toEqual([]);
expect(rendering).toHaveBeenLastCalledWith(
expect.objectContaining({
items: [],
}),
expect.anything()
);

widget.render({
results: new SearchResults(helper.state, [
Expand Down Expand Up @@ -215,42 +221,46 @@ describe('connectHierarchicalMenu', () => {
createURL: () => '#',
});

const secondRenderingOptions = rendering.lastCall.args[0];
expect(secondRenderingOptions.items).toEqual([
{
label: 'Decoration',
value: 'Decoration',
count: 880,
isRefined: true,
data: [
expect(rendering).toHaveBeenLastCalledWith(
expect.objectContaining({
items: [
{
label: 'Candle holders & candles',
value: 'Decoration > Candle holders & candles',
count: 193,
isRefined: false,
data: null,
label: 'Decoration',
value: 'Decoration',
count: 880,
isRefined: true,
data: [
{
label: 'Candle holders & candles',
value: 'Decoration > Candle holders & candles',
count: 193,
isRefined: false,
data: null,
},
{
label: 'Frames & pictures',
value: 'Decoration > Frames & pictures',
count: 173,
isRefined: false,
data: null,
},
],
},
{
label: 'Frames & pictures',
value: 'Decoration > Frames & pictures',
count: 173,
label: 'Outdoor',
value: 'Outdoor',
count: 47,
isRefined: false,
data: null,
},
],
},
{
label: 'Outdoor',
value: 'Outdoor',
count: 47,
isRefined: false,
data: null,
},
]);
}),
expect.anything()
);
});

it('provides the correct transformed facet values', () => {
const rendering = sinon.stub();
const rendering = jest.fn();
const makeWidget = connectHierarchicalMenu(rendering);
const widget = makeWidget({
attributes: ['category', 'subCategory'],
Expand All @@ -262,7 +272,7 @@ describe('connectHierarchicalMenu', () => {
});

const helper = jsHelper({}, '', widget.getConfiguration({}));
helper.search = sinon.stub();
helper.search = jest.fn();

helper.toggleRefinement('category', 'Decoration');

Expand All @@ -271,8 +281,10 @@ describe('connectHierarchicalMenu', () => {
state: helper.state,
});

const firstRenderingOptions = rendering.lastCall.args[0];
expect(firstRenderingOptions.items).toEqual([]);
expect(rendering).toHaveBeenLastCalledWith(
expect.objectContaining({ items: [] }),
expect.anything()
);

widget.render({
results: new SearchResults(helper.state, [
Expand Down Expand Up @@ -301,11 +313,15 @@ describe('connectHierarchicalMenu', () => {
helper,
});

const secondRenderingOptions = rendering.lastCall.args[0];
expect(secondRenderingOptions.items).toEqual([
expect.objectContaining({ label: 'transformed' }),
expect.objectContaining({ label: 'transformed' }),
]);
expect(rendering).toHaveBeenLastCalledWith(
expect.objectContaining({
items: [
expect.objectContaining({ label: 'transformed' }),
expect.objectContaining({ label: 'transformed' }),
],
}),
expect.anything()
);
});

describe('routing', () => {
Expand All @@ -317,7 +333,7 @@ describe('connectHierarchicalMenu', () => {
});

const helper = jsHelper({}, '', widget.getConfiguration({}));
helper.search = sinon.stub();
helper.search = jest.fn();

widget.init({
helper,
Expand Down
Loading