Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vuetify/src/components/VSelect/VSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ export default baseMixins.extend({
const input = VTextField.methods.genInput.call(this)

delete input.props.name
delete input.props.placeholder

input.props = mergeData(input.props, {
readonly: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Components
import VSelect from '../VSelect'

// Utilities
import {
mount,
VueWrapper,
enableAutoUnmount
} from '@vue/test-utils'
import { h } from 'vue'

const statusItems = [{ text: 'Новый', value: 'new' }]

const baseProps = {
items: statusItems,
modelValue: 'new',
placeholder: 'Выберите статус',
label: ''
}

describe('VSelect placeholder при value', () => {
type Instance = InstanceType<typeof VSelect>
let mountFunction: (options?: object) => VueWrapper<Instance>
let el: HTMLDivElement

beforeEach(() => {
mountFunction = (options = {}) => {
el = document.createElement('div')
el.setAttribute('data-app', 'true')
document.body.appendChild(el)

return mount(VSelect, {
global: {
mocks: {
$vuetify: {
lang: {
t: (val: string) => val
},
theme: {
dark: false
},
icons: {
component: 'mdi'
}
}
}
},
attachTo: el,
...options
})
}
})

afterEach(() => {
if (el?.parentNode) {
document.body.removeChild(el)
}
})

enableAutoUnmount(afterEach)

function textInput (wrapper: VueWrapper<Instance>) {
return wrapper.find('input[type="text"]')
}

it('при value: isDirty и текст выбора корректны', () => {
const wrapper = mountFunction({ props: baseProps })

expect(wrapper.vm.isDirty).toBe(true)
expect(wrapper.find('.v-select__selection--comma').text()).toBe('Новый')
})

it('при value: на text-input нет атрибута placeholder', () => {
const wrapper = mountFunction({ props: baseProps })
const input = textInput(wrapper)

expect(input.exists()).toBe(true)
expect(input.attributes('placeholder')).toBeUndefined()
})

it('при пустом value: placeholder на text-input есть', () => {
const wrapper = mountFunction({
props: {
...baseProps,
modelValue: null
}
})
const input = textInput(wrapper)

expect(wrapper.vm.isDirty).toBe(false)
expect(input.attributes('placeholder')).toBe('Выберите статус')
})

it('со слотом #selection при value: placeholder на input отсутствует', () => {
const wrapper = mountFunction({
props: baseProps,
slots: {
selection: ({ item }: { item: { text: string } }) => h('span', item.text)
}
})
const input = textInput(wrapper)

expect(wrapper.text()).toContain('Новый')
expect(input.attributes('placeholder')).toBeUndefined()
})

it('при persistentPlaceholder и value: placeholder на input отсутствует', () => {
const wrapper = mountFunction({
props: {
...baseProps,
persistentPlaceholder: true
}
})
const input = textInput(wrapper)

expect(input.attributes('placeholder')).toBeUndefined()
})
})
Loading