Skip to content

Commit

Permalink
feat: Add data-test for the select element
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume60240 committed Oct 30, 2023
1 parent 989dd65 commit 8775790
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/components/select/src/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const optionProps = buildProps({
required: false,
default: false,
},
optionDataTest: {
type: String,
required: false,
},
} as const)

export type OptionProps = ExtractPropTypes<typeof optionProps>
Expand Down
1 change: 1 addition & 0 deletions packages/components/select/src/option.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'puik-option--selected': selectedValue === value,
'puik-option--disabled': disabled,
}"
:data-test="optionDataTest"
>
<slot class="puik-option__label">{{ label }}</slot>
<puik-icon
Expand Down
15 changes: 15 additions & 0 deletions packages/components/select/src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ export const selectProps = buildProps({
required: false,
default: true,
},
selectDataTest: {
type: String,
required: false,
default: undefined,
},
searchInputDataTest: {
type: String,
required: false,
default: undefined,
},
noResultsDataTest: {
type: String,
required: false,
default: undefined,
},
} as const)

export type SelectProps = ExtractPropTypes<typeof selectProps>
Expand Down
6 changes: 5 additions & 1 deletion packages/components/select/src/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
tabindex="-1"
:readonly="open"
type="text"
:data-test="selectDataTest"
@input="
handleAutoComplete(($event.target as HTMLInputElement)?.value)
"
Expand Down Expand Up @@ -53,6 +54,7 @@
v-model="query"
class="puik-select__search"
:placeholder="t('puik.select.searchPlaceholder')"
:input-data-test="searchInputDataTest"
>
<template #prepend
><puik-icon
Expand All @@ -69,17 +71,19 @@
: !filteredItems?.length)
"
class="puik-select__no-results"
:data-test="noResultsDataTest"
>
{{ noMatchText || `${t('puik.select.noResults')} ${query}` }}
</p>
<ul class="puik-select__options-list">
<slot :options="filteredItems">
<template v-if="options">
<puik-option
v-for="option in filteredItems"
v-for="(option, index) in filteredItems"
:key="option"
:label="option[labelKey]"
:value="isObject(option) ? option[valueKey] : option"
:option-data-test="`dataTestOption-${index + 1}`"
/>
</template>
</slot>
Expand Down
21 changes: 21 additions & 0 deletions packages/components/select/stories/select.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ export default {
category: 'Common',
},
},
selectDataTest: {
control: 'text',
description: 'Set the data-test attribute for the select',
table: {
category: 'Common',
},
},
searchInputDataTest: {
control: 'text',
description: 'Set the data-test attribute for the search input',
table: {
category: 'Searchable',
},
},
noResultsDataTest: {
control: 'text',
description: 'Set the data-test attribute for the no results message',
table: {
category: 'Searchable',
},
},
},
args: {
labelKey: '',
Expand Down

0 comments on commit 8775790

Please sign in to comment.