Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/date picker change delete system #3670

Merged
merged 2 commits into from
Jul 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ exports[`FormBuilder > renders correctly 1`] = `
</div>
<div data-v-9067cb71="" class="vd-form-field">
<!--v-if-->
<!--v-if-->
<div data-v-2a54188f="" data-v-9067cb71="" class="vd-date-picker vd-form-input mt-4" variant="outlined" textfield="[object Object]">
<!--v-if--> Date: - inputValue: <div data-v-2a54188f="" class="vd-date-picker">
<!-- doc: https://vue3datepicker.com-->
<div data-v-2a54188f="" class="dp__main dp__theme_light" data-datepicker-instance="">
<div>
Expand Down
20 changes: 5 additions & 15 deletions packages/synapse-bridge/src/patterns/DatePicker/DatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ export default defineComponent({
if (newVal) {
this.lastTypeAddedDate = 'date'
this.$emit('change', newVal)
if (newVal.length === 10) {
this.validate(newVal)
}
if (typeof newVal === 'string' && newVal.length === 10) {
this.$emit('update:model-value', this.formatDate(newVal))
}
Expand All @@ -239,6 +236,7 @@ export default defineComponent({
)
if (newVal.length === 10) {
this.validate(newVal)
this.inputValue = newVal
}
} else if (
typeof newVal === 'string' &&
Expand Down Expand Up @@ -296,6 +294,7 @@ export default defineComponent({
if (typeof this.modelValue === 'string') {
const [day, month, year] = this.modelValue.split(/[-/]/)
this.date = new Date(Number(year), Number(month) - 1, Number(day))
this.inputValue = this.modelValue
}
},
methods: {
Expand Down Expand Up @@ -526,18 +525,11 @@ export default defineComponent({
? 'underlined'
: 'outlined'
},
onClear() {
onClearInput() {
this.date = null
this.inputValue = ''
this.$emit('update:model-value', null)
},
handleKeyDown(event: KeyboardEvent) {
if (event.key === 'Backspace' || event.key === 'Delete') {
this.inputValue = ''
this.date = null
this.$emit('update:model-value', null)
}
},
async handleCut(event?: ClipboardEvent) {
if (event && event.clipboardData) {
this.inputValue = '';
Expand Down Expand Up @@ -596,7 +588,7 @@ export default defineComponent({
{{ date.getDate() }}
</div>
</template>
<template #dp-input="{onClear}">
<template #dp-input="{}">
<VTextField
:model-value="date"
v-bind="textFieldOptions"
Expand Down Expand Up @@ -626,8 +618,6 @@ export default defineComponent({
"
:variant="getVariant"
@blur="emitUpdateEvent"
@keydown="handleKeyDown"
@click:clear="onClear"
@paste="handlePaste"
@cut="handleCut"
>
Expand All @@ -653,7 +643,7 @@ export default defineComponent({

<template v-slot:clear v-if="clearable" >
<VIcon
@click='onClear'
@click='onClearInput'
tabindex="-1"
aria-hidden="true"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,6 @@ describe('Methods', () => {
expect(wrapper.vm.determineVariant()).toEqual('underlined')
})

it('emits update:model-value event with null when onClear is called', () => {
const wrapper = shallowMount(DatePicker)
wrapper.vm.onClear()
const emittedEvent = wrapper.emitted('update:model-value')
expect(emittedEvent).toBeTruthy()
if (emittedEvent) {
expect(emittedEvent[1]).toEqual([null])
}
})

it('returns correct formatted date when formatDate is called', () => {
const wrapper = shallowMount(DatePicker)
const date = new Date(2023, 3, 15) // April 15, 2023
Expand Down Expand Up @@ -658,18 +648,6 @@ describe('Mounted', () => {

expect(wrapper.vm.errorMessages).toContain('Une erreur est survenue')
})
it('calls handleKeyDown with correct arguments when handleKeyDown Backspace is called', async () => {
const wrapper = shallowMount(DatePicker)
const handleKeyDownMock = vi.fn()
wrapper.vm.handleKeyDown = handleKeyDownMock
const mockEvent = { key: 'Backspace' }
wrapper.vm.handleKeyDown(<KeyboardEvent>mockEvent)
expect(handleKeyDownMock).toHaveBeenCalledWith(mockEvent)

expect(wrapper.emitted('update:model-value')).toStrictEqual([[null]])
expect(wrapper.vm.date).toBe(null)
expect(wrapper.vm.inputValue).toBe('')
})

it('handleCut method updates state and clipboard correctly', async () => {
const wrapper = shallowMount(DatePicker)
Expand Down
Loading