1 | import React from 'react';
|
2 | import { render, screen } from '@testing-library/react';
|
3 | import '@testing-library/jest-dom';
|
4 | import { FormGroup } from '..';
|
5 | import {
|
6 | testForChildrenInComponent,
|
7 | testForCustomClass,
|
8 | testForCustomTag,
|
9 | testForDefaultClass,
|
10 | testForDefaultTag,
|
11 | } from '../testUtils';
|
12 |
|
13 | describe('FormGroup', () => {
|
14 | it('should render with "div" tag by default', () => {
|
15 | testForDefaultTag(FormGroup, 'div');
|
16 | });
|
17 |
|
18 | it('should render children', () => {
|
19 | testForChildrenInComponent(FormGroup);
|
20 | });
|
21 |
|
22 | it('should render with "mb-3" class by default', () => {
|
23 | testForDefaultClass(FormGroup, 'mb-3');
|
24 | });
|
25 |
|
26 | it('should not render with "form-check" nor "form-check-inline" class by default', () => {
|
27 | render(<FormGroup>Yo!</FormGroup>);
|
28 |
|
29 | expect(screen.getByText('Yo!')).not.toHaveClass('form-check');
|
30 | expect(screen.getByText('Yo!')).not.toHaveClass('form-check-inline');
|
31 | });
|
32 |
|
33 | it('should render with "form-check" class when check prop is truthy', () => {
|
34 | render(<FormGroup check>Yo!</FormGroup>);
|
35 | expect(screen.getByText('Yo!')).toHaveClass('form-check');
|
36 | });
|
37 |
|
38 | it('should render with "form-check" and "form-switch" class when switch prop is truthy', () => {
|
39 | render(<FormGroup switch>Yo!</FormGroup>);
|
40 | expect(screen.getByText('Yo!')).toHaveClass('form-check');
|
41 | expect(screen.getByText('Yo!')).toHaveClass('form-switch');
|
42 | });
|
43 |
|
44 | it('should not render with "form-check-inline" class when check prop is truthy and inline prop is falsy', () => {
|
45 | render(<FormGroup check>Yo!</FormGroup>);
|
46 | expect(screen.getByText('Yo!')).not.toHaveClass('form-check-inline');
|
47 | });
|
48 |
|
49 | it('should not render with "form-check-inline" class when switch prop is truthy and inline prop is falsy', () => {
|
50 | render(<FormGroup switch>Yo!</FormGroup>);
|
51 | expect(screen.getByText('Yo!')).not.toHaveClass('form-check-inline');
|
52 | });
|
53 |
|
54 | it('should render with "form-check" and "form-check-inline" classes when check prop and inline prop are both truthy', () => {
|
55 | render(
|
56 | <FormGroup check inline>
|
57 | Yo!
|
58 | </FormGroup>,
|
59 | );
|
60 | expect(screen.getByText('Yo!')).toHaveClass('form-check');
|
61 | expect(screen.getByText('Yo!')).toHaveClass('form-check-inline');
|
62 | });
|
63 |
|
64 | it('should render with "form-check" and "form-switch" and "form-check-inline" classes when check prop and inline prop are both truthy', () => {
|
65 | render(
|
66 | <FormGroup switch inline>
|
67 | Yo!
|
68 | </FormGroup>,
|
69 | );
|
70 | expect(screen.getByText('Yo!')).toHaveClass('form-check');
|
71 | expect(screen.getByText('Yo!')).toHaveClass('form-switch');
|
72 | expect(screen.getByText('Yo!')).toHaveClass('form-check-inline');
|
73 | });
|
74 |
|
75 | it('should not render with "form-check-inline" class when check and switch prop are falsy and inline prop is truthy', () => {
|
76 | render(<FormGroup inline>Yo!</FormGroup>);
|
77 |
|
78 | expect(screen.getByText('Yo!')).not.toHaveClass('form-check');
|
79 | });
|
80 |
|
81 | it('should not render with "mb-3" class when noMargin prop is truthy', () => {
|
82 | render(<FormGroup noMargin>Yo!</FormGroup>);
|
83 |
|
84 | expect(screen.getByText('Yo!')).not.toHaveClass('mb-3');
|
85 | });
|
86 |
|
87 | it('should not render with "mb-3" class when check prop is truthy', () => {
|
88 | render(<FormGroup check>Yo!</FormGroup>);
|
89 |
|
90 | expect(screen.getByText('Yo!')).not.toHaveClass('mb-3');
|
91 | });
|
92 |
|
93 | it('should not render with "mb-3" class when switch prop is truthy', () => {
|
94 | render(<FormGroup switch>Yo!</FormGroup>);
|
95 |
|
96 | expect(screen.getByText('Yo!')).not.toHaveClass('mb-3');
|
97 | });
|
98 |
|
99 | it('should not render with "disabled" class when disabled prop is truthy but check and switch are not', () => {
|
100 | render(<FormGroup disabled>Yo!</FormGroup>);
|
101 |
|
102 | expect(screen.getByText('Yo!')).not.toHaveClass('disabled');
|
103 | });
|
104 |
|
105 | it('should render with "disabled" class when both check disabled props are truthy', () => {
|
106 | render(
|
107 | <FormGroup check disabled>
|
108 | Yo!
|
109 | </FormGroup>,
|
110 | );
|
111 |
|
112 | expect(screen.getByText('Yo!')).toHaveClass('disabled');
|
113 | expect(screen.getByText('Yo!')).toHaveClass('form-check');
|
114 | });
|
115 |
|
116 | it('should render with "disabled" class when both switch and disabled props are truthy', () => {
|
117 | render(
|
118 | <FormGroup switch disabled>
|
119 | Yo!
|
120 | </FormGroup>,
|
121 | );
|
122 |
|
123 | expect(screen.getByText('Yo!')).toHaveClass('disabled');
|
124 | expect(screen.getByText('Yo!')).toHaveClass('form-check');
|
125 | });
|
126 |
|
127 | it('should render with "row" class when row prop is truthy', () => {
|
128 | render(<FormGroup row>Yo!</FormGroup>);
|
129 |
|
130 | expect(screen.getByText('Yo!')).toHaveClass('row');
|
131 | });
|
132 |
|
133 | it('should not render with "row" class when row prop is not truthy', () => {
|
134 | render(<FormGroup>Yo!</FormGroup>);
|
135 |
|
136 | expect(screen.getByText('Yo!')).not.toHaveClass('row');
|
137 | });
|
138 |
|
139 | it('should render with "form-floating" class when floating prop is truthy', () => {
|
140 | render(<FormGroup floating>Yo!</FormGroup>);
|
141 |
|
142 | expect(screen.getByText('Yo!')).toHaveClass('form-floating');
|
143 | });
|
144 |
|
145 | it('should not render with "form-floating" class when floating prop is falsey', () => {
|
146 | render(<FormGroup>Yo!</FormGroup>);
|
147 |
|
148 | expect(screen.getByText('Yo!')).not.toHaveClass('form-floating');
|
149 | });
|
150 |
|
151 | it('should render additional classes', () => {
|
152 | testForCustomClass(FormGroup);
|
153 | });
|
154 |
|
155 | it('should render custom tag', () => {
|
156 | testForCustomTag(FormGroup);
|
157 | });
|
158 | });
|