lucid-ui
Version:
A UI component library from AppNexus.
103 lines • 3.8 kB
JavaScript
import _isEqual from "lodash/isEqual";
import assert from 'assert';
import { onExpand, onCollapse, onSelect, onFocusNext, onFocusPrev, onFocusOption } from './DropMenu.reducers';
describe('DropMenu reducers', function () {
describe('onExpand', function () {
it('should set isExpanded=true, focusedIndex=null if selectedIndices is empty', function () {
var initialState = {
selectedIndices: []
};
var nextState = onExpand(initialState);
var selectedIndices = nextState.selectedIndices,
isExpanded = nextState.isExpanded,
focusedIndex = nextState.focusedIndex;
assert(_isEqual(selectedIndices, initialState.selectedIndices));
assert.equal(isExpanded, true);
assert.equal(focusedIndex, null);
});
it('should set isExpanded=true, focusedIndex={last selectedIndices}', function () {
var initialState = {
selectedIndices: [3, 2]
};
var nextState = onExpand(initialState);
var selectedIndices = nextState.selectedIndices,
isExpanded = nextState.isExpanded,
focusedIndex = nextState.focusedIndex;
assert(_isEqual(selectedIndices, initialState.selectedIndices));
assert.equal(isExpanded, true);
assert.equal(focusedIndex, 2);
});
});
describe('onCollapse', function () {
it('should set isExpanded=false', function () {
var initialState = {};
var nextState = onCollapse(initialState);
var isExpanded = nextState.isExpanded;
assert.equal(isExpanded, false);
});
});
describe('onSelect', function () {
it('should set isExpanded=false, selectedIndices=[optionIndex]', function () {
var initialState = {};
var optionIndex = 3;
var nextState = onSelect(initialState, optionIndex);
var isExpanded = nextState.isExpanded,
selectedIndices = nextState.selectedIndices;
assert.equal(isExpanded, false);
assert(_isEqual(selectedIndices, [3]));
});
});
describe('onFocusNext', function () {
it('should set focusedIndex=0 if focusedIndex=null', function () {
var initialState = {
focusedIndex: null
};
var nextState = onFocusNext(initialState);
var focusedIndex = nextState.focusedIndex;
assert.equal(focusedIndex, 0);
});
it('should set focusedIndex+=1 if focusedIndex={number}', function () {
var initialState = {
focusedIndex: 2
};
var nextState = onFocusNext(initialState);
var focusedIndex = nextState.focusedIndex;
assert.equal(focusedIndex, 3);
});
});
describe('onFocusPrev', function () {
it('should set focusedIndex=null if focusedIndex=null', function () {
var initialState = {
focusedIndex: null
};
var nextState = onFocusPrev(initialState);
var focusedIndex = nextState.focusedIndex;
assert.equal(focusedIndex, null);
});
it('should set focusedIndex=null if focusedIndex=0', function () {
var initialState = {
focusedIndex: 0
};
var nextState = onFocusPrev(initialState);
var focusedIndex = nextState.focusedIndex;
assert.equal(focusedIndex, null);
});
it('should set focusedIndex-=1 if focusedIndex={number}', function () {
var initialState = {
focusedIndex: 2
};
var nextState = onFocusPrev(initialState);
var focusedIndex = nextState.focusedIndex;
assert.equal(focusedIndex, 1);
});
});
describe('onFocusOption', function () {
it('should set focusedIndex=optionIndex', function () {
var initialState = {};
var optionIndex = 3;
var nextState = onFocusOption(initialState, optionIndex);
var focusedIndex = nextState.focusedIndex;
assert.equal(focusedIndex, 3);
});
});
});