1+ import "@testing-library/jest-dom" ;
2+
3+ import { BaseThemeOptions } from "./BaseTheme" ;
4+ import { mergeThemeOptions } from "./ThemeManager" ;
5+
6+ describe ( "Theme Manager merge" , ( ) => {
7+ it ( "should merge" , ( ) => {
8+ const a = { a : 1 , b : 2 } ;
9+ const b = { x : 1 , y : 2 } ;
10+ const new_a = mergeThemeOptions ( a , b ) ;
11+
12+ expect ( new_a ) . toStrictEqual ( { a : 1 , b : 2 , x : 1 , y : 2 } )
13+ } )
14+
15+
16+ it ( "should deep merge" , ( ) => {
17+ const a = { a : 1 , b : 2 , c : { d : 1 , e : 2 } } ;
18+ const b = { x : 1 , y :{ z : 3 } } ;
19+ const merged = mergeThemeOptions ( a , b ) ;
20+
21+ expect ( merged ) . toStrictEqual ( { a : 1 , b : 2 , c : { d : 1 , e : 2 } , x : 1 , y :{ z : 3 } } )
22+ } )
23+
24+ it ( "should use a value over b" , ( ) => {
25+ const a = { a : 100 , b : 2 } ;
26+ const b = { a : 1 , c : 3 } ;
27+ const merged = mergeThemeOptions ( a , b ) ;
28+
29+ expect ( merged ) . toStrictEqual ( { a : 100 , b : 2 , c :3 } )
30+ } )
31+
32+ it ( "should take the base theme and make a new one" , ( ) => {
33+ const fontSize = 4422 ;
34+ const a = { typography : { fontSize : fontSize } } ;
35+ const b = BaseThemeOptions ;
36+
37+ const merged = mergeThemeOptions ( a , b ) ;
38+
39+ expect ( BaseThemeOptions . typography . fontSize ) . not . toStrictEqual ( fontSize )
40+ expect ( merged . typography . fontSize ) . toStrictEqual ( fontSize )
41+ } )
42+
43+ it ( "should effectively clone to an empty object" , ( ) => {
44+ const a = { a : 100 , b : 2 } ;
45+ const cloned = mergeThemeOptions ( { } , a ) ;
46+
47+ expect ( cloned ) . toStrictEqual ( a )
48+ } )
49+
50+ } )
0 commit comments