mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-02 05:52:46 +02:00
Fixes an issue where deepmerge concatenates array configs (#496)
This commit is contained in:
parent
826384b9d5
commit
9c001487ba
|
@ -853,5 +853,35 @@ describe('Choices - select multiple', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('searching by label only', () => {
|
||||
it('gets zero results when searching by value', () => {
|
||||
cy.get('[data-test-hook=search-by-label]')
|
||||
.find('.choices__input--cloned')
|
||||
.type('value1');
|
||||
|
||||
cy.get('[data-test-hook=search-by-label]')
|
||||
.find('.choices__list--dropdown .choices__list')
|
||||
.children()
|
||||
.first()
|
||||
.should($choice => {
|
||||
expect($choice.text().trim()).to.equal('No results found');
|
||||
});
|
||||
});
|
||||
|
||||
it('gets a result when searching by label', () => {
|
||||
cy.get('[data-test-hook=search-by-label]')
|
||||
.find('.choices__input--cloned')
|
||||
.type('label1');
|
||||
|
||||
cy.get('[data-test-hook=search-by-label]')
|
||||
.find('.choices__list--dropdown .choices__list')
|
||||
.children()
|
||||
.first()
|
||||
.should($choice => {
|
||||
expect($choice.text().trim()).to.equal('label1');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -867,5 +867,41 @@ describe('Choices - select one', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('searching by label only', () => {
|
||||
beforeEach(() => {
|
||||
cy.get('[data-test-hook=search-by-label]')
|
||||
.find('.choices')
|
||||
.click();
|
||||
});
|
||||
|
||||
it('gets zero results when searching by value', () => {
|
||||
cy.get('[data-test-hook=search-by-label]')
|
||||
.find('.choices__input--cloned')
|
||||
.type('value1');
|
||||
|
||||
cy.get('[data-test-hook=search-by-label]')
|
||||
.find('.choices__list--dropdown .choices__list')
|
||||
.children()
|
||||
.first()
|
||||
.should($choice => {
|
||||
expect($choice.text().trim()).to.equal('No results found');
|
||||
});
|
||||
});
|
||||
|
||||
it('gets a result when searching by label', () => {
|
||||
cy.get('[data-test-hook=search-by-label]')
|
||||
.find('.choices__input--cloned')
|
||||
.type('label1');
|
||||
|
||||
cy.get('[data-test-hook=search-by-label]')
|
||||
.find('.choices__list--dropdown .choices__list')
|
||||
.children()
|
||||
.first()
|
||||
.should($choice => {
|
||||
expect($choice.text().trim()).to.equal('label1');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -194,6 +194,14 @@
|
|||
<option value="Choice 3">Choice 3</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div data-test-hook="search-by-label">
|
||||
<label for="choices-search-by-label">Search by label</label>
|
||||
<select class="form-control" name="choices-search-by-label" id="choices-search-by-label" multiple>
|
||||
<option value="value1">label1</option>
|
||||
<option value="value2">label2</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
@ -307,6 +315,8 @@
|
|||
new Choices('#choices-within-form');
|
||||
|
||||
new Choices('#choices-set-choice-by-value').setChoiceByValue('Choice 2');
|
||||
|
||||
new Choices('#choices-search-by-label', { searchFields: ['label'] });
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -198,6 +198,14 @@
|
|||
<option value="Choice 3">Choice 3</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div data-test-hook="search-by-label">
|
||||
<label for="choices-search-by-label">Search by label</label>
|
||||
<select class="form-control" name="choices-search-by-label" id="choices-search-by-label">
|
||||
<option value="value1">label1</option>
|
||||
<option value="value2">label2</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
@ -319,6 +327,8 @@
|
|||
new Choices('#choices-within-form');
|
||||
|
||||
new Choices('#choices-set-choice-by-value').setChoiceByValue('Choice 2');
|
||||
|
||||
new Choices('#choices-search-by-label', { searchFields: ['label'] });
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -56,7 +56,12 @@ class Choices {
|
|||
}
|
||||
}
|
||||
|
||||
this.config = merge.all([DEFAULT_CONFIG, Choices.userDefaults, userConfig]);
|
||||
this.config = merge.all(
|
||||
[DEFAULT_CONFIG, Choices.userDefaults, userConfig],
|
||||
// When merging array configs, replace with a copy of the userConfig array,
|
||||
// instead of concatenating with the default array
|
||||
{ arrayMerge: (destinationArray, sourceArray) => [...sourceArray] },
|
||||
);
|
||||
|
||||
if (!doKeysMatch(this.config, DEFAULT_CONFIG)) {
|
||||
console.warn('Unknown config option(s) passed');
|
||||
|
|
Loading…
Reference in a new issue