@@ -112,4 +112,77 @@ describe('<Select>', () => {
112112 expect ( getByText ( container , 'No hay opciones' ) ) . toBeInTheDocument ( ) ;
113113 } ) ;
114114 } ) ;
115+
116+ describe ( 'when label is provided' , ( ) => {
117+ beforeEach ( ( ) => {
118+ props . label = 'Test Label' ;
119+ } ) ;
120+
121+ it ( 'should display the label' , ( ) => {
122+ const { container} = getComponent ( ) ;
123+ expect ( getByText ( container , 'Test Label' ) ) . toBeInTheDocument ( ) ;
124+ } ) ;
125+
126+ it ( 'should associate label with input' , ( ) => {
127+ const { container} = getComponent ( ) ;
128+ const label = getByText ( container , 'Test Label' ) ;
129+ const input = container . querySelector ( 'input' ) ;
130+ expect ( label ) . toHaveAttribute ( 'for' , props . name ) ;
131+ expect ( input ) . toHaveAttribute ( 'id' , props . name ) ;
132+ } ) ;
133+ } ) ;
134+
135+ describe ( 'when error is provided' , ( ) => {
136+ beforeEach ( ( ) => {
137+ props . error = 'This field is required' ;
138+ } ) ;
139+
140+ it ( 'should display error message when dropdown is closed' , ( ) => {
141+ const { container} = getComponent ( ) ;
142+ expect ( getByText ( container , 'This field is required' ) ) . toBeInTheDocument ( ) ;
143+ } ) ;
144+
145+ it ( 'should hide error message when dropdown is open' , ( ) => {
146+ const { container} = getComponent ( ) ;
147+ const input = container . querySelector ( 'input' ) ;
148+
149+ expect ( getByText ( container , 'This field is required' ) ) . toBeInTheDocument ( ) ;
150+
151+ fireEvent . click ( input ) ;
152+
153+ expect ( queryByText ( container , 'This field is required' ) ) . toBeNull ( ) ;
154+ } ) ;
155+
156+ it ( 'should show error message again when dropdown is closed' , ( ) => {
157+ const { container} = getComponent ( ) ;
158+ const input = container . querySelector ( 'input' ) ;
159+
160+ fireEvent . click ( input ) ;
161+ expect ( queryByText ( container , 'This field is required' ) ) . toBeNull ( ) ;
162+
163+ const backdrop = container . querySelector ( '.fixed' ) ;
164+ fireEvent . click ( backdrop ) ;
165+
166+ expect ( getByText ( container , 'This field is required' ) ) . toBeInTheDocument ( ) ;
167+ } ) ;
168+
169+ it ( 'should apply error styling to input' , ( ) => {
170+ const { container} = getComponent ( ) ;
171+ const input = container . querySelector ( 'input' ) ;
172+ expect ( input ) . toHaveClass ( 'border-error' ) ;
173+ } ) ;
174+ } ) ;
175+
176+ describe ( 'when both label and error are provided' , ( ) => {
177+ beforeEach ( ( ) => {
178+ props . label = 'Country' ;
179+ props . error = 'Please select a country' ;
180+ } ) ;
181+
182+ it ( 'should display both label and error' , ( ) => {
183+ const { container} = getComponent ( ) ;
184+ expect ( getByText ( container , 'Country' ) ) . toBeInTheDocument ( ) ;
185+ expect ( getByText ( container , 'Please select a country' ) ) . toBeInTheDocument ( ) ;
186+ } ) ;
187+ } ) ;
115188} ) ;
0 commit comments