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
45 lines (33 loc) • 1.39 kB
text/typescript
import {it, beforeEach} from '@angular/core/testing';
import {MultiSelectionStrategy} from './multi-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: MultiSelectionStrategy;
beforeEach(() => {
items = [{id: 1, label: 'foo', color: 'red'}, {id: 2, label: 'bar'}, {id: 3, label: 'baz'}];
selection = [items[0]];
selectionStrategy = new MultiSelectionStrategy(idGetter, labelGetter, selection);
});
it('should return preset selection', () => {
expect(selectionStrategy.getSelection()).toEqual(['data', [{id: 1, text: 'foo'}]]);
});
it('should deselect item', () => {
selectionStrategy.deSelectItem(1);
expect(selectionStrategy.getSelection()).toEqual(['data', []]);
});
it('should deselect nothing if item isn\'t selected', () => {
selectionStrategy.deSelectItem(100);
expect(selectionStrategy.getSelection()).toEqual(['data', [{id: 1, text: 'foo'}]]);
});
it('should select item', () => {
selectionStrategy.selectItem(items[2]);
expect(selectionStrategy.getSelection()).toEqual(['data', [{id: 1, text: 'foo'}, {id: 3, text: 'baz'}]]);
});
});