Skip to content

Commit

Permalink
Merge pull request #471 from storyblok/feat/work-1388-add-data-testid…
Browse files Browse the repository at this point in the history
…-in-datepicker-and-more

refactor(WORK-1388): add data-testid in datepicker and textfield
  • Loading branch information
ademarCardoso authored Nov 8, 2023
2 parents 0303efd + 0a66c67 commit 302e873
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/DataTable/components/SbDataTableHeader.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<thead :data-testid="dataTestid">
<tr>
<tr :data-testid="`${dataTestid}-list-column`">
<th
v-if="allowSelection && isMultiple"
class="sb-data-table__head-cell"
Expand Down
9 changes: 9 additions & 0 deletions src/components/Datepicker/Datepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
:model-value="internalValueFormatted"
:error="invalidDate"
:inline-label="inlineLabel"
:data-testid="`${baseDataTestId}-input`"
clearable
@icon-click="handleInputClick"
@clear="handleClear"
Expand Down Expand Up @@ -51,6 +52,7 @@
isMonthView,
isTimeView,
modelValue: internalDate,
dataTestid: baseDataTestId,
}"
@previous-month="handlePreviousMonth"
@next-month="handleNextMonth"
Expand All @@ -66,20 +68,23 @@
:max-date="maxDate"
:minute-range="minuteRange"
:disabled-past="disabledPast"
:data-testid="baseDataTestId"
@update:model-value="handleComponentsInput"
@input-minutes="handleMinutesInput"
/>

<div class="sb-datepicker__actions">
<button
class="sb-datepicker__action-button"
:data-testid="`${baseDataTestId}-cancel`"
@click="handleCancelAction"
>
Cancel
</button>

