-
Notifications
You must be signed in to change notification settings - Fork 539
/
Copy path_clearNumericRefinements.js
82 lines (70 loc) · 2.22 KB
/
_clearNumericRefinements.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
var SearchParameters = require('../../../src/SearchParameters');
test('When removing all numeric refinements of a state without any', function () {
var state = SearchParameters.make({});
expect(state._clearNumericRefinements()).toBe(state.numericRefinements);
});
test('When removing numericRefinements of a specific attribute, which has no refinements', function () {
var state = SearchParameters.make({
numericRefinements: {
size: {},
},
});
expect(state._clearNumericRefinements('size')).toEqual({});
});
test('When removing numericRefinements of a specific attribute, and there are no refinements for this attribute', function () {
var state = SearchParameters.make({
numericRefinements: {
price: { '>': [300] },
},
});
expect(state._clearNumericRefinements('size')).toEqual(
state.numericRefinements
);
});
test('When removing refinements of a specific attribute, and another refinement is a substring of this attribute', function () {
var state = SearchParameters.make({
numericRefinements: {
price: { '>': [300] },
'price with taxes': { '>': [300] },
},
});
const expectedNumericRefinements = {
price: { '>': [300] },
};
expect(state._clearNumericRefinements('price with taxes')).toEqual(
expectedNumericRefinements
);
});
test('When removing numericRefinements using a function, and there are no changes', function () {
var state = SearchParameters.make({
numericRefinements: {
price: { '>': [300, 30] },
size: { '=': [32, 30] },
},
});
function clearNothing() {
return false;
}
function clearUndefinedAttribute(v, attribute) {
return attribute === 'distance';
}
function clearUndefinedOperator(v) {
return v.op === '<';
}
function clearUndefinedValue(v) {
return v.val === 3;
}
expect(state._clearNumericRefinements(clearNothing)).toBe(
state.numericRefinements
);
expect(state._clearNumericRefinements(clearUndefinedAttribute)).toBe(
state.numericRefinements
);
expect(state._clearNumericRefinements(clearUndefinedOperator)).toBe(
state.numericRefinements
);
expect(state._clearNumericRefinements(clearUndefinedValue)).toBe(
state.numericRefinements
);
});