Skip to content

Commit

Permalink
feat(ratingMenu): Add support for floats in values (#4611)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Croissant authored Jan 20, 2021
1 parent 734b2f4 commit 3f52784
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 94 deletions.
117 changes: 75 additions & 42 deletions src/connectors/rating-menu/__tests__/connectRatingMenu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
expect(helper.getRefinements(attribute)).toEqual([]);
refine('3');
expect(helper.getRefinements(attribute)).toEqual([
{ type: 'disjunctive', value: '3' },
{ type: 'disjunctive', value: '4' },
{ type: 'disjunctive', value: '5' },
{ operator: '<=', type: 'numeric', value: [5] },
{ operator: '>=', type: 'numeric', value: [3] },
]);
expect(helper.search).toHaveBeenCalledTimes(1);

Expand Down Expand Up @@ -229,14 +228,13 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
},
]);
expect(helper.getRefinements(attribute)).toEqual([
{ type: 'disjunctive', value: '3' },
{ type: 'disjunctive', value: '4' },
{ type: 'disjunctive', value: '5' },
{ operator: '<=', type: 'numeric', value: [5] },
{ operator: '>=', type: 'numeric', value: [3] },
]);
refine('4');
expect(helper.getRefinements(attribute)).toEqual([
{ type: 'disjunctive', value: '4' },
{ type: 'disjunctive', value: '5' },
{ operator: '<=', type: 'numeric', value: [5] },
{ operator: '>=', type: 'numeric', value: [4] },
]);
expect(helper.search).toHaveBeenCalledTimes(2);
}
Expand All @@ -252,9 +250,8 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
expect(helper.getRefinements(attribute)).toEqual([]);
refine('3');
expect(helper.getRefinements(attribute)).toEqual([
{ type: 'disjunctive', value: '3' },
{ type: 'disjunctive', value: '4' },
{ type: 'disjunctive', value: '5' },
{ operator: '<=', type: 'numeric', value: [5] },
{ operator: '>=', type: 'numeric', value: [3] },
]);
expect(helper.search).toHaveBeenCalledTimes(1);

Expand All @@ -278,13 +275,17 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu

// Second rendering
expect(helper.getRefinements(attribute)).toEqual([
{ type: 'disjunctive', value: '3' },
{ type: 'disjunctive', value: '4' },
{ type: 'disjunctive', value: '5' },
{ operator: '<=', type: 'numeric', value: [5] },
{ operator: '>=', type: 'numeric', value: [3] },
]);
refine('3');
expect(helper.getRefinements(attribute)).toEqual([]);
expect(helper.state.disjunctiveFacetsRefinements).toEqual({ swag: [] });
expect(helper.getRefinements(attribute)).toEqual([
{ operator: '<=', type: 'numeric', value: [] },
{ operator: '>=', type: 'numeric', value: [] },
]);
expect(helper.state.numericRefinements).toEqual({
swag: { '<=': [], '>=': [] },
});
expect(helper.search).toHaveBeenCalledTimes(2);
});

Expand Down Expand Up @@ -313,8 +314,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
const attribute = 'grade';
const helper = jsHelper({}, indexName, {
disjunctiveFacets: [attribute],
disjunctiveFacetsRefinements: {
[attribute]: [4, 5],
numericRefinements: {
[attribute]: {
'>=': [4],
},
},
});
helper.search = jest.fn();
Expand All @@ -327,8 +330,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
new SearchParameters({
index: indexName,
disjunctiveFacets: [attribute],
disjunctiveFacetsRefinements: {
grade: [4, 5],
numericRefinements: {
grade: {
'>=': [4],
},
},
})
);
Expand All @@ -338,6 +343,12 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
expect(nextState).toEqual(
new SearchParameters({
index: indexName,
disjunctiveFacets: [attribute],
numericRefinements: {
grade: {
'>=': [],
},
},
})
);
});
Expand Down Expand Up @@ -368,8 +379,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
const makeWidget = connectRatingMenu(render);
const helper = jsHelper({}, '', {
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
grade: ['2', '3', '4', '5'],
numericRefinements: {
grade: {
'>=': [2],
},
},
});

Expand Down Expand Up @@ -397,8 +410,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
const makeWidget = connectRatingMenu(render);
const helper = jsHelper({}, '', {
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
grade: ['2', '3', '4', '5'],
numericRefinements: {
grade: {
'>=': [2],
},
},
});

Expand Down Expand Up @@ -437,8 +452,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
});
const helper = jsHelper({}, 'indexName', {
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
grade: ['2', '3', '4'],
numericRefinements: {
grade: {
'>=': [2],
},
},
});

Expand Down Expand Up @@ -469,8 +486,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
});
const helper = jsHelper({}, 'indexName', {
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
grade: ['2', '3', '4'],
numericRefinements: {
grade: {
'>=': [2],
},
},
});

Expand Down Expand Up @@ -548,8 +567,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
});
const helper = jsHelper({}, 'indexName', {
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
grade: ['2', '3', '4'],
numericRefinements: {
grade: {
'>=': [2],
},
},
});

Expand Down Expand Up @@ -578,8 +599,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
});
const helper = jsHelper({}, 'indexName', {
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
grade: ['2', '3', '4'],
numericRefinements: {
grade: {
'>=': [2],
},
},
});

Expand Down Expand Up @@ -662,7 +685,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
new SearchParameters({
index: '',
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
numericRefinements: {
grade: [],
},
})
Expand All @@ -673,8 +696,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
const render = () => {};
const makeWidget = connectRatingMenu(render);
const helper = jsHelper({}, '', {
disjunctiveFacetsRefinements: {
grade: ['2', '3', '4', '5'],
numericRefinements: {
grade: {
'>=': [2],
},
},
});

Expand All @@ -690,7 +715,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
new SearchParameters({
index: '',
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
numericRefinements: {
grade: [],
},
})
Expand All @@ -717,8 +742,11 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
new SearchParameters({
index: '',
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
grade: ['3', '4', '5'],
numericRefinements: {
grade: {
'<=': [5],
'>=': [3],
},
},
})
);
Expand All @@ -729,8 +757,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
const makeWidget = connectRatingMenu(render);
const helper = jsHelper({}, '', {
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
grade: ['1', '2', '3', '4', '5'],
numericRefinements: {
grade: {
'>=': [1],
},
},
});

Expand All @@ -750,8 +780,11 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/rating-menu
new SearchParameters({
index: '',
disjunctiveFacets: ['grade'],
disjunctiveFacetsRefinements: {
grade: ['3', '4', '5'],
numericRefinements: {
grade: {
'<=': [5],
'>=': [3],
},
},
})
);
Expand Down
Loading

0 comments on commit 3f52784

Please sign in to comment.