Skip to content

Commit

Permalink
fix: hide the clear button if the field is disabled (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDASILVA authored Jun 20, 2020
1 parent 688211a commit 586635a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/VueCtkDateTimePicker/_subs/CustomInput/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
: null
},
hasClearButton () {
return !this.noClearButton && !this.disabled && this.value
return !this.noClearButton && !this.isDisabled && this.value
},
/**
* Returns true if the field is disabled
Expand Down
59 changes: 59 additions & 0 deletions tests/unit/VueCtkDateTimePicker/CustomInput/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { shallowMount } from '@vue/test-utils'

import CustomInput from '@/VueCtkDateTimePicker/_subs/CustomInput'
import CustomButton from '@/VueCtkDateTimePicker/_subs/CustomButton'

describe('VueCtkDateTimePicker/CustomInput', () => {
let wrapper
Expand Down Expand Up @@ -72,6 +73,64 @@ describe('VueCtkDateTimePicker/CustomInput', () => {
/**
* TODO: Add clear button test cases
*/
describe('clear button', () => {
it('should be defined if the "noClearButton" prop is not defined, the input is not disabled and there is a value', () => {
const wrapper = shallowMount(CustomInput, {
propsData: {
value: '2020-06-20 12:00:00',
noClearButton: false
},
attrs: {
disabled: false
}
})

const button = wrapper.find(CustomButton)
expect(button.exists()).toBeTruthy()
expect(button.is(CustomButton)).toBeTruthy()
})

it('should undefined if the "noClearButton" prop is defined or the input is disabled or there is no value', () => {
let wrapper = shallowMount(CustomInput, {
propsData: {
value: '2020-06-20 12:00:00',
noClearButton: true
},
attrs: {
disabled: false
}
})

let button = wrapper.find('.field-clear-button')
expect(button.exists()).toBeFalsy()

wrapper = shallowMount(CustomInput, {
propsData: {
value: null,
noClearButton: false
},
attrs: {
disabled: false
}
})

button = wrapper.find('.field-clear-button')
expect(button.exists()).toBeFalsy()

wrapper = shallowMount(CustomInput, {
propsData: {
value: '2020-06-20 12:00:00',
noClearButton: false
},
attrs: {
disabled: true
}
})

button = wrapper.find('.field-clear-button')
expect(button.exists()).toBeFalsy()
})
})

afterEach(() => {
wrapper.destroy()
Expand Down

0 comments on commit 586635a

Please sign in to comment.