Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/compass-query-bar/src/stores/query-bar-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import assert from 'assert';
import diff from 'object-diff';
import {
clone,
contains,
includes,
every,
get,
has,
Expand Down Expand Up @@ -508,7 +508,7 @@ const configureStore = (options = {}) => {
if (has(field, '$in')) {
// add value to $in array if it is not present yet
const inArray = filter[args.field].$in;
if (!contains(inArray, args.value)) {
if (!includes(inArray, args.value)) {
filter[args.field].$in.push(args.value);
this.setQuery({ filter: filter }, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,71 @@ describe('QueryBarStore [Store]', function() {
});
});

describe('addDistinctValue', function() {
afterEach(function() {
unsubscribe();
});

it('should add a distinct value to the filter state', function(done) {
unsubscribe = store.listen(state => {
expect(state.filter.name).to.equal('pineapple');
done();
});

store.addDistinctValue({
field: 'name',
value: 'pineapple'
});
});

it('should start a $in if the field already exists with one primitive', function(done) {
expect(store.state.userTyping).to.be.false;

store.addDistinctValue({
field: 'name',
value: 'winter'
});

unsubscribe = store.listen(state => {
expect(state.filter.name).to.deep.equal({
$in: ['winter', 'tomatoes']
});

done();
});

store.addDistinctValue({
field: 'name',
value: 'tomatoes'
});
});

it('should add a value to an array if it already exists', function(done) {
expect(store.state.userTyping).to.be.false;

store.addDistinctValue({
field: 'name',
value: 'e.t.'
});
store.addDistinctValue({
field: 'name',
value: 'phone'
});

unsubscribe = store.listen(state => {
expect(state.filter.name).to.deep.equal({
$in: ['e.t.', 'phone', 'home']
});
done();
});

store.addDistinctValue({
field: 'name',
value: 'home'
});
});
});

describe('setQueryString', function() {
afterEach(function() {
unsubscribe();
Expand Down