diff --git a/packages/components/accordion/src/accordion.ts b/packages/components/accordion/src/accordion.ts index 8c14194e..bf71a2b1 100644 --- a/packages/components/accordion/src/accordion.ts +++ b/packages/components/accordion/src/accordion.ts @@ -27,6 +27,11 @@ export const accordionProps = buildProps({ required: false, default: false, }, + dataTest: { + type: String, + required: false, + default: undefined, + }, } as const) export const accordionEmits = ['click'] diff --git a/packages/components/accordion/src/accordion.vue b/packages/components/accordion/src/accordion.vue index bebae64a..c54e078f 100644 --- a/packages/components/accordion/src/accordion.vue +++ b/packages/components/accordion/src/accordion.vue @@ -11,6 +11,7 @@ :aria-controls="id" class="puik-accordion__header" :disabled="disabled" + :data-test="dataTest != undefined ? `button-${dataTest}` : undefined" @click="onClick" >
-
{{ title }}
-
+
+ {{ title }} +
+
{{ subTitle }}
diff --git a/packages/components/accordion/stories/accordion.stories.ts b/packages/components/accordion/stories/accordion.stories.ts index 9bd358e2..d9160e08 100644 --- a/packages/components/accordion/stories/accordion.stories.ts +++ b/packages/components/accordion/stories/accordion.stories.ts @@ -36,6 +36,11 @@ export default { control: 'none', description: 'Accordion content', }, + dataTest: { + control: 'text', + description: + 'Set the data-test attribute for the accordion `button-${dataTest}` `title-${dataTest}` `icon-${dataTest}` `subTitle-${dataTest}`', + }, }, } as Meta diff --git a/packages/components/accordion/test/accordion.spec.ts b/packages/components/accordion/test/accordion.spec.ts index 1605a99d..456b9aee 100644 --- a/packages/components/accordion/test/accordion.spec.ts +++ b/packages/components/accordion/test/accordion.spec.ts @@ -152,4 +152,29 @@ describe('Accordion tests', () => { expect(getAccordionIcon(wrapper).text()).toBe(icon) }) + + it('should have data-test attribute on button, title, sub-title, icon', () => { + const template = ` + + + Content + + + ` + factory(template) + + const accordion = getAccordion(wrapper) + expect(getAccordionHeader(accordion).attributes('data-test')).toBe( + 'button-accordion' + ) + expect(getAccordionTitle(accordion).attributes('data-test')).toBe( + 'title-accordion' + ) + expect(getAccordionSubTitle(accordion).attributes('data-test')).toBe( + 'subTitle-accordion' + ) + expect(getAccordionIcon(accordion).attributes('data-test')).toBe( + 'icon-accordion' + ) + }) }) diff --git a/packages/components/alert/src/alert.ts b/packages/components/alert/src/alert.ts index ee3800f1..f179699e 100644 --- a/packages/components/alert/src/alert.ts +++ b/packages/components/alert/src/alert.ts @@ -47,6 +47,11 @@ export const alertProps = buildProps({ required: false, default: 'polite', }, + dataTest: { + type: String, + required: false, + default: undefined, + }, } as const) export type AlertProps = ExtractPropTypes diff --git a/packages/components/alert/src/alert.vue b/packages/components/alert/src/alert.vue index 5d9dc8a8..4992e0e4 100644 --- a/packages/components/alert/src/alert.vue +++ b/packages/components/alert/src/alert.vue @@ -11,10 +11,19 @@
-

{{ title }}

+

+ {{ title }} +

