/
index.spec.tsx
72 lines (62 loc) · 2.13 KB
/
index.spec.tsx
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
import * as React from 'react';
import {render, screen} from '@testing-library/react';
import {CustomizationProvider} from '@twilio-paste/customization';
import {DetailText} from '../src';
describe('DetailText', () => {
it('should render', () => {
render(<DetailText>test</DetailText>);
expect(screen.getByText('test')).toBeDefined();
});
it('should render the element based on the as prop', () => {
render(<DetailText as="li">test</DetailText>);
expect(screen.getByRole('listitem')).toBeDefined();
});
describe('Customization', () => {
it('should set default data paste element attribute', () => {
render(<DetailText data-testid="detail-text">test</DetailText>);
expect(screen.getByTestId('detail-text').dataset.pasteElement).toEqual('DETAIL_TEXT');
});
it('should set custom data paste element attribute', () => {
render(
<DetailText data-testid="detail-text" element="MY_DETAIL_TEXT">
test
</DetailText>
);
expect(screen.getByTestId('detail-text').dataset.pasteElement).toEqual('MY_DETAIL_TEXT');
});
it('should add custom styles', () => {
render(
<CustomizationProvider
baseTheme="default"
theme={TestTheme}
elements={{
DETAIL_TEXT: {
color: 'colorTextNew',
},
}}
>
<DetailText data-testid="detail-text">test</DetailText>
</CustomizationProvider>
);
expect(screen.getByTestId('detail-text')).toHaveStyleRule('color', 'rgb(109, 46, 209)');
});
it('should add custom styles with a custom data paste element attribute', () => {
render(
<CustomizationProvider
baseTheme="default"
theme={TestTheme}
elements={{
MY_DETAIL_TEXT: {
color: 'colorTextNew',
},
}}
>
<DetailText data-testid="detail-text" element="MY_DETAIL_TEXT">
test
</DetailText>
</CustomizationProvider>
);
expect(screen.getByTestId('detail-text')).toHaveStyleRule('color', 'rgb(109, 46, 209)');
});
});
});