-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[full-ci] Introduce read-only options to OcSelect (#8727)
- Loading branch information
1 parent
c47e18e
commit 9f87057
Showing
9 changed files
with
231 additions
and
64 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/design-system/changelog/unreleased/enhancement-read-only-select-options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Enhancement: Read-only select options | ||
|
||
The `OcSelect` component now supports read-only select options which can't be removed if selected. | ||
|
||
https://github.com/owncloud/web/issues/8729 | ||
https://github.com/owncloud/web/pull/8727 |
94 changes: 94 additions & 0 deletions
94
packages/design-system/src/components/OcSelect/OcSelect.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { defaultPlugins, mount } from 'web-test-helpers' | ||
import OcSelect from './OcSelect.vue' | ||
|
||
const selectors = { | ||
ocSelect: '.oc-select', | ||
selectedOptions: '.vs__selected-options .vs__selected', | ||
deselectBtn: '.vs__selected-options .vs__deselect', | ||
deselectLockIcon: '.vs__deselect-lock', | ||
clearBtn: '.vs__clear', | ||
searchInput: '.vs__search', | ||
ocSpinner: '.oc-spinner', | ||
warningMessage: '.oc-text-input-warning', | ||
errorMessage: '.oc-text-input-danger', | ||
descriptionMessage: '.oc-text-input-description' | ||
} | ||
|
||
describe('OcSelect', () => { | ||
it('passes the options to the vue-select component', () => { | ||
const options = [{ label: 'label1' }, { label: 'label2' }] | ||
const wrapper = getWrapper({ options }) | ||
expect(wrapper.findComponent<any>(selectors.ocSelect).props('options')).toEqual(options) | ||
}) | ||
it('shows ocSpinner component when loading', () => { | ||
const wrapper = getWrapper({ loading: true }) | ||
expect(wrapper.find(selectors.ocSpinner).exists()).toBeTruthy() | ||
}) | ||
it('triggers the "search:input"-event on search input', async () => { | ||
const wrapper = getWrapper() | ||
await wrapper.find(selectors.searchInput).trigger('input') | ||
expect(wrapper.emitted('search:input')).toBeDefined() | ||
}) | ||
describe('clear button', () => { | ||
it('is hidden by default', () => { | ||
const options = [{ label: 'label1' }, { label: 'label2' }] | ||
const wrapper = getWrapper({ options, modelValue: options[0] }) | ||
expect(wrapper.find(selectors.clearBtn).attributes('style')).toEqual('display: none;') | ||
}) | ||
it('is visible if "clearable" is set to true', () => { | ||
const options = [{ label: 'label1' }, { label: 'label2' }] | ||
const wrapper = getWrapper({ options, modelValue: options[0], clearable: true }) | ||
expect(wrapper.find(selectors.clearBtn).attributes('style')).toBeUndefined() | ||
}) | ||
}) | ||
describe('selected option', () => { | ||
it('displays', () => { | ||
const options = [{ label: 'label1' }, { label: 'label2' }] | ||
const wrapper = getWrapper({ options, modelValue: options[0] }) | ||
expect(wrapper.findAll(selectors.selectedOptions).length).toBe(1) | ||
expect(wrapper.findAll(selectors.selectedOptions).at(0).text()).toEqual(options[0].label) | ||
}) | ||
it('displays with a custom label property', () => { | ||
const options = [{ customLabel: 'label1' }, { customLabel: 'label2' }] | ||
const wrapper = getWrapper({ options, modelValue: options[0], optionLabel: 'customLabel' }) | ||
expect(wrapper.findAll(selectors.selectedOptions).at(0).text()).toEqual( | ||
options[0].customLabel | ||
) | ||
}) | ||
it('can be cleared if multi-select is allowed', () => { | ||
const options = [{ label: 'label1' }, { label: 'label2' }] | ||
const wrapper = getWrapper({ options, modelValue: options[0], multiple: true }) | ||
expect(wrapper.find(selectors.deselectBtn).exists()).toBeTruthy() | ||
expect(wrapper.find(selectors.deselectLockIcon).exists()).toBeFalsy() | ||
}) | ||
it('can not be cleared if readonly', () => { | ||
const options = [{ label: 'label1', readonly: true }, { label: 'label2' }] | ||
const wrapper = getWrapper({ options, modelValue: options[0], multiple: true }) | ||
expect(wrapper.find(selectors.deselectBtn).exists()).toBeFalsy() | ||
expect(wrapper.find(selectors.deselectLockIcon).exists()).toBeTruthy() | ||
}) | ||
}) | ||
describe('message', () => { | ||
it('displays a warning message', () => { | ||
const wrapper = getWrapper({ warningMessage: 'foo' }) | ||
expect(wrapper.find(selectors.warningMessage).exists()).toBeTruthy() | ||
}) | ||
it('displays an error message', () => { | ||
const wrapper = getWrapper({ errorMessage: 'foo' }) | ||
expect(wrapper.find(selectors.errorMessage).exists()).toBeTruthy() | ||
}) | ||
it('displays a description message', () => { | ||
const wrapper = getWrapper({ descriptionMessage: 'foo' }) | ||
expect(wrapper.find(selectors.descriptionMessage).exists()).toBeTruthy() | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper(props = {}) { | ||
return mount(OcSelect, { | ||
props, | ||
global: { | ||
plugins: [...defaultPlugins()] | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.