Skip to content

Commit f8b710f

Browse files
committed
test: add more test case for BaseInput
1 parent 3bf975c commit f8b710f

1 file changed

Lines changed: 119 additions & 26 deletions

File tree

tests/BaseInput.test.tsx

Lines changed: 119 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -270,35 +270,128 @@ describe('BaseInput', () => {
270270
expect(container.firstChild).toHaveClass('rc-input-group-wrapper-disabled');
271271
});
272272

273-
it('variant cls', () => {
274-
const { container, rerender } = render(
275-
<BaseInput
276-
prefixCls="rc-input"
277-
prefix="$"
278-
classNames={{ variant: 'test-variant' }}
279-
disabled
280-
>
281-
<input />
282-
</BaseInput>,
283-
);
273+
describe('variant cls', () => {
274+
it('variant cls', () => {
275+
const { container, rerender } = render(
276+
<BaseInput
277+
prefixCls="rc-input"
278+
prefix="$"
279+
classNames={{ variant: 'test-variant' }}
280+
disabled
281+
>
282+
<input />
283+
</BaseInput>,
284+
);
284285

285-
expect(container.querySelector('.rc-input-affix-wrapper')).toHaveClass(
286-
'test-variant',
287-
);
288-
expect(container.querySelector('input')).not.toHaveClass('test-variant');
286+
expect(container.querySelector('.rc-input-affix-wrapper')).toHaveClass(
287+
'test-variant',
288+
);
289+
expect(container.querySelector('input')).not.toHaveClass('test-variant');
289290

290-
rerender(
291-
<BaseInput
292-
prefixCls="rc-input"
293-
classNames={{ variant: 'test-variant' }}
294-
disabled
295-
>
296-
<input />
297-
</BaseInput>,
298-
);
291+
rerender(
292+
<BaseInput
293+
prefixCls="rc-input"
294+
classNames={{ variant: 'test-variant' }}
295+
disabled
296+
>
297+
<input />
298+
</BaseInput>,
299+
);
299300

300-
expect(container.querySelector('.rc-input-affix-wrapper')).toBeFalsy();
301-
expect(container.querySelector('input')).toHaveClass('test-variant');
301+
expect(container.querySelector('.rc-input-affix-wrapper')).toBeFalsy();
302+
expect(container.querySelector('input')).toHaveClass('test-variant');
303+
});
304+
305+
it('should handle empty className correctly', () => {
306+
const { container } = render(
307+
<BaseInput prefixCls="rc-input">
308+
<input className="" />
309+
</BaseInput>,
310+
);
311+
expect(container.querySelector('input')?.className).toBe('');
312+
});
313+
314+
it('should merge classNames correctly', () => {
315+
const { container } = render(
316+
<BaseInput
317+
prefixCls="rc-input"
318+
className="global-class"
319+
classNames={{ variant: 'variant-class' }}
320+
>
321+
<input className="input-class" />
322+
</BaseInput>,
323+
);
324+
expect(container.querySelector('input')?.className).toBe(
325+
'input-class variant-class global-class',
326+
);
327+
});
328+
329+
it('should apply styles correctly', () => {
330+
const { container } = render(
331+
<BaseInput
332+
prefixCls="rc-input"
333+
style={{ color: 'red' }}
334+
styles={{
335+
affixWrapper: { backgroundColor: 'blue' },
336+
prefix: { fontSize: '12px' },
337+
}}
338+
prefix="$"
339+
>
340+
<input style={{ padding: '4px' }} />
341+
</BaseInput>,
342+
);
343+
344+
const affixWrapper = container.querySelector('.rc-input-affix-wrapper');
345+
const prefix = container.querySelector('.rc-input-prefix');
346+
const input = container.querySelector('input');
347+
348+
expect(affixWrapper).toHaveStyle({ backgroundColor: 'blue' });
349+
expect(prefix).toHaveStyle({ fontSize: '12px' });
350+
expect(input).toHaveStyle({ padding: '4px' });
351+
});
352+
353+
it('should handle data attributes', () => {
354+
const { container } = render(
355+
<BaseInput
356+
prefixCls="rc-input"
357+
dataAttrs={{
358+
affixWrapper: { 'data-testid': 'affix-wrapper' },
359+
}}
360+
prefix="$"
361+
>
362+
<input />
363+
</BaseInput>,
364+
);
365+
366+
expect(
367+
container.querySelector('.rc-input-affix-wrapper'),
368+
).toHaveAttribute('data-testid', 'affix-wrapper');
369+
});
370+
371+
it('should handle custom components', () => {
372+
const { container } = render(
373+
<BaseInput
374+
prefixCls="rc-input"
375+
components={{
376+
affixWrapper: 'div',
377+
groupWrapper: 'div',
378+
wrapper: 'div',
379+
groupAddon: 'div',
380+
}}
381+
prefix="$"
382+
addonBefore="Before"
383+
>
384+
<input />
385+
</BaseInput>,
386+
);
387+
388+
expect(container.querySelector('.rc-input-affix-wrapper')?.tagName).toBe(
389+
'DIV',
390+
);
391+
expect(container.querySelector('.rc-input-group-wrapper')?.tagName).toBe(
392+
'DIV',
393+
);
394+
});
302395
});
303396

304397
describe('ref', () => {

0 commit comments

Comments
 (0)