|
| 1 | +/** |
| 2 | + * Copyright 2024 Mia srl |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + */ |
| 18 | + |
| 19 | +import Theme from '../../themes/schema' |
| 20 | +import { ThemeProvider } from '../../components/ThemeProvider' |
| 21 | +import { ThemeProviderProps } from '../../components/ThemeProvider/ThemeProvider.props' |
| 22 | +import { generateAntTheme } from '../../components/ThemeProvider/Ant' |
| 23 | +import { renderHook } from '../../test-utils' |
| 24 | +import themes from '../../themes' |
| 25 | +import { useAntTheme } from './useAntTheme' |
| 26 | + |
| 27 | +const { lightTheme } = themes |
| 28 | + |
| 29 | +describe('useAntTheme', () => { |
| 30 | + const themeProvider = (defaultTheme: Theme) => function component({ theme, children }: ThemeProviderProps) { |
| 31 | + return ( |
| 32 | + <ThemeProvider theme={theme ?? defaultTheme}> |
| 33 | + {children} |
| 34 | + </ThemeProvider> |
| 35 | + ) |
| 36 | + } |
| 37 | + |
| 38 | + test('correctly generates ant theme from default theme', () => { |
| 39 | + const antTheme = generateAntTheme(lightTheme) |
| 40 | + |
| 41 | + const { result } = renderHook(() => useAntTheme(), { wrapper: ThemeProvider }) |
| 42 | + |
| 43 | + expect(result.current).toEqual(antTheme) |
| 44 | + }) |
| 45 | + |
| 46 | + for (const [themeName, theme] of Object.entries(themes)) { |
| 47 | + test(`correctly generates ant theme from ${themeName} theme`, () => { |
| 48 | + const antTheme = generateAntTheme(theme) |
| 49 | + |
| 50 | + const { result } = renderHook(() => useAntTheme(), { wrapper: themeProvider(theme) }) |
| 51 | + |
| 52 | + expect(result.current).toEqual(antTheme) |
| 53 | + }) |
| 54 | + } |
| 55 | +}) |
0 commit comments