|
1 | 1 | import { expect } from 'chai'; |
2 | | -import { createRenderer, isJsdom } from '@mui/internal-test-utils'; |
| 2 | +import { createRenderer, isJsdom, screen } from '@mui/internal-test-utils'; |
3 | 3 | import { |
4 | 4 | alpha as systemAlpha, |
5 | 5 | lighten as systemLighten, |
6 | 6 | darken as systemDarken, |
7 | 7 | } from '@mui/system/colorManipulator'; |
8 | 8 | import Button from '@mui/material/Button'; |
| 9 | +import Alert from '@mui/material/Alert'; |
9 | 10 | import Box from '@mui/material/Box'; |
| 11 | +import GlobalStyles from '@mui/material/GlobalStyles'; |
10 | 12 | import { ThemeProvider, createTheme, styled } from '@mui/material/styles'; |
11 | 13 | import { deepOrange, green, grey } from '@mui/material/colors'; |
12 | 14 | import createPalette from './createPalette'; |
@@ -782,4 +784,42 @@ describe('createTheme', () => { |
782 | 784 | ); |
783 | 785 | }); |
784 | 786 | }); |
| 787 | + |
| 788 | + // Skip WebKit and firefox because they have a slightly different value |
| 789 | + it.skipIf(isJSDOM || !/chrome/.test(window.navigator.userAgent))( |
| 790 | + 'should build color-mix() on top of generated Material UI CSS variables', |
| 791 | + () => { |
| 792 | + function App() { |
| 793 | + const theme = createTheme({ |
| 794 | + cssVariables: { |
| 795 | + nativeColor: true, |
| 796 | + }, |
| 797 | + }); |
| 798 | + |
| 799 | + return ( |
| 800 | + <ThemeProvider theme={theme}> |
| 801 | + {/* This is just to replicate the global CSS file */} |
| 802 | + <GlobalStyles |
| 803 | + styles={{ |
| 804 | + ':root': { |
| 805 | + '--mui-palette-info-main': '#d3b613 !important', // !important is to take precedence over the default one. This is just for test, in real world case global CSS file should be used. |
| 806 | + '--mui-palette-info-light': '#dfc21f !important', |
| 807 | + }, |
| 808 | + }} |
| 809 | + /> |
| 810 | + |
| 811 | + <Alert variant="standard" severity="info" data-testid="alert"> |
| 812 | + Alert |
| 813 | + </Alert> |
| 814 | + </ThemeProvider> |
| 815 | + ); |
| 816 | + } |
| 817 | + |
| 818 | + render(<App />); |
| 819 | + |
| 820 | + expect(screen.getByTestId('alert')).toHaveComputedStyle({ |
| 821 | + backgroundColor: 'oklch(0.981465 0.01628 97.7526)', // browser converts color-mix to oklch in window.getComputedStyle() |
| 822 | + }); |
| 823 | + }, |
| 824 | + ); |
785 | 825 | }); |
0 commit comments