k15t-aui-ng2
Version:
aui-ng2 is a set of angular 2 components, directives and services to simplify the integration with Atlassian products based on AUI/ADG. The library is still under development and is considered in an experimental state. So be aware that things will change
37 lines (28 loc) • 1.03 kB
text/typescript
import {SingleSelectionStrategy} from './single-selection-strategy';
describe('Single Selection Strategy', () => {
function labelGetter(obj) {
return obj.label;
}
function idGetter(obj) {
return obj.id;
}
let items: any[];
let selection: any;
let selectionStrategy: SingleSelectionStrategy;
beforeEach(() => {
items = [{id: 1, label: 'foo', color: 'red'}, {id: 2, label: 'bar'}];
selection = items[0];
selectionStrategy = new SingleSelectionStrategy(idGetter, labelGetter, selection);
});
it('should return preset selection', () => {
expect(selectionStrategy.getSelection()).toEqual(['val', 1]);
});
it('should deselect item', () => {
selectionStrategy.deSelectItem(1);
expect(selectionStrategy.getSelection()).toEqual(['val', null]);
});
it('should select item', () => {
selectionStrategy.selectItem(items[1]);
expect(selectionStrategy.getSelection()).toEqual(['val', 2]);
});
});