@npm_leadtech/legal-lib-components 7.106.0 → 7.106.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/atoms/PhoneNumberDisplay/PhoneNumberDisplay.styled.js +1 -1
- package/dist/src/components/atoms/PhoneNumberDisplay/PhoneNumberDisplay.styled.ts +1 -1
- package/dist/src/components/molecules/TextInput/tests/InputComponent.test.tsx +108 -0
- package/dist/src/components/molecules/TextInput/tests/TextInputLabelComponent.test.tsx +61 -0
- package/dist/src/components/molecules/TextInput/tests/TextInputMessageComponent.test.tsx +37 -0
- package/dist/src/components/sections/Header/Header.styled.js +2 -0
- package/dist/src/components/sections/Header/Header.styled.ts +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { Input } from '../Input'
|
|
5
|
+
|
|
6
|
+
jest.mock('../../../../../images/svg/eye-close.svg', () => 'eye-close.svg')
|
|
7
|
+
jest.mock('../../../../../images/svg/eye-24-px.svg', () => 'eye-open.svg')
|
|
8
|
+
jest.mock('../../../../../images/svg/percent.svg', () => 'percent.svg')
|
|
9
|
+
|
|
10
|
+
const defaultProps = {
|
|
11
|
+
name: 'test-input',
|
|
12
|
+
placeholder: 'Enter text',
|
|
13
|
+
prefix: '',
|
|
14
|
+
value: '',
|
|
15
|
+
type: 'text' as const,
|
|
16
|
+
disabled: false,
|
|
17
|
+
className: 'e-text-input',
|
|
18
|
+
onChange: jest.fn(),
|
|
19
|
+
onClick: jest.fn(),
|
|
20
|
+
onBlur: jest.fn(),
|
|
21
|
+
onKeyDown: jest.fn(),
|
|
22
|
+
onKeyUp: jest.fn(),
|
|
23
|
+
country: 'US'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('Input', () => {
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
cleanup()
|
|
29
|
+
jest.clearAllMocks()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('renders a text input with correct attributes', () => {
|
|
33
|
+
render(<Input {...defaultProps} />)
|
|
34
|
+
const input = screen.getByPlaceholderText('Enter text')
|
|
35
|
+
expect(input).toBeInTheDocument()
|
|
36
|
+
expect(input).toHaveAttribute('name', 'test-input')
|
|
37
|
+
expect(input).toHaveAttribute('type', 'text')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('renders disabled input when disabled prop is true', () => {
|
|
41
|
+
render(<Input {...defaultProps} disabled={true} />)
|
|
42
|
+
expect(screen.getByPlaceholderText('Enter text')).toBeDisabled()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('applies short input class when maxLength is 5 or less', () => {
|
|
46
|
+
render(<Input {...defaultProps} maxLength={3} />)
|
|
47
|
+
const input = screen.getByPlaceholderText('Enter text')
|
|
48
|
+
expect(input.className).toContain('e-text-input__short')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('does not apply short input class when maxLength is greater than 5', () => {
|
|
52
|
+
render(<Input {...defaultProps} maxLength={10} />)
|
|
53
|
+
const input = screen.getByPlaceholderText('Enter text')
|
|
54
|
+
expect(input.className).not.toContain('e-text-input__short')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('renders password toggle button for password type', () => {
|
|
58
|
+
render(<Input {...defaultProps} type='password' value='secret' />)
|
|
59
|
+
const button = screen.getByRole('button')
|
|
60
|
+
expect(button).toBeInTheDocument()
|
|
61
|
+
expect(button).toHaveClass('input-icon-password-button')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('toggles password visibility on button click', () => {
|
|
65
|
+
render(<Input {...defaultProps} type='password' value='secret' />)
|
|
66
|
+
const input = screen.getByPlaceholderText('Enter text')
|
|
67
|
+
expect(input).toHaveAttribute('type', 'password')
|
|
68
|
+
|
|
69
|
+
fireEvent.click(screen.getByRole('button'))
|
|
70
|
+
expect(input).toHaveAttribute('type', 'text')
|
|
71
|
+
|
|
72
|
+
fireEvent.click(screen.getByRole('button'))
|
|
73
|
+
expect(input).toHaveAttribute('type', 'password')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('renders currency prefix for non-DE country', () => {
|
|
77
|
+
render(<Input {...defaultProps} prefix='currency' country='US' currencySymbol='$' />)
|
|
78
|
+
expect(screen.getByText('$')).toBeInTheDocument()
|
|
79
|
+
const input = screen.getByPlaceholderText('Enter text')
|
|
80
|
+
expect(input.className).toContain('has-currency-prefix')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('renders currency suffix for DE country', () => {
|
|
84
|
+
render(<Input {...defaultProps} prefix='currency' country='DE' currencySymbol='€' />)
|
|
85
|
+
expect(screen.getByText('€')).toBeInTheDocument()
|
|
86
|
+
const input = screen.getByPlaceholderText('Enter text')
|
|
87
|
+
expect(input.className).toContain('has-currency-suffix')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('renders percent suffix when prefix is percent', () => {
|
|
91
|
+
render(<Input {...defaultProps} prefix='percent' />)
|
|
92
|
+
const input = screen.getByPlaceholderText('Enter text')
|
|
93
|
+
expect(input.className).toContain('has-percent-suffix')
|
|
94
|
+
expect(screen.getByAltText('percent')).toBeInTheDocument()
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('calls onChange when input value changes', () => {
|
|
98
|
+
render(<Input {...defaultProps} />)
|
|
99
|
+
fireEvent.change(screen.getByPlaceholderText('Enter text'), { target: { value: 'hello' } })
|
|
100
|
+
expect(defaultProps.onChange).toHaveBeenCalledTimes(1)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('calls onBlur when input loses focus', () => {
|
|
104
|
+
render(<Input {...defaultProps} />)
|
|
105
|
+
fireEvent.blur(screen.getByPlaceholderText('Enter text'))
|
|
106
|
+
expect(defaultProps.onBlur).toHaveBeenCalledTimes(1)
|
|
107
|
+
})
|
|
108
|
+
})
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { TextInputLabel } from '../TextInputLabel'
|
|
5
|
+
|
|
6
|
+
jest.mock('../../../atoms', () => ({
|
|
7
|
+
DialogMenuIcon: ({ content }: { content: string }) => <span data-testid='dialog-menu-icon'>{content}</span>
|
|
8
|
+
}))
|
|
9
|
+
|
|
10
|
+
describe('TextInputLabel', () => {
|
|
11
|
+
afterEach(cleanup)
|
|
12
|
+
|
|
13
|
+
test('returns null when neither label nor notes are provided', () => {
|
|
14
|
+
const { container } = render(<TextInputLabel />)
|
|
15
|
+
expect(container.innerHTML).toBe('')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('renders the label text', () => {
|
|
19
|
+
render(<TextInputLabel label='Full Name' htmlFor='full-name' />)
|
|
20
|
+
expect(screen.getByText('Full Name')).toBeInTheDocument()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('renders label element with correct htmlFor attribute', () => {
|
|
24
|
+
render(<TextInputLabel label='Email' htmlFor='email-input' />)
|
|
25
|
+
const label = screen.getByText('Email')
|
|
26
|
+
expect(label.closest('label')).toHaveAttribute('for', 'email-input')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('renders notes text', () => {
|
|
30
|
+
render(<TextInputLabel label='Name' notes='Optional field' />)
|
|
31
|
+
expect(screen.getByText('Optional field')).toBeInTheDocument()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('renders with form-group__label class when no tooltip', () => {
|
|
35
|
+
render(<TextInputLabel label='Name' />)
|
|
36
|
+
const label = screen.getByText('Name').closest('label')
|
|
37
|
+
expect(label).toHaveClass('form-group__label')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('renders with form-group__label-icon class when tooltip is provided', () => {
|
|
41
|
+
render(<TextInputLabel label='SSN' dialogMenuTip='Required for verification' />)
|
|
42
|
+
const label = screen.getByText('SSN').closest('label')
|
|
43
|
+
expect(label).toHaveClass('form-group__label-icon')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('renders DialogMenuIcon when dialogMenuTip is provided', () => {
|
|
47
|
+
render(<TextInputLabel label='SSN' dialogMenuTip='Tooltip content' />)
|
|
48
|
+
expect(screen.getByTestId('dialog-menu-icon')).toBeInTheDocument()
|
|
49
|
+
expect(screen.getByText('Tooltip content')).toBeInTheDocument()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('does not render DialogMenuIcon when dialogMenuTip is empty', () => {
|
|
53
|
+
render(<TextInputLabel label='Name' dialogMenuTip='' />)
|
|
54
|
+
expect(screen.queryByTestId('dialog-menu-icon')).not.toBeInTheDocument()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('renders when only notes are provided', () => {
|
|
58
|
+
render(<TextInputLabel notes='Some note' />)
|
|
59
|
+
expect(screen.getByText('Some note')).toBeInTheDocument()
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { TextInputMessage } from '../TextInputMessage'
|
|
5
|
+
|
|
6
|
+
jest.mock('../../../../../images/svg/info-error_24px_outlined.svg', () => 'error-icon.svg')
|
|
7
|
+
|
|
8
|
+
describe('TextInputMessage', () => {
|
|
9
|
+
afterEach(cleanup)
|
|
10
|
+
|
|
11
|
+
test('renders error message when errorMessage is set and validate is false', () => {
|
|
12
|
+
render(<TextInputMessage errorMessage='This field is required' validate={false} />)
|
|
13
|
+
expect(screen.getByText('This field is required')).toBeInTheDocument()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test('renders error icon with alt text matching the error message', () => {
|
|
17
|
+
render(<TextInputMessage errorMessage='Invalid email' validate={false} />)
|
|
18
|
+
expect(screen.getByAltText('Invalid email')).toBeInTheDocument()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('returns null when errorMessage is empty', () => {
|
|
22
|
+
const { container } = render(<TextInputMessage errorMessage='' validate={false} />)
|
|
23
|
+
expect(container.innerHTML).toBe('')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('returns null when validate is true even with error message', () => {
|
|
27
|
+
const { container } = render(<TextInputMessage errorMessage='Some error' validate={true} />)
|
|
28
|
+
expect(container.innerHTML).toBe('')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('renders with correct CSS classes', () => {
|
|
32
|
+
const { container } = render(<TextInputMessage errorMessage='Error' validate={false} />)
|
|
33
|
+
expect(container.querySelector('.e-text__error')).toBeInTheDocument()
|
|
34
|
+
expect(container.querySelector('.e-text__error-icon')).toBeInTheDocument()
|
|
35
|
+
expect(container.querySelector('.e-text__error-label')).toBeInTheDocument()
|
|
36
|
+
})
|
|
37
|
+
})
|