forked from react-component/input
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextArea.showCount.test.tsx
More file actions
77 lines (71 loc) · 2.22 KB
/
TextArea.showCount.test.tsx
File metadata and controls
77 lines (71 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { render } from '@testing-library/react';
import React from 'react';
import { TextArea } from '../src';
describe('should support showCount', () => {
it('maxLength', () => {
const { container } = render(
<TextArea maxLength={5} showCount value="12345" />,
);
expect(container.querySelector('textarea')?.value).toBe('12345');
expect(
container
.querySelector('.rc-textarea-show-count')
?.getAttribute('data-count'),
).toBe('5 / 5');
expect(container.querySelector('.rc-textarea-data-count')?.innerHTML).toBe(
'5 / 5',
);
});
it('control exceed maxLength', () => {
const { container } = render(
<TextArea maxLength={5} showCount value="12345678" />,
);
expect(container.querySelector('textarea')?.value).toBe('12345678');
expect(
container
.querySelector('.rc-textarea-show-count')
?.getAttribute('data-count'),
).toBe('8 / 5');
expect(container.querySelector('.rc-textarea-data-count')?.innerHTML).toBe(
'8 / 5',
);
});
it('should support object', () => {
const { container } = render(
<TextArea
maxLength={5}
showCount={{
formatter: ({ value, count, maxLength }) =>
`${value}, ${count}, ${maxLength}`,
}}
value="12345"
/>,
);
expect(container.querySelector('textarea')?.value).toBe('12345');
expect(
container
.querySelector('.rc-textarea-show-count')
?.getAttribute('data-count'),
).toBe('12345, 5, 5');
expect(container.querySelector('.rc-textarea-data-count')?.innerHTML).toBe(
'12345, 5, 5',
);
});
it('className & style patch to outer', () => {
const { container } = render(
<TextArea className="bamboo" style={{ background: 'red' }} showCount />,
);
// Outer
expect(
container.querySelector('span')?.classList.contains('bamboo'),
).toBeTruthy();
expect(container.querySelector('span')?.style.background).toEqual('red');
// Inner
expect(
container.querySelector('.rc-textarea')?.classList.contains('bamboo'),
).toBeFalsy();
expect(
container.querySelector<HTMLDivElement>('.rc-textarea')?.style.background,
).toBeFalsy();
});
});