mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-20 14:36:34 +02:00
Further public method unit tests
This commit is contained in:
parent
2f094e8e10
commit
b3486ccfbb
|
@ -610,7 +610,7 @@ class Choices {
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
removeActiveItemsByValue(value) {
|
removeActiveItemsByValue(value) {
|
||||||
if (!value || !isType('String', value)) {
|
if (!value) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1147,13 +1147,111 @@ describe('choices', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removeActiveItemsByValue', () => {
|
describe('removeActiveItemsByValue', () => {
|
||||||
beforeEach(() => {});
|
describe('passing invalid value', () => {
|
||||||
it('removes each active item in store with matching value', () => {});
|
beforeEach(() => {
|
||||||
|
output = instance.removeActiveItemsByValue(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
returnsInstance(output);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('passing valid value', () => {
|
||||||
|
let getItemsFilteredByActiveStub;
|
||||||
|
let removeItemStub;
|
||||||
|
const value = 'Removed';
|
||||||
|
const items = [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
value: 'Not removed',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
value: 'Removed',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3',
|
||||||
|
value: 'Removed',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
removeItemStub = stub();
|
||||||
|
getItemsFilteredByActiveStub = stub().returns(items);
|
||||||
|
instance.store.getItemsFilteredByActive = getItemsFilteredByActiveStub;
|
||||||
|
instance._removeItem = removeItemStub;
|
||||||
|
|
||||||
|
output = instance.removeActiveItemsByValue(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
instance.store.getItemsFilteredByActive.reset();
|
||||||
|
instance._removeItem.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes each active item in store with matching value', () => {
|
||||||
|
expect(removeItemStub.callCount).to.equal(2);
|
||||||
|
expect(removeItemStub.firstCall.args[0]).to.equal(items[1]);
|
||||||
|
expect(removeItemStub.secondCall.args[0]).to.equal(items[2]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removeActiveItems', () => {
|
describe('removeActiveItems', () => {
|
||||||
beforeEach(() => {});
|
let getItemsFilteredByActiveStub;
|
||||||
it('removes each active item in store', () => {});
|
let removeItemStub;
|
||||||
|
const items = [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
value: 'Not removed',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
value: 'Removed',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3',
|
||||||
|
value: 'Removed',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
removeItemStub = stub();
|
||||||
|
getItemsFilteredByActiveStub = stub().returns(items);
|
||||||
|
instance.store.getItemsFilteredByActive = getItemsFilteredByActiveStub;
|
||||||
|
instance._removeItem = removeItemStub;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
instance.store.getItemsFilteredByActive.reset();
|
||||||
|
instance._removeItem.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('not passing id to exclude', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
output = instance.removeActiveItems();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes all active items in store', () => {
|
||||||
|
expect(removeItemStub.callCount).to.equal(items.length);
|
||||||
|
expect(removeItemStub.firstCall.args[0]).to.equal(items[0]);
|
||||||
|
expect(removeItemStub.secondCall.args[0]).to.equal(items[1]);
|
||||||
|
expect(removeItemStub.thirdCall.args[0]).to.equal(items[2]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('passing id to exclude', () => {
|
||||||
|
const idToExclude = '2';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
output = instance.removeActiveItems(idToExclude);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes all active items in store with id that does match excludedId', () => {
|
||||||
|
expect(removeItemStub.callCount).to.equal(2);
|
||||||
|
expect(removeItemStub.firstCall.args[0]).to.equal(items[0]);
|
||||||
|
expect(removeItemStub.secondCall.args[0]).to.equal(items[2]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removeHighlightedItems', () => {
|
describe('removeHighlightedItems', () => {
|
||||||
|
|
Loading…
Reference in a new issue