{{ description }}
@@ -23,6 +32,7 @@ v-if="buttonLabel" :variant="variant" class="puik-alert__button" + :data-test="dataTest != undefined ? `button-${dataTest}` : undefined" @click="click" > {{ buttonLabel }} @@ -34,6 +44,7 @@ icon="close" font-size="1.5rem" class="puik-alert__close" + :data-test="dataTest != undefined ? `close-${dataTest}` : undefined" @click="close" />
diff --git a/packages/components/alert/stories/alert.stories.ts b/packages/components/alert/stories/alert.stories.ts index 3f3469f3..c405d565 100644 --- a/packages/components/alert/stories/alert.stories.ts +++ b/packages/components/alert/stories/alert.stories.ts @@ -47,6 +47,11 @@ export default { control: 'none', description: 'Set the alert description', }, + dataTest: { + control: 'text', + description: + 'Set the data-test attribute for the alert components `title-${dataTest}` `description-${dataTest}` `button-${dataTest}` `close-${dataTest}`', + }, }, args: { title: 'Title', diff --git a/packages/components/alert/test/alert.spec.ts b/packages/components/alert/test/alert.spec.ts index 05a5f5c7..d2bdcb6f 100644 --- a/packages/components/alert/test/alert.spec.ts +++ b/packages/components/alert/test/alert.spec.ts @@ -75,4 +75,18 @@ describe('Alert tests', () => { await findCloseButton().trigger('click') expect(wrapper.emitted('close')).toBeTruthy() }) + + it('should have a data-test attribute on title, description button and close button', () => { + factory({ + title: faker.lorem.word(2), + description: faker.lorem.sentence(60), + buttonLabel: 'Button', + isClosable: true, + dataTest: 'alert', + }) + expect(findTitle().attributes('data-test')).toBe('title-alert') + expect(findDesc().attributes('data-test')).toBe('description-alert') + expect(findButton().attributes('data-test')).toBe('button-alert') + expect(findCloseButton().attributes('data-test')).toBe('close-alert') + }) }) diff --git a/packages/components/badge/src/badge.ts b/packages/components/badge/src/badge.ts index 04927ec2..bc2790e2 100644 --- a/packages/components/badge/src/badge.ts +++ b/packages/components/badge/src/badge.ts @@ -17,6 +17,11 @@ export const badgeProps = buildProps({ type: String as PropType, default: 'neutral', }, + dataTest: { + type: String, + required: false, + default: undefined, + }, } as const) export type BadgeProps = ExtractPropTypes diff --git a/packages/components/badge/src/badge.vue b/packages/components/badge/src/badge.vue index 031efe10..692c7269 100644 --- a/packages/components/badge/src/badge.vue +++ b/packages/components/badge/src/badge.vue @@ -1,5 +1,9 @@ diff --git a/packages/components/badge/stories/badge.stories.ts b/packages/components/badge/stories/badge.stories.ts index 5ec5d5c7..e77a28e4 100644 --- a/packages/components/badge/stories/badge.stories.ts +++ b/packages/components/badge/stories/badge.stories.ts @@ -25,6 +25,10 @@ export default { }, }, }, + dataTest: { + control: 'text', + description: 'Set the data-test attribute on the badge', + }, }, args: { default: 'Status', diff --git a/packages/components/badge/test/badge.spec.ts b/packages/components/badge/test/badge.spec.ts index 81eca07e..10e80c0f 100644 --- a/packages/components/badge/test/badge.spec.ts +++ b/packages/components/badge/test/badge.spec.ts @@ -47,4 +47,9 @@ describe('Badge tests', () => { ) expect(findBadge().text()).toBe(slotDefault) }) + + it('should have a data-test attribute', () => { + factory({ 'data-test': 'test' }) + expect(findBadge().attributes('data-test')).toBe('test') + }) }) diff --git a/packages/components/breadcrumb/src/breadcrumb.ts b/packages/components/breadcrumb/src/breadcrumb.ts index 02f9e895..94ad999f 100644 --- a/packages/components/breadcrumb/src/breadcrumb.ts +++ b/packages/components/breadcrumb/src/breadcrumb.ts @@ -3,11 +3,13 @@ import type { RouteLocationRaw } from 'vue-router' import type { ExtractPropTypes, PropType } from 'vue' import type Breadcrumb from './breadcrumb.vue' +import type { PuikTargetString } from '../../link/src/link' export interface BreadcrumbItem { label: string to?: RouteLocationRaw href?: string - target?: string + target?: PuikTargetString + dataTest?: string } export const breadcrumbProps = buildProps({ diff --git a/packages/components/breadcrumb/src/breadcrumb.vue b/packages/components/breadcrumb/src/breadcrumb.vue index f060fbd1..9aba01fd 100644 --- a/packages/components/breadcrumb/src/breadcrumb.vue +++ b/packages/components/breadcrumb/src/breadcrumb.vue @@ -17,6 +17,7 @@ :to="item.to" :href="item.href" :target="item.target" + :data-test="item.dataTest ? item.dataTest : undefined" size="sm" > {{ item.label }} @@ -29,7 +30,14 @@ >
-
+
{{ items[items.length - 1].label }}
diff --git a/packages/components/breadcrumb/stories/breadcrumb.stories.ts b/packages/components/breadcrumb/stories/breadcrumb.stories.ts index 4b2459d6..9761907a 100644 --- a/packages/components/breadcrumb/stories/breadcrumb.stories.ts +++ b/packages/components/breadcrumb/stories/breadcrumb.stories.ts @@ -23,6 +23,7 @@ interface BreadBreadcrumbItem { to: string | undefined, href: string | undefined, target: '_blank' | '_self' | '_parent' | '_top' | undefined, + dataTest: string | undefined, }`, }, }, diff --git a/packages/components/breadcrumb/test/breadcrumb.spec.ts b/packages/components/breadcrumb/test/breadcrumb.spec.ts index c2f5bcb4..49c77870 100644 --- a/packages/components/breadcrumb/test/breadcrumb.spec.ts +++ b/packages/components/breadcrumb/test/breadcrumb.spec.ts @@ -1,8 +1,9 @@ import { mount } from '@vue/test-utils' import { describe, it, expect } from 'vitest' import PuikBreadcrumb from '../src/breadcrumb.vue' -import type { MountingOptions, VueWrapper } from '@vue/test-utils' +import { PuikLinkTarget } from '../../link' import type { BreadcrumbItem } from '../src/breadcrumb' +import type { MountingOptions, VueWrapper } from '@vue/test-utils' describe('Breadcrumb tests', () => { let wrapper: VueWrapper @@ -29,7 +30,8 @@ describe('Breadcrumb tests', () => { { label: 'First link', href: '#', - target: '_blank', + target: PuikLinkTarget.BLANK, + dataTest: 'test-1', }, { label: 'Second link', @@ -38,6 +40,7 @@ describe('Breadcrumb tests', () => { { label: 'Third link', to: 'name', + dataTest: 'test-3', }, { label: 'Last link', @@ -51,17 +54,27 @@ describe('Breadcrumb tests', () => { factory() expect(wrapper.element.tagName).toBeFalsy() }) - it('should first item be A with href', () => { + it('should first item be A with href and data-test', () => { factory({ items }) const localItems = getBreadcrumbItems() expect(localItems[0].element.tagName).toBe('A') expect(localItems[0].element.getAttribute('href')).toBe(items[0].href) + expect( + localItems[0].element + .getAttribute('data-test') + .includes(items[0].dataTest) + ) }) - it('should third item be ROUTER-LINK with to', () => { + it('should third item be ROUTER-LINK with to and data-test', () => { factory({ items }) const localItems = getBreadcrumbItems() expect(localItems[2].element.tagName).toBe('ROUTER-LINK') expect(localItems[2].element.getAttribute('to')).toBe(items[2].to) + expect( + localItems[2].element + .getAttribute('data-test') + .includes(items[2].dataTest) + ) }) it('should display only three separator icon', () => { factory({ items }) diff --git a/packages/components/button/src/button.ts b/packages/components/button/src/button.ts index 73db5e85..a6885676 100644 --- a/packages/components/button/src/button.ts +++ b/packages/components/button/src/button.ts @@ -68,6 +68,11 @@ export const buttonProps = buildProps({ required: false, default: undefined, }, + dataTest: { + type: String, + required: false, + default: undefined, + }, } as const) export type ButtonProps = ExtractPropTypes diff --git a/packages/components/button/src/button.vue b/packages/components/button/src/button.vue index 9f70637a..5c095584 100644 --- a/packages/components/button/src/button.vue +++ b/packages/components/button/src/button.vue @@ -10,6 +10,7 @@ { 'puik-button--fluid': fluid }, ]" :disabled="disabled" + :data-test="dataTest" @click="setSelected" > diff --git a/packages/components/button/stories/button.stories.ts b/packages/components/button/stories/button.stories.ts index 0406bdf0..a71e84a2 100644 --- a/packages/components/button/stories/button.stories.ts +++ b/packages/components/button/stories/button.stories.ts @@ -71,6 +71,11 @@ export default { control: 'text', description: 'Set a link for the button (changes button to "a" html tag)', }, + dataTest: { + control: 'text', + description: + 'Set a data-test attribute to the button `${dataTest}` `left-icon-${dataTest}` `right-icon-${dataTest}`', + }, }, args: { variant: 'primary', diff --git a/packages/components/button/test/button.spec.ts b/packages/components/button/test/button.spec.ts index b83a1858..a209f85c 100644 --- a/packages/components/button/test/button.spec.ts +++ b/packages/components/button/test/button.spec.ts @@ -100,4 +100,17 @@ describe('Button tests', () => { factory({ href: '/test' }) expect(findButton().element.tagName).toBe('A') }) + + it('should have a data-test attribute on global component, left-icon and right-icon', () => { + factory({ + leftIcon: 'close', + rightIcon: 'close', + dataTest: 'button', + }) + expect(findButton().attributes('data-test')).toBe('button') + expect(findButtonLeftIcon().attributes('data-test')).toBe('leftIcon-button') + expect(findButtonRightIcon().attributes('data-test')).toBe( + 'rightIcon-button' + ) + }) }) diff --git a/packages/components/checkbox/src/checkbox.ts b/packages/components/checkbox/src/checkbox.ts index b443a474..b47f0491 100644 --- a/packages/components/checkbox/src/checkbox.ts +++ b/packages/components/checkbox/src/checkbox.ts @@ -22,6 +22,11 @@ export const checkboxProps = buildProps({ required: false, default: false, }, + dataTest: { + type: String, + required: false, + default: undefined, + }, } as const) export type CheckboxProps = ExtractPropTypes diff --git a/packages/components/checkbox/src/checkbox.vue b/packages/components/checkbox/src/checkbox.vue index aecc9ea4..7f322ca1 100644 --- a/packages/components/checkbox/src/checkbox.vue +++ b/packages/components/checkbox/src/checkbox.vue @@ -8,11 +8,13 @@ type="checkbox" :indeterminate="indeterminate" :disabled="disabled" + :data-test="dataTest != undefined ? `input-${dataTest}` : undefined" /> diff --git a/packages/components/checkbox/stories/checkbox.stories.ts b/packages/components/checkbox/stories/checkbox.stories.ts index c421eff8..fd725641 100644 --- a/packages/components/checkbox/stories/checkbox.stories.ts +++ b/packages/components/checkbox/stories/checkbox.stories.ts @@ -33,6 +33,11 @@ export default { }, }, }, + dataTest: { + description: + 'Set the data-test attribute for the label and the input `label-${dataTest}` `input-${dataTest}`}`', + control: 'text', + }, }, args: { label: 'Label', diff --git a/packages/components/checkbox/test/checkbox.spec.ts b/packages/components/checkbox/test/checkbox.spec.ts index 1cf8e87a..95bdfe05 100644 --- a/packages/components/checkbox/test/checkbox.spec.ts +++ b/packages/components/checkbox/test/checkbox.spec.ts @@ -93,4 +93,10 @@ describe('Checkbox tests', () => { await findLabel().trigger('click') expect(wrapper.vm.checkboxInputRef.click).not.toHaveBeenCalled() }) + + it('shouold have a data-test attribute on the input and the label', () => { + factory({ label: 'Label', modelValue: false, dataTest: 'test' }) + expect(findInput().attributes('data-test')).toBe('input-test') + expect(findLabel().attributes('data-test')).toBe('label-test') + }) }) diff --git a/packages/components/icon/src/icon.ts b/packages/components/icon/src/icon.ts index 8ed7cc43..008b7611 100644 --- a/packages/components/icon/src/icon.ts +++ b/packages/components/icon/src/icon.ts @@ -7,6 +7,11 @@ export const iconProps = buildProps({ type: String, required: true, }, + dataTest: { + type: String, + required: false, + default: undefined, + }, nodeType: { type: String, default: 'div', diff --git a/packages/components/icon/src/icon.vue b/packages/components/icon/src/icon.vue index 22cd7bc0..6071cd73 100644 --- a/packages/components/icon/src/icon.vue +++ b/packages/components/icon/src/icon.vue @@ -1,5 +1,10 @@ diff --git a/packages/components/icon/stories/icon.stories.ts b/packages/components/icon/stories/icon.stories.ts index a8b7e58c..4aaffbb6 100644 --- a/packages/components/icon/stories/icon.stories.ts +++ b/packages/components/icon/stories/icon.stories.ts @@ -31,6 +31,9 @@ export default { options: ['div', 'span'], }, }, + dataTest: { + description: 'Set the data-test attribute', + }, }, } as Meta @@ -52,6 +55,7 @@ export const Default = { color: 'green', fontSize: 24, nodeType: 'span', + dataTest: '', }, parameters: { diff --git a/packages/components/icon/test/icon.spec.ts b/packages/components/icon/test/icon.spec.ts index 1a67a17e..2c872007 100644 --- a/packages/components/icon/test/icon.spec.ts +++ b/packages/components/icon/test/icon.spec.ts @@ -68,4 +68,9 @@ describe('Icon tests', () => { expect(findIcon().element.nodeName).toBe('SPAN') }) + + it('should have a data-test attribute', () => { + factory({ 'data-test': 'test' }) + expect(findIcon().attributes('data-test')).toBe('test') + }) }) diff --git a/packages/components/input/src/input.ts b/packages/components/input/src/input.ts index c64f5338..a921ae82 100644 --- a/packages/components/input/src/input.ts +++ b/packages/components/input/src/input.ts @@ -90,6 +90,11 @@ export const inputProps = buildProps({ required: false, default: false, }, + dataTest: { + type: String, + required: false, + default: undefined, + }, } as const) export type InputProps = ExtractPropTypes diff --git a/packages/components/input/src/input.vue b/packages/components/input/src/input.vue index db774fbc..612603b6 100644 --- a/packages/components/input/src/input.vue +++ b/packages/components/input/src/input.vue @@ -17,6 +17,7 @@ :min="type === 'number' ? min : undefined" :max="type === 'number' ? max : undefined" :step="type === 'number' ? step : undefined" + :data-test="dataTest != undefined ? `input-${dataTest}` : undefined" @focus="handleFocus" @blur="handleBlur" /> @@ -49,7 +50,10 @@ class="puik-input__hint__error__icon" font-size="1.25rem" > - + {{ error }}
diff --git a/packages/components/input/stories/input.stories.ts b/packages/components/input/stories/input.stories.ts index 5c2d25de..4fe82475 100644 --- a/packages/components/input/stories/input.stories.ts +++ b/packages/components/input/stories/input.stories.ts @@ -93,6 +93,11 @@ export default { control: 'none', description: 'Append an icon or text to the input', }, + dataTest: { + description: + 'Set the data-test attribute on the input and error text elements `input-${dataTest}` `error-${dataTest}`', + control: 'text', + }, }, } as Meta diff --git a/packages/components/input/test/input.spec.ts b/packages/components/input/test/input.spec.ts index ea0070cf..d69f2dac 100644 --- a/packages/components/input/test/input.spec.ts +++ b/packages/components/input/test/input.spec.ts @@ -10,6 +10,7 @@ describe('Input tests', () => { const findWrapper = () => wrapper.find('.puik-input__wrapper') const findHint = () => wrapper.find('.puik-input__hint__text') const findError = () => wrapper.find('.puik-input__hint__error') + const findErrorMessage = () => wrapper.find('.puik-input__hint__error__text') const findIncrement = () => wrapper.find('.puik-input__controls__increment') const findDecrement = () => wrapper.find('.puik-input__controls__decrement') const findRevealPassword = () => wrapper.find('.puik-input__reveal-password') @@ -183,4 +184,18 @@ describe('Input tests', () => { expect(findAppend().exists).toBeTruthy() expect(findAppend().text()).toBe('$') }) + + it('should have a data-tes attribut for the input and the error message', () => { + const error = 'This is an error message' + factory( + { modelValue: 'value', type: 'text', dataTest: 'test' }, + { + slots: { + error, + }, + } + ) + expect(findField().attributes('data-test')).toBe('input-test') + expect(findErrorMessage().attributes('data-test')).toBe('error-test') + }) }) diff --git a/packages/components/label/src/label.ts b/packages/components/label/src/label.ts index 67b23ee8..4e25ff2a 100644 --- a/packages/components/label/src/label.ts +++ b/packages/components/label/src/label.ts @@ -2,6 +2,11 @@ import { buildProps } from '@puik/utils' import type { ExtractPropTypes } from 'vue' import type Label from './label.vue' export const labelProps = buildProps({ + dataTest: { + type: String, + required: false, + default: undefined, + }, optional: { type: Boolean, required: false, diff --git a/packages/components/label/src/label.vue b/packages/components/label/src/label.vue index 69d5080b..a89c0d56 100644 --- a/packages/components/label/src/label.vue +++ b/packages/components/label/src/label.vue @@ -1,5 +1,5 @@