<button
class="sb-datepicker__action-button sb-datepicker__action-button--primary"
:data-testid="`${baseDataTestId}-apply`"
@click="handleDoneAction"
>
Apply
Expand Down Expand Up @@ -219,6 +224,10 @@ export default {
}),
computed: {
baseDataTestId() {
const dataTestid = this.$attrs['data-testid']
return dataTestid ? dataTestid : 'sb-datepicker'
},
isInputReadonly() {
return this.minuteRange > 1
},
Expand Down
12 changes: 12 additions & 0 deletions src/components/Datepicker/components/DatepickerDays.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'sb-datepicker-days__item--current': dayItem.current,
'sb-datepicker-days__item--disabled': dayItem.disabled,
}"
:data-testid="dayItem.dataTestid"
@click="($evt) => handleDayClick($evt, dayItem)"
>
{{ dayItem.label }}
Expand Down Expand Up @@ -44,6 +45,10 @@ export default {
type: Boolean,
default: false,
},
dataTestid: {
type: String,
default: null,
},
},
emits: ['update:modelValue'],
Expand All @@ -64,6 +69,7 @@ export default {
checked: false,
current: false,
disabled: this.isDisabledDay(dateValue),
dataTestid: this.getDataTestid(dateValue),
})
}
Expand All @@ -77,6 +83,7 @@ export default {
checked: dayjs(this.modelValue).isSame(dateValue, 'day'),
current: dayjs().isSame(dateValue, 'day'),
disabled: this.isDisabledDay(dateValue),
dataTestid: this.getDataTestid(dateValue),
})
}
Expand All @@ -91,6 +98,7 @@ export default {
checked: false,
current: false,
disabled: this.isDisabledDay(dateValue),
dataTestid: this.getDataTestid(dateValue),
})
}
Expand Down Expand Up @@ -134,6 +142,10 @@ export default {
this.isMaxDateDisabled(dateValue)
)
},
getDataTestid(date) {
return `${this.dataTestid}-day-${dayjs(date).format('MM-DD-YYYY')}`
},
},
}
</script>
6 changes: 6 additions & 0 deletions src/components/Datepicker/components/DatepickerHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<button
class="sb-datepicker-header__button"
:disabled="isDisabled"
:data-testid="`${dataTestid}-header-previous-month`"
@click="handlePreviousClick"
>
<SbIcon name="chevron-left" :color="iconColor" />
Expand All @@ -30,6 +31,7 @@
<button
class="sb-datepicker-header__button"
:disabled="isDisabled"
:data-testid="`${dataTestid}-header-next-month`"
@click="handleNextClick"
>
<SbIcon name="chevron-right" :color="iconColor" />
Expand Down Expand Up @@ -65,6 +67,10 @@ export default {
type: String,
default: null,
},
dataTestid: {
type: String,
default: null,
},
},
emits: ['change-month', 'change-year', 'next-month', 'previous-month'],
Expand Down
6 changes: 6 additions & 0 deletions src/components/Datepicker/components/DatepickerMonths.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:key="index"
class="sb-datepicker-months__item"
:class="{ 'sb-datepicker-months__item--active': monthItem.checked }"
:data-testid="monthItem.dataTestid"
@click="($evt) => handleMonthClick($evt, monthItem.label)"
>
{{ monthItem.label }}
Expand All @@ -26,6 +27,10 @@ export default {
type: String,
default: null,
},
dataTestid: {
type: String,
default: null,
},
},
emits: ['update:modelValue'],
Expand Down Expand Up @@ -53,6 +58,7 @@ export default {
return {
checked: dayjs(this.internalDate).format('MMM') === month,
label: month,
dataTestid: `${this.dataTestid}-month-${month}`,
}
})
},
Expand Down
6 changes: 6 additions & 0 deletions src/components/Datepicker/components/DatepickerYears.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:key="index"
class="sb-datepicker-years__item"
:class="{ 'sb-datepicker-years__item--active': yearItem.checked }"
:data-testid="yearItem.dataTestid"
@click="($evt) => handleYearClick($evt, yearItem.label)"
>
{{ yearItem.label }}
Expand All @@ -27,6 +28,10 @@ export default {
type: String,
default: null,
},
dataTestid: {
type: String,
default: null,
},
},
emits: ['update:modelValue'],
Expand All @@ -45,6 +50,7 @@ export default {
return {
label: year,
checked: year === this.currentYear,
dataTestid: `${this.dataTestid}-year-${year}`,
}
})
},
Expand Down
15 changes: 11 additions & 4 deletions src/components/TextField/SbTextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<span
v-if="inlineLabel"
class="sb-textfield__inner-label"
:data-testid="baseDataTestId"
@click="$refs.textfield.focus()"
>
{{ inlineLabel }}
Expand Down Expand Up @@ -69,7 +70,7 @@
:name="iconLeft"
class="sb-textfield__icon sb-textfield__icon--left"
:color="iconColor"
data-testid="sb-textfield-icon-click"
:data-testid="`${baseDataTestId}-icon-click`"
@click="handleIconClick"
/>
<SbTooltip
Expand All @@ -83,7 +84,7 @@
:name="iconLeft"
class="sb-textfield__icon sb-textfield__icon--left"
:color="iconColor"
data-testid="sb-textfield-icon-click"
:data-testid="`${baseDataTestId}-icon-click`"
@click="handleIconClick"
/>
</SbTooltip>
Expand All @@ -92,15 +93,15 @@
:name="iconRight"
class="sb-textfield__icon sb-textfield__icon--right"
:color="iconColor"
data-testid="sb-textfield-icon-click"
:data-testid="`${baseDataTestId}-icon-click`"
@click="handleIconClick"
/>
<SbIcon
v-if="internalIconRight && type === 'password'"
:name="internalIconRight"
class="sb-textfield__icon sb-textfield__icon--right"
:color="iconColor"
data-testid="sb-textfield-icon-click"
:data-testid="`${baseDataTestId}-icon-click`"
@click="handleShowHidePassword"
/>
<SbIcon
Expand All @@ -109,6 +110,7 @@
name="x-clear"
:class="computedClearIconClasses"
:color="iconColor"
:data-testid="`${baseDataTestId}-icon-clear`"
@click="handleClearableClick"
/>
</div>
Expand Down Expand Up @@ -191,6 +193,11 @@ export default {
],
computed: {
baseDataTestId() {
const dataTestid = this.$attrs['data-testid']
return dataTestid ? dataTestid : 'sb-textfield'
},
hasValue() {
return this.computedValue !== null && ('' + this.computedValue).length > 0
},
Expand Down

0 comments on commit 302e873

Please sign in to comment.