lucid-ui
Version:
A UI component library from AppNexus.
85 lines (84 loc) • 3.02 kB
JavaScript
import _isEqual from "lodash/isEqual";
/* eslint-disable comma-spacing */
import assert from 'assert';
import { onChange, onSelect, onExpand } from './Autocomplete.reducers';
describe('Autocomplete reducers', function () {
describe('onChange', function () {
it('should set DropMenu.focusedIndex=null and value to arg', function () {
var initialState = {
value: '',
DropMenu: {
focusedIndex: 2
}
};
var nextState = onChange(initialState, 'foo');
var value = nextState.value,
focusedIndex = nextState.DropMenu.focusedIndex;
assert.equal(value, 'foo');
assert.equal(focusedIndex, null);
});
});
describe('onSelect', function () {
it('should set DropMenu.selectedIndices=[] and value to suggestion at given index arg', function () {
var initialState = {
suggestions: ['Portland', 'portal', 'porridge', 'potent', 'please'],
value: '',
DropMenu: {
selectedIndices: [3, 2]
}
};
var nextState = onSelect(initialState, 2);
var value = nextState.value,
selectedIndices = nextState.DropMenu.selectedIndices;
assert.equal(value, 'porridge');
assert(_isEqual(selectedIndices, []));
});
});
describe('onExpand', function () {
it('should set DropMenu.focusedIndex=null and DropMenu.isExpanded=true if `suggestions` and `value` are not empty', function () {
var initialState = {
value: 'foo',
suggestions: ['foo', 'bar'],
DropMenu: {
focusedIndex: 2
}
};
var nextState = onExpand(initialState);
var _nextState$DropMenu = nextState.DropMenu,
focusedIndex = _nextState$DropMenu.focusedIndex,
isExpanded = _nextState$DropMenu.isExpanded;
assert.equal(isExpanded, true);
assert.equal(focusedIndex, null);
});
it('should set DropMenu.focusedIndex=null and DropMenu.isExpanded=false if `suggestions` is empty', function () {
var initialState = {
value: 'foo',
suggestions: [],
DropMenu: {
focusedIndex: 2
}
};
var nextState = onExpand(initialState);
var _nextState$DropMenu2 = nextState.DropMenu,
focusedIndex = _nextState$DropMenu2.focusedIndex,
isExpanded = _nextState$DropMenu2.isExpanded;
assert.equal(isExpanded, false);
assert.equal(focusedIndex, null);
});
it('should set DropMenu.focusedIndex=null and DropMenu.isExpanded=false if `value` is empty', function () {
var initialState = {
value: '',
suggestions: ['foo', 'bar'],
DropMenu: {
focusedIndex: 2
}
};
var nextState = onExpand(initialState);
var _nextState$DropMenu3 = nextState.DropMenu,
focusedIndex = _nextState$DropMenu3.focusedIndex,
isExpanded = _nextState$DropMenu3.isExpanded;
assert.equal(isExpanded, false);
assert.equal(focusedIndex, null);
});
});
});