2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-23 03:54:04 +03:00
Files
vue-select/tests/unit/Deselecting.spec.js
Owen Conti f9725919a4 V3 - Remove mutable class properties plus other misc changes (#781)
* Remove the mutableValue prop in the Select component.

* Add back mutable value when Vue Select has to manage its own value.

* Remove mutableOptions, valueAsAarray. Update webpack minifer to use Terser.

* Fix tabbing

* Fix bug with showClearButton

* Fix tests.

* Call clearSelection when possible

* Update dev sandbox to have all three options for setting value.

* Update dev sandbox to display current value

* Remove unused karma test setup.

* Revert onInput name change.

* Use coveralls

* Change this.internalValue to this.$data._value.

* Remove onInput prop and replace with internal method, updateValue.

* Update tests.

* Rename optionObjectComparator to optionComparator.
2019-03-23 11:25:31 -07:00

96 lines
2.7 KiB
JavaScript
Executable File

import { selectWithProps } from "../helpers";
describe("Removing values", () => {
it("can remove the given tag when its close icon is clicked", () => {
const Select = selectWithProps({ multiple: true });
Select.vm.$data._value = 'one';
Select.find(".vs__deselect").trigger("click");
expect(Select.emitted().input).toEqual([[[]]]);
expect(Select.vm.selectedValue).toEqual([]);
});
it("should not remove tag when close icon is clicked and component is disabled", () => {
const Select = selectWithProps({
value: ["one"],
options: ["one", "two", "three"],
multiple: true,
disabled: true
});
Select.find(".vs__deselect").trigger("click");
expect(Select.vm.selectedValue).toEqual(["one"]);
});
it("should remove the last item in the value array on delete keypress when multiple is true", () => {
const Select = selectWithProps({
multiple: true,
options: ["one", "two", "three"]
});
Select.vm.$data._value = ["one", "two"];
Select.find('.vs__search').trigger('keydown.backspace')
expect(Select.emitted().input).toEqual([[['one']]]);
expect(Select.vm.selectedValue).toEqual(["one"]);
});
it("should set value to null on delete keypress when multiple is false", () => {
const Select = selectWithProps({
options: ["one", "two", "three"]
});
Select.vm.$data._value = 'one';
Select.vm.maybeDeleteValue();
expect(Select.vm.selectedValue).toEqual([]);
});
describe("Clear button", () => {
it("should be displayed on single select when value is selected", () => {
const Select = selectWithProps({
options: ["foo", "bar"],
value: "foo"
});
expect(Select.vm.showClearButton).toEqual(true);
});
it("should not be displayed on multiple select", () => {
const Select = selectWithProps({
options: ["foo", "bar"],
value: "foo",
multiple: true
});
expect(Select.vm.showClearButton).toEqual(false);
});
it("should remove selected value when clicked", () => {
const Select = selectWithProps({
options: ["foo", "bar"],
});
Select.vm.$data._value = 'foo';
expect(Select.vm.selectedValue).toEqual(["foo"]);
Select.find("button.vs__clear").trigger("click");
expect(Select.emitted().input).toEqual([[null]]);
expect(Select.vm.selectedValue).toEqual([]);
});
it("should be disabled when component is disabled", () => {
const Select = selectWithProps({
options: ["foo", "bar"],
value: "foo",
disabled: true
});
expect(Select.find("button.vs__clear").attributes().disabled).toEqual(
"disabled"
);
});
});
});