mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-10 09:36:35 +02:00
Prepare test descriptions
This commit is contained in:
parent
dd0b4bc086
commit
3adccb3ce5
|
@ -670,7 +670,7 @@ choices.disable();
|
|||
**Usage:** Un-highlight each chosen item.
|
||||
|
||||
|
||||
### removeItemsByValue(value);
|
||||
### removeActiveItemsByValue(value);
|
||||
**Input types affected:** `text`, `select-multiple`
|
||||
|
||||
**Usage:** Remove each item by a given value.
|
||||
|
|
2
index.d.ts
vendored
2
index.d.ts
vendored
|
@ -91,7 +91,7 @@ declare module "choices.js" {
|
|||
* @return {Object} Class instance
|
||||
* @public
|
||||
*/
|
||||
removeItemsByValue(value: string): this;
|
||||
removeActiveItemsByValue(value: string): this;
|
||||
|
||||
/**
|
||||
* Remove all items from store array
|
||||
|
|
4
src/scripts/dist/choices.js
vendored
4
src/scripts/dist/choices.js
vendored
|
@ -2482,8 +2482,8 @@ var Choices = function () {
|
|||
*/
|
||||
|
||||
}, {
|
||||
key: 'removeItemsByValue',
|
||||
value: function removeItemsByValue(value) {
|
||||
key: 'removeActiveItemsByValue',
|
||||
value: function removeActiveItemsByValue(value) {
|
||||
var _this6 = this;
|
||||
|
||||
if (!value || !(0, _utils.isType)('String', value)) {
|
||||
|
|
2
src/scripts/dist/choices.js.map
vendored
2
src/scripts/dist/choices.js.map
vendored
File diff suppressed because one or more lines are too long
2
src/scripts/dist/choices.min.js
vendored
2
src/scripts/dist/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -470,11 +470,11 @@ class Choices {
|
|||
choiceListFragment = this.renderChoices(activeChoices, choiceListFragment);
|
||||
}
|
||||
|
||||
const activeItems = this.store.getItemsFilteredByActive();
|
||||
const canAddItem = this._canAddItem(activeItems, this.input.getValue());
|
||||
|
||||
// If we have choices to show
|
||||
if (choiceListFragment.childNodes && choiceListFragment.childNodes.length > 0) {
|
||||
const activeItems = this.store.getItemsFilteredByActive();
|
||||
const canAddItem = this._canAddItem(activeItems, this.input.getValue());
|
||||
|
||||
// ...and we can select them
|
||||
if (canAddItem.response) {
|
||||
// ...append them and highlight the first choice
|
||||
|
@ -511,17 +511,15 @@ class Choices {
|
|||
|
||||
// Get active items (items that can be selected)
|
||||
const activeItems = this.store.getItemsFilteredByActive() || [];
|
||||
// Clear list
|
||||
this.itemList.clear();
|
||||
|
||||
if (activeItems.length) {
|
||||
// Clear list
|
||||
this.itemList.clear();
|
||||
// Create a fragment to store our list items
|
||||
// (so we don't have to update the DOM for each item)
|
||||
const itemListFragment = this.renderItems(activeItems);
|
||||
|
||||
// If we have items to add
|
||||
// If we have items to add, append them
|
||||
if (itemListFragment.childNodes) {
|
||||
// Update list
|
||||
this.itemList.append(itemListFragment);
|
||||
}
|
||||
}
|
||||
|
@ -611,7 +609,7 @@ class Choices {
|
|||
* @return {Object} Class instance
|
||||
* @public
|
||||
*/
|
||||
removeItemsByValue(value) {
|
||||
removeActiveItemsByValue(value) {
|
||||
if (!value || !isType('String', value)) {
|
||||
return this;
|
||||
}
|
||||
|
@ -638,7 +636,7 @@ class Choices {
|
|||
const items = this.store.getItemsFilteredByActive();
|
||||
|
||||
items.forEach((item) => {
|
||||
if (item.active && excludedId !== item.id) {
|
||||
if (excludedId !== item.id) {
|
||||
this._removeItem(item);
|
||||
}
|
||||
});
|
||||
|
@ -656,13 +654,15 @@ class Choices {
|
|||
const items = this.store.getItemsFilteredByActive();
|
||||
|
||||
items.forEach((item) => {
|
||||
if (item.highlighted && item.active) {
|
||||
this._removeItem(item);
|
||||
// If this action was performed by the user
|
||||
// trigger the event
|
||||
if (runEvent) {
|
||||
this._triggerChange(item.value);
|
||||
}
|
||||
if (item.highlighted) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._removeItem(item);
|
||||
// If this action was performed by the user
|
||||
// trigger the event
|
||||
if (runEvent) {
|
||||
this._triggerChange(item.value);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -792,6 +792,7 @@ class Choices {
|
|||
!this.initialised ||
|
||||
!this.isSelectElement ||
|
||||
!isType('Array', choices) ||
|
||||
!choices.length ||
|
||||
!value
|
||||
) {
|
||||
return this;
|
||||
|
@ -802,32 +803,29 @@ class Choices {
|
|||
this._clearChoices();
|
||||
}
|
||||
|
||||
// Add choices if passed
|
||||
if (choices.length) {
|
||||
this.containerOuter.removeLoadingState();
|
||||
const addGroupsAndChoices = (groupOrChoice) => {
|
||||
if (groupOrChoice.choices) {
|
||||
this._addGroup(
|
||||
groupOrChoice,
|
||||
(groupOrChoice.id || null),
|
||||
value,
|
||||
label,
|
||||
);
|
||||
} else {
|
||||
this._addChoice(
|
||||
groupOrChoice[value],
|
||||
groupOrChoice[label],
|
||||
groupOrChoice.selected,
|
||||
groupOrChoice.disabled,
|
||||
undefined,
|
||||
groupOrChoice.customProperties,
|
||||
groupOrChoice.placeholder,
|
||||
);
|
||||
}
|
||||
};
|
||||
this.containerOuter.removeLoadingState();
|
||||
const addGroupsAndChoices = (groupOrChoice) => {
|
||||
if (groupOrChoice.choices) {
|
||||
this._addGroup(
|
||||
groupOrChoice,
|
||||
(groupOrChoice.id || null),
|
||||
value,
|
||||
label,
|
||||
);
|
||||
} else {
|
||||
this._addChoice(
|
||||
groupOrChoice[value],
|
||||
groupOrChoice[label],
|
||||
groupOrChoice.selected,
|
||||
groupOrChoice.disabled,
|
||||
undefined,
|
||||
groupOrChoice.customProperties,
|
||||
groupOrChoice.placeholder,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
choices.forEach(addGroupsAndChoices);
|
||||
}
|
||||
choices.forEach(addGroupsAndChoices);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ describe('Choices', () => {
|
|||
expect(instance.unhighlightItem).to.be.a('function');
|
||||
expect(instance.highlightAll).to.be.a('function');
|
||||
expect(instance.unhighlightAll).to.be.a('function');
|
||||
expect(instance.removeItemsByValue).to.be.a('function');
|
||||
expect(instance.removeActiveItemsByValue).to.be.a('function');
|
||||
expect(instance.removeActiveItems).to.be.a('function');
|
||||
expect(instance.removeHighlightedItems).to.be.a('function');
|
||||
expect(instance.showDropdown).to.be.a('function');
|
||||
|
@ -940,11 +940,11 @@ describe('Choices', () => {
|
|||
expect(instance.input.element.value).to.equal('');
|
||||
});
|
||||
|
||||
it('handles removeItemsByValue()', () => {
|
||||
it('handles removeActiveItemsByValue()', () => {
|
||||
const items = instance.currentState.items;
|
||||
const randomItem = items[Math.floor(Math.random() * items.length)];
|
||||
|
||||
instance.removeItemsByValue(randomItem.value);
|
||||
instance.removeActiveItemsByValue(randomItem.value);
|
||||
expect(randomItem.active).to.be.false;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -34,7 +34,7 @@ describe('choices', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('already initialised', () => {
|
||||
describe('when already initialised', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = true;
|
||||
instance.init();
|
||||
|
@ -123,7 +123,7 @@ describe('choices', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('already initialised', () => {
|
||||
describe('when already initialised', () => {
|
||||
let removeEventListenersSpy;
|
||||
let passedElementRevealSpy;
|
||||
let containerOuterRevertSpy;
|
||||
|
@ -209,7 +209,7 @@ describe('choices', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('already initialised', () => {
|
||||
describe('when already initialised', () => {
|
||||
describe('containerOuter enabled', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = true;
|
||||
|
@ -282,7 +282,7 @@ describe('choices', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('already initialised', () => {
|
||||
describe('when already initialised', () => {
|
||||
describe('containerOuter disabled', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = true;
|
||||
|
@ -995,7 +995,7 @@ describe('choices', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('already initialised', () => {
|
||||
describe('when already initialised', () => {
|
||||
beforeEach(() => {
|
||||
instance.initialised = true;
|
||||
output = instance.setValue(values);
|
||||
|
@ -1036,7 +1036,7 @@ describe('choices', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('already initialised', () => {
|
||||
describe('when already initialised', () => {
|
||||
describe('passing a string value', () => {
|
||||
const value = 'Test value';
|
||||
|
||||
|
@ -1146,14 +1146,89 @@ describe('choices', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('renderGroups', () => {});
|
||||
describe('renderChoices', () => {});
|
||||
describe('renderItems', () => {});
|
||||
describe('render', () => {});
|
||||
describe('removeItemsByValue', () => {});
|
||||
describe('removeActiveItems', () => {});
|
||||
describe('removeHighlightedItems', () => {});
|
||||
describe('setChoices', () => {});
|
||||
describe('removeActiveItemsByValue', () => {
|
||||
beforeEach(() => {});
|
||||
it('removes each active item in store with matching value', () => {});
|
||||
});
|
||||
|
||||
describe('removeActiveItems', () => {
|
||||
beforeEach(() => {});
|
||||
it('removes each active item in store', () => {});
|
||||
});
|
||||
|
||||
describe('removeHighlightedItems', () => {
|
||||
beforeEach(() => {});
|
||||
it('removes each highlighted item in store', () => {});
|
||||
it('triggers event with item value if runEvent passed', () => {});
|
||||
});
|
||||
|
||||
describe('setChoices', () => {
|
||||
beforeEach(() => {});
|
||||
|
||||
describe('when not initialised', () => {});
|
||||
describe('when element is not select element', () => {});
|
||||
describe('when passing invalid arguments', () => {});
|
||||
|
||||
it('removes loading state', () => {});
|
||||
|
||||
describe('passing choices with children choices', () => {
|
||||
it('adds groups ', () => {});
|
||||
});
|
||||
|
||||
describe('passing choices without children choices', () => {
|
||||
it('adds passed choices', () => {});
|
||||
});
|
||||
|
||||
describe('passing truthy replaceChoices flag', () => {
|
||||
it('choices are cleared', () => {});
|
||||
});
|
||||
|
||||
describe('passing falsey replaceChoices flag', () => {
|
||||
it('choices are not cleared', () => {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('renderGroups', () => {
|
||||
beforeEach(() => {});
|
||||
it('returns a fragment of groups', () => {});
|
||||
});
|
||||
|
||||
describe('renderChoices', () => {
|
||||
beforeEach(() => {});
|
||||
it('returns a fragment of choices', () => {});
|
||||
});
|
||||
|
||||
describe('renderItems', () => {
|
||||
beforeEach(() => {});
|
||||
it('returns a fragment of items', () => {});
|
||||
});
|
||||
|
||||
describe('render', () => {
|
||||
beforeEach(() => {});
|
||||
|
||||
describe('no change to state', () => {
|
||||
it('returns early', () => {});
|
||||
});
|
||||
|
||||
describe('change to state', () => {
|
||||
it('updates previous state to current state', () => {});
|
||||
|
||||
describe('select element', () => {
|
||||
it('clears choice list', () => {});
|
||||
|
||||
describe('when resetScrollPosition config option is set to true', () => {
|
||||
it('scrolls to top of choice list', () => {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('text element', () => {
|
||||
describe('active items in store', () => {
|
||||
it('clears item list', () => {});
|
||||
it('renders active items inside item list', () => {});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('private methods', () => {
|
||||
|
|
Loading…
Reference in a new issue