@@ -2,7 +2,6 @@ import { createRef } from 'react';
22import { describe , expect , it , vi } from 'vitest' ;
33import { page } from 'vitest/browser' ;
44import { DsButtonV3 } from '../index.ts' ;
5- import styles from '../ds-button-v3.module.scss' ;
65
76describe ( 'DsButtonV3' , ( ) => {
87 it ( 'calls onClick when clicked' , async ( ) => {
@@ -48,28 +47,28 @@ describe('DsButtonV3', () => {
4847 await expect . element ( button ) . toHaveAttribute ( 'data-color' , 'negative' ) ;
4948 } ) ;
5049
51- it ( 'sets ondark color palette ' , async ( ) => {
52- await page . render ( < DsButtonV3 color = "ondark" > Label </ DsButtonV3 > ) ;
50+ it ( 'applies iconOnly layout when startIcon is set without children ' , async ( ) => {
51+ await page . render ( < DsButtonV3 startIcon = "check_circle" aria-label = "Confirm" / >) ;
5352
54- const button = page . getByRole ( 'button' , { name : 'Label ' } ) ;
53+ const button = page . getByRole ( 'button' , { name : 'Confirm ' } ) ;
5554
56- await expect . element ( button ) . toHaveAttribute ( 'data-color ' , 'ondark ' ) ;
55+ await expect . element ( button ) . toHaveAttribute ( 'data-icon-only ' , 'true ' ) ;
5756 } ) ;
5857
59- it ( 'applies iconOnly layout when icon is set without children' , async ( ) => {
60- await page . render ( < DsButtonV3 icon = "check_circle " aria-label = "Confirm " /> ) ;
58+ it ( 'applies iconOnly layout when endIcon is set without children' , async ( ) => {
59+ await page . render ( < DsButtonV3 endIcon = "arrow_forward " aria-label = "Next " /> ) ;
6160
62- const button = page . getByRole ( 'button' , { name : 'Confirm ' } ) ;
61+ const button = page . getByRole ( 'button' , { name : 'Next ' } ) ;
6362
64- await expect . element ( button ) . toHaveClass ( styles . iconOnly ) ;
63+ await expect . element ( button ) . toHaveAttribute ( 'data-icon-only' , 'true' ) ;
6564 } ) ;
6665
6766 it ( 'does not apply iconOnly layout when icon is set with children' , async ( ) => {
68- await page . render ( < DsButtonV3 icon = "check_circle" > Save</ DsButtonV3 > ) ;
67+ await page . render ( < DsButtonV3 startIcon = "check_circle" > Save</ DsButtonV3 > ) ;
6968
7069 const button = page . getByRole ( 'button' , { name : 'Save' } ) ;
7170
72- await expect . element ( button ) . not . toHaveClass ( styles . iconOnly ) ;
71+ await expect . element ( button ) . not . toHaveAttribute ( 'data-icon-only' ) ;
7372 } ) ;
7473
7574 it ( 'renders native submit button type' , async ( ) => {
@@ -86,17 +85,17 @@ describe('DsButtonV3', () => {
8685 await expect . element ( page . getByRole ( 'button' , { name : 'X' } ) ) . toHaveClass ( 'extra' ) ;
8786 } ) ;
8887
89- it ( 'sets aria-busy and loading class when loading' , async ( ) => {
88+ it ( 'sets aria-busy and data- loading when loading' , async ( ) => {
9089 await page . render ( < DsButtonV3 loading > Save</ DsButtonV3 > ) ;
9190
9291 const button = page . getByRole ( 'button' , { name : 'Save' } ) ;
9392
9493 await expect . element ( button ) . toHaveAttribute ( 'aria-busy' , 'true' ) ;
95- await expect . element ( button ) . toHaveClass ( styles . loading ) ;
94+ await expect . element ( button ) . toHaveAttribute ( 'data- loading' , '' ) ;
9695 } ) ;
9796
98- it ( 'renders spinner instead of icon when loading' , async ( ) => {
99- await page . render ( < DsButtonV3 loading icon = "check_circle" aria-label = "Saving" /> ) ;
97+ it ( 'renders spinner instead of startIcon when loading' , async ( ) => {
98+ await page . render ( < DsButtonV3 loading startIcon = "check_circle" aria-label = "Saving" /> ) ;
10099
101100 const button = page . getByRole ( 'button' , { name : 'Saving' } ) ;
102101
@@ -107,6 +106,34 @@ describe('DsButtonV3', () => {
107106 expect ( el . querySelector ( '[aria-hidden]' ) ) . toBeNull ( ) ;
108107 } ) ;
109108
109+ it ( 'preserves endIcon when loading' , async ( ) => {
110+ await page . render (
111+ < DsButtonV3 loading startIcon = "check_circle" endIcon = "arrow_forward" >
112+ Save
113+ </ DsButtonV3 > ,
114+ ) ;
115+
116+ const button = page . getByRole ( 'button' , { name : 'Save' } ) ;
117+ const el = button . element ( ) ;
118+ const hiddenIcons = el . querySelectorAll ( '[aria-hidden]' ) ;
119+
120+ expect ( el . querySelector ( 'svg' ) ) . toBeTruthy ( ) ;
121+ expect ( hiddenIcons ) . toHaveLength ( 1 ) ;
122+ } ) ;
123+
124+ it ( 'renders both startIcon and endIcon' , async ( ) => {
125+ await page . render (
126+ < DsButtonV3 startIcon = "check_circle" endIcon = "arrow_forward" >
127+ Continue
128+ </ DsButtonV3 > ,
129+ ) ;
130+
131+ const button = page . getByRole ( 'button' , { name : 'Continue' } ) ;
132+ const hiddenIcons = button . element ( ) . querySelectorAll ( '[aria-hidden]' ) ;
133+
134+ expect ( hiddenIcons ) . toHaveLength ( 2 ) ;
135+ } ) ;
136+
110137 it ( 'does not call onClick when loading' , async ( ) => {
111138 const onClick = vi . fn ( ) ;
112139
@@ -142,6 +169,7 @@ describe('DsButtonV3', () => {
142169
143170 await expect . element ( button ) . toHaveAttribute ( 'data-color' , 'default' ) ;
144171 await expect . element ( button ) . toHaveAttribute ( 'data-variant' , 'primary' ) ;
172+ await expect . element ( button ) . toHaveAttribute ( 'data-size' , 'medium' ) ;
145173 } ) ;
146174
147175 it ( 'forwards ref to the button element' , async ( ) => {
@@ -165,7 +193,7 @@ describe('DsButtonV3', () => {
165193 const button = page . getByRole ( 'button' , { name : 'Saving' , disabled : true } ) ;
166194
167195 await expect . element ( button ) . toBeDisabled ( ) ;
168- await expect . element ( button ) . toHaveClass ( styles . loading ) ;
196+ await expect . element ( button ) . toHaveAttribute ( 'data- loading' , '' ) ;
169197 await button . click ( { force : true } ) ;
170198 expect ( onClick ) . not . toHaveBeenCalled ( ) ;
171199 } ) ;
@@ -180,7 +208,7 @@ describe('DsButtonV3', () => {
180208 const button = page . getByRole ( 'button' , { name : 'Saving' , disabled : true } ) ;
181209
182210 await expect . element ( button ) . toBeDisabled ( ) ;
183- await expect . element ( button ) . not . toHaveClass ( styles . loading ) ;
211+ await expect . element ( button ) . not . toHaveAttribute ( 'data- loading' ) ;
184212 await expect . element ( button ) . toHaveAttribute ( 'aria-busy' , 'true' ) ;
185213 } ) ;
186214
0 commit comments