mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
Complete deselecting spec
This commit is contained in:
+78
-108
@@ -1,117 +1,87 @@
|
|||||||
import { shallowMount } from "@vue/test-utils";
|
import { selectWithProps } from "../helpers";
|
||||||
import VueSelect from "../../src/components/Select";
|
|
||||||
|
|
||||||
describe("Removing values", () => {
|
describe("Removing values", () => {
|
||||||
it("can remove the given tag when its close icon is clicked", () => {
|
it("can remove the given tag when its close icon is clicked", () => {
|
||||||
const Select = shallowMount(VueSelect, {
|
const Select = selectWithProps({ multiple: true, value: ["foo"] });
|
||||||
propsData: { multiple: true, value: ["foo"] }
|
|
||||||
});
|
|
||||||
|
|
||||||
Select.find(".close").trigger("click");
|
Select.find(".close").trigger("click");
|
||||||
expect(Select.vm.mutableValue).toEqual([]);
|
expect(Select.vm.mutableValue).toEqual([]);
|
||||||
});
|
});
|
||||||
//
|
|
||||||
// it("should not remove tag when close icon is clicked and component is disabled", done => {
|
|
||||||
// const vm = new Vue({
|
|
||||||
// template:
|
|
||||||
// '<div><v-select disabled multiple :options="options" v-model="value"></v-select></div>',
|
|
||||||
// components: { vSelect },
|
|
||||||
// data: {
|
|
||||||
// value: ["one"],
|
|
||||||
// options: ["one", "two", "three"]
|
|
||||||
// }
|
|
||||||
// }).$mount();
|
|
||||||
// vm.$children[0].$refs.toggle.querySelector(".close").click();
|
|
||||||
// Vue.nextTick(() => {
|
|
||||||
// expect(vm.$children[0].mutableValue).toEqual(["one"]);
|
|
||||||
// done();
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it("should remove the last item in the value array on delete keypress when multiple is true", () => {
|
|
||||||
// const vm = new Vue({
|
|
||||||
// template:
|
|
||||||
// '<div><v-select :options="options" v-model="value" :multiple="true"></v-select></div>',
|
|
||||||
// components: { vSelect },
|
|
||||||
// data: {
|
|
||||||
// value: ["one", "two"],
|
|
||||||
// options: ["one", "two", "three"]
|
|
||||||
// }
|
|
||||||
// }).$mount();
|
|
||||||
// vm.$children[0].maybeDeleteValue();
|
|
||||||
// Vue.nextTick(() => {
|
|
||||||
// expect(vm.$children[0].mutableValue).toEqual(["one"]);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it("should set value to null on delete keypress when multiple is false", () => {
|
|
||||||
// const vm = new Vue({
|
|
||||||
// template:
|
|
||||||
// '<div><v-select :options="options" v-model="value"></v-select></div>',
|
|
||||||
// components: { vSelect },
|
|
||||||
// data: {
|
|
||||||
// value: "one",
|
|
||||||
// options: ["one", "two", "three"]
|
|
||||||
// }
|
|
||||||
// }).$mount();
|
|
||||||
// vm.$children[0].maybeDeleteValue();
|
|
||||||
// Vue.nextTick(() => {
|
|
||||||
// expect(vm.$children[0].mutableValue).toEqual(null);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// describe("Clear button", () => {
|
it("should not remove tag when close icon is clicked and component is disabled", () => {
|
||||||
// it("should be displayed on single select when value is selected", () => {
|
const Select = selectWithProps({
|
||||||
// const VueSelect = Vue.extend(vSelect);
|
value: ["one"],
|
||||||
// const vm = new VueSelect({
|
options: ["one", "two", "three"],
|
||||||
// propsData: {
|
multiple: true,
|
||||||
// options: ["foo", "bar"],
|
disabled: true
|
||||||
// value: "foo"
|
});
|
||||||
// }
|
|
||||||
// }).$mount();
|
Select.find(".close").trigger("click");
|
||||||
//
|
expect(Select.vm.mutableValue).toEqual(["one"]);
|
||||||
// expect(vm.showClearButton).toEqual(true);
|
});
|
||||||
// });
|
|
||||||
//
|
it("should remove the last item in the value array on delete keypress when multiple is true", () => {
|
||||||
// it("should not be displayed on multiple select", () => {
|
const Select = selectWithProps({
|
||||||
// const VueSelect = Vue.extend(vSelect);
|
multiple: true,
|
||||||
// const vm = new VueSelect({
|
value: ["one", "two"],
|
||||||
// propsData: {
|
options: ["one", "two", "three"]
|
||||||
// options: ["foo", "bar"],
|
});
|
||||||
// value: "foo",
|
|
||||||
// multiple: true
|
Select.vm.maybeDeleteValue();
|
||||||
// }
|
expect(Select.vm.mutableValue).toEqual(["one"]);
|
||||||
// }).$mount();
|
});
|
||||||
//
|
|
||||||
// expect(vm.showClearButton).toEqual(false);
|
it("should set value to null on delete keypress when multiple is false", () => {
|
||||||
// });
|
const Select = selectWithProps({
|
||||||
//
|
value: "one",
|
||||||
// it("should remove selected value when clicked", () => {
|
options: ["one", "two", "three"]
|
||||||
// const VueSelect = Vue.extend(vSelect);
|
});
|
||||||
// const vm = new VueSelect({
|
|
||||||
// propsData: {
|
Select.vm.maybeDeleteValue();
|
||||||
// options: ["foo", "bar"],
|
expect(Select.vm.mutableValue).toEqual(null);
|
||||||
// value: "foo"
|
});
|
||||||
// }
|
|
||||||
// }).$mount();
|
describe("Clear button", () => {
|
||||||
//
|
it("should be displayed on single select when value is selected", () => {
|
||||||
// expect(vm.mutableValue).toEqual("foo");
|
const Select = selectWithProps({
|
||||||
// vm.$el.querySelector("button.clear").click();
|
options: ["foo", "bar"],
|
||||||
// expect(vm.mutableValue).toEqual(null);
|
value: "foo"
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// it("should be disabled when component is disabled", () => {
|
expect(Select.vm.showClearButton).toEqual(true);
|
||||||
// const VueSelect = Vue.extend(vSelect);
|
});
|
||||||
// const vm = new VueSelect({
|
|
||||||
// propsData: {
|
it("should not be displayed on multiple select", () => {
|
||||||
// options: ["foo", "bar"],
|
const Select = selectWithProps({
|
||||||
// value: "foo",
|
options: ["foo", "bar"],
|
||||||
// disabled: true
|
value: "foo",
|
||||||
// }
|
multiple: true
|
||||||
// }).$mount();
|
});
|
||||||
//
|
|
||||||
// const buttonEl = vm.$el.querySelector("button.clear");
|
expect(Select.vm.showClearButton).toEqual(false);
|
||||||
// expect(buttonEl.disabled).toEqual(true);
|
});
|
||||||
// });
|
|
||||||
// });
|
it("should remove selected value when clicked", () => {
|
||||||
|
const Select = selectWithProps({
|
||||||
|
options: ["foo", "bar"],
|
||||||
|
value: "foo"
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(Select.vm.mutableValue).toEqual("foo");
|
||||||
|
Select.find("button.clear").trigger("click");
|
||||||
|
expect(Select.vm.mutableValue).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be disabled when component is disabled", () => {
|
||||||
|
const Select = selectWithProps({
|
||||||
|
options: ["foo", "bar"],
|
||||||
|
value: "foo",
|
||||||
|
disabled: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(Select.find("button.clear").attributes().disabled).toEqual(
|
||||||
|
"disabled"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user