|
1 | | -import { act, render } from '@testing-library/react'; |
| 1 | +import { act, render, screen } from '@testing-library/react'; |
| 2 | +import classNames from 'classnames'; |
| 3 | +import { ComponentProps, FC } from 'react'; |
2 | 4 | import { afterEach, describe, expect, it } from 'vitest'; |
3 | 5 | import { mergeDeep } from '../../helpers/mergeDeep'; |
4 | 6 | import defaultTheme from '../../theme/default'; |
@@ -83,19 +85,54 @@ describe('Components / Flowbite', () => { |
83 | 85 | expect(mode2).toBe('dark'); |
84 | 86 | expect(documentEl()).toHaveClass('dark'); |
85 | 87 | }); |
| 88 | + |
| 89 | + it('should incapsulate nested themes', () => { |
| 90 | + render( |
| 91 | + <> |
| 92 | + <Flowbite theme={{ theme: { avatar: { size: { md: 'w-1 h-1' } } } }}> |
| 93 | + {/* should be w-1 h-1 */} |
| 94 | + <TestComponent data-testid="first-lvl" /> |
| 95 | + |
| 96 | + <Flowbite theme={{ theme: { avatar: { size: { md: 'w-2 h-2' } } } }}> |
| 97 | + {/* should be w-2 h-2 */} |
| 98 | + <TestComponent data-testid="second-lvl" /> |
| 99 | + |
| 100 | + <Flowbite> |
| 101 | + {/* should be w-2 h-2, closest provider return w-2 h-2 */} |
| 102 | + <TestComponent data-testid="third-lvl" /> |
| 103 | + </Flowbite> |
| 104 | + </Flowbite> |
| 105 | + </Flowbite> |
| 106 | + {/* should be w-10 h-10 default */} |
| 107 | + <TestComponent data-testid="without-provider" /> |
| 108 | + </>, |
| 109 | + ); |
| 110 | + |
| 111 | + const withoutProvider = screen.getByTestId('without-provider'); |
| 112 | + const firstLvlProvider = screen.getByTestId('first-lvl'); |
| 113 | + const secondLvlProvider = screen.getByTestId('second-lvl'); |
| 114 | + const thirdLvlProvider = screen.getByTestId('third-lvl'); |
| 115 | + |
| 116 | + expect(firstLvlProvider).toHaveClass('w-1 h-1'); |
| 117 | + expect(secondLvlProvider).toHaveClass('w-2 h-2'); |
| 118 | + expect(thirdLvlProvider).toHaveClass('w-2 h-2'); |
| 119 | + expect(withoutProvider).toHaveClass('w-10 h-10'); |
| 120 | + }); |
86 | 121 | }); |
87 | 122 | }); |
88 | 123 |
|
89 | 124 | let context: ThemeContextProps; |
90 | | -const TestComponent = () => { |
| 125 | +const TestComponent: FC<ComponentProps<'div'>> = (props) => { |
| 126 | + const { className, ...other } = props; |
91 | 127 | context = useTheme(); |
92 | | - return null; |
| 128 | + |
| 129 | + return <div className={classNames(context.theme.avatar.size.md, className)} {...other} />; |
93 | 130 | }; |
94 | 131 |
|
95 | 132 | const customTheme = { |
96 | 133 | avatar: { |
97 | 134 | size: { |
98 | | - xxl: 'h-64 w-64', |
| 135 | + md: 'h-64 w-64', |
99 | 136 | }, |
100 | 137 | }, |
101 | 138 | }; |
|
0 commit comments