2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-07 07:12:23 +03:00
Files
vue-select/tests/unit/Dropdown.spec.js
T
Jeff Sagal dc91310860 Sass & Class Renames (#759)
* - add autoprefixer
- add cssnano
- add postcss-loader
- remove unused packages

* create RTL scss module

* add vs__ prefix to open-indicator, extract to module

* module for dropdown-toggle

* vs__clear module

* vs__dropdown-menu module

* rename `selected-tag` to `vs__selected`

* remove rtl class

* remove dropdown class

* search-input scss module

* move animations to global module

* refactor dropdown list items

* - spinner slot is now scoped with `loading` variable
- move spinner to scss module

* apply vs__search class directly to search input: if you're using the slot, you might not want default styles

* finish global modules

* make RTL a component state

* - update component states to use vs-- prefix
- rename dropdownClasses to stateClasses

* remove unused property

* Closes #760

* fix states

* more state fixes

* rename .close to vs__deselect

* - simplify dev.html
- start on 'sandbox' development

* update build

* - update webpack config
- move Sandbox to VuePress folder

* update external framework version links

* assign grid areas, ensure 100% height outside of docs

* limit specificity

* first pass at assigning variables

* assign 'darkest'

* remove max-height prop

* rename 'component' variables to 'state'

* update badges

* add deprecation notice to docs

* bump travis config

* add coveralls coverage reporter

* bump netlify config

* additional pass pulling up to variables

* start converting to SVG icons

* middle align action icons

* update netlify config

* netlify bump

* fix travis

* fix travis

* try lcov

* netlify attempt

* prune old packages

* bump travis config
2019-02-18 22:01:39 -08:00

136 lines
3.9 KiB
JavaScript
Executable File

import { selectWithProps } from "../helpers";
describe("Toggling Dropdown", () => {
it("should not open the dropdown when the el is clicked but the component is disabled", () => {
const Select = selectWithProps({ disabled: true });
Select.vm.toggleDropdown({ target: Select.vm.$refs.search });
expect(Select.vm.open).toEqual(false);
});
it("should open the dropdown when the el is clicked", () => {
const Select = selectWithProps({
value: [{ label: "one" }],
options: [{ label: "one" }]
});
Select.vm.toggleDropdown({ target: Select.vm.$refs.search });
expect(Select.vm.open).toEqual(true);
});
it("should open the dropdown when the selected tag is clicked", () => {
const Select = selectWithProps({
value: [{ label: "one" }],
options: [{ label: "one" }]
});
const selectedTag = Select.find(".vs__selected").element;
Select.vm.toggleDropdown({ target: selectedTag });
expect(Select.vm.open).toEqual(true);
});
it("can close the dropdown when the el is clicked", () => {
const Select = selectWithProps();
const spy = jest.spyOn(Select.vm.$refs.search, "blur");
Select.vm.open = true;
Select.vm.toggleDropdown({ target: Select.vm.$el });
expect(spy).toHaveBeenCalled();
});
it("closes the dropdown when an option is selected, multiple is true, and closeOnSelect option is true", () => {
const Select = selectWithProps({
value: [],
options: ["one", "two", "three"],
multiple: true
});
Select.vm.open = true;
Select.vm.select("one");
expect(Select.vm.open).toEqual(false);
});
it("does not close the dropdown when the el is clicked, multiple is true, and closeOnSelect option is false", () => {
const Select = selectWithProps({
value: [],
options: ["one", "two", "three"],
multiple: true,
closeOnSelect: false
});
// const vm = new Vue({
// template:
// '<div><v-select ref="select" :options="options" multiple :closeOnSelect="false" :value="value"></v-select></div>',
// components: { vSelect },
// }).$mount();
Select.vm.open = true;
Select.vm.select("one");
expect(Select.vm.open).toEqual(true);
});
it("should close the dropdown on search blur", () => {
const Select = selectWithProps({
options: [{ label: "one" }]
});
Select.vm.open = true;
Select.find({ ref: "search" }).trigger("blur");
expect(Select.vm.open).toEqual(false);
});
it("will close the dropdown and emit the search:blur event from onSearchBlur", () => {
const Select = selectWithProps();
const spy = jest.spyOn(Select.vm, "$emit");
Select.vm.open = true;
Select.vm.onSearchBlur();
expect(Select.vm.open).toEqual(false);
expect(spy).toHaveBeenCalledWith("search:blur");
});
it("will open the dropdown and emit the search:focus event from onSearchFocus", () => {
const Select = selectWithProps();
const spy = jest.spyOn(Select.vm, "$emit");
Select.vm.onSearchFocus();
expect(Select.vm.open).toEqual(true);
expect(spy).toHaveBeenCalledWith("search:focus");
});
it("will close the dropdown on escape, if search is empty", () => {
const Select = selectWithProps();
const spy = jest.spyOn(Select.vm.$refs.search, "blur");
Select.vm.open = true;
Select.vm.onEscape();
expect(spy).toHaveBeenCalled();
});
it("should remove existing search text on escape keyup", () => {
const Select = selectWithProps({
value: [{ label: "one" }],
options: [{ label: "one" }]
});
Select.vm.search = "foo";
Select.vm.onEscape();
expect(Select.vm.search).toEqual("");
});
it("should have an open class when dropdown is active", () => {
const Select = selectWithProps();
expect(Select.vm.stateClasses['vs--open']).toEqual(false);
Select.vm.open = true;
expect(Select.vm.stateClasses['vs--open']).toEqual(true);
});
});