mirror of
https://github.com/tenrok/vue-select.git
synced 2026-05-17 02:29:37 +03:00
feat: option selection events (#1324)
- `option:selecting` before state is set - `option:selected` after state is set - `option:deselecting` before state is set - `option:deselected` after state is set Co-authored-by: tiagoroldao <troldao@assurehedge.com> Co-authored-by: Jeff <sagalbot@gmail.com>
This commit is contained in:
@@ -220,5 +220,84 @@ describe("VS - Selecting Values", () => {
|
||||
Select.vm.select("bar");
|
||||
expect(Select.emitted("input")[0]).toEqual([["foo", "bar"]]);
|
||||
});
|
||||
|
||||
it("will not trigger the input event when multiple is true and selection is repeated", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { multiple: true, value: ["foo ", "bar"], options: ["foo", "bar", "baz"] }
|
||||
});
|
||||
|
||||
Select.vm.select("bar");
|
||||
expect(Select.emitted("input")).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("option:selecting Event", () => {
|
||||
it("will trigger the option:selecting event when an option is selected", () => {
|
||||
const Select = shallowMount(VueSelect);
|
||||
Select.vm.select("bar");
|
||||
expect(Select.emitted("option:selecting")[0]).toEqual(["bar"]);
|
||||
});
|
||||
|
||||
it("will trigger the option:selecting event regardless of current value", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { value: ["foo"], options: ["foo", "bar"] }
|
||||
});
|
||||
Select.vm.select("foo");
|
||||
Select.vm.select("bar");
|
||||
expect(Select.emitted("option:selecting")).toEqual([["foo"], ["bar"]]);
|
||||
});
|
||||
|
||||
it("will trigger the option:selecting event with current selected item when multiple is true", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { multiple: true, value: ["foo"], options: ["foo", "bar"] }
|
||||
});
|
||||
Select.vm.select("bar");
|
||||
expect(Select.emitted("option:selecting")[0]).toEqual(["bar"]);
|
||||
});
|
||||
|
||||
it("will trigger the option:selecting event regardless of current value when multiple is true", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { multiple: true, value: ["foo", "bar"], options: ["foo", "bar"] }
|
||||
});
|
||||
Select.vm.select("bar");
|
||||
Select.vm.select("bar");
|
||||
expect(Select.emitted("option:selecting")).toEqual([["bar"], ["bar"]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("option:deselected Event", () => {
|
||||
it("will trigger the option:deselected event when an option is deselected", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { value: ["foo"], options: ["foo", "bar"] }
|
||||
});
|
||||
Select.vm.deselect("foo");
|
||||
expect(Select.emitted("option:deselected")[0]).toEqual(["foo"]);
|
||||
});
|
||||
|
||||
it("will trigger the option:deselected event regardless of current value", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { value: ["foo"], options: ["foo", "bar"] }
|
||||
});
|
||||
Select.vm.deselect("foo");
|
||||
Select.vm.deselect("bar");
|
||||
expect(Select.emitted("option:deselected")).toEqual([["foo"], ["bar"]]);
|
||||
});
|
||||
|
||||
it("will trigger the option:selected event with current selected item when multiple is true", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { multiple: true, value: ["foo"], options: ["foo", "bar"] }
|
||||
});
|
||||
Select.vm.deselect("bar");
|
||||
expect(Select.emitted("option:deselected")[0]).toEqual(["bar"]);
|
||||
});
|
||||
|
||||
it("will trigger the option:selected event regardless of current value when multiple is true", () => {
|
||||
const Select = shallowMount(VueSelect, {
|
||||
propsData: { multiple: true, value: ["foo", "bar"], options: ["foo", "bar"] }
|
||||
});
|
||||
Select.vm.deselect("bar");
|
||||
Select.vm.deselect("bar");
|
||||
expect(Select.emitted("option:deselected")).toEqual([["bar"], ["bar"]]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user