File tree Expand file tree Collapse file tree 1 file changed +81
-0
lines changed
Expand file tree Collapse file tree 1 file changed +81
-0
lines changed Original file line number Diff line number Diff line change 1+ import { overrideLonghand } from '../src/utils/override-longhand' ;
2+ import { CreateStyle } from '../src/types/main/create' ;
3+
4+ describe ( 'overrideLonghand' , ( ) => {
5+ test ( 'should remove longhand properties overridden by shorthand properties' , ( ) => {
6+ const style = {
7+ marginTop : '10px' ,
8+ margin : '20px' ,
9+ } as CreateStyle ;
10+ const expected = {
11+ margin : '20px' ,
12+ } ;
13+ expect ( overrideLonghand ( style ) ) . toEqual ( expected ) ;
14+ } ) ;
15+
16+ test ( 'should not remove longhand if shorthand comes before it' , ( ) => {
17+ const style = {
18+ margin : '20px' ,
19+ marginTop : '10px' ,
20+ } as CreateStyle ;
21+ const expected = {
22+ margin : '20px' ,
23+ marginTop : '10px' ,
24+ } ;
25+ expect ( overrideLonghand ( style ) ) . toEqual ( expected ) ;
26+ } ) ;
27+
28+ test ( 'should remove multiple longhands overridden by a single shorthand' , ( ) => {
29+ const style = {
30+ marginTop : '10px' ,
31+ marginLeft : '5px' ,
32+ marginBottom : '15px' ,
33+ marginRight : '5px' ,
34+ margin : '20px' ,
35+ } as CreateStyle ;
36+ const expected = {
37+ margin : '20px' ,
38+ } ;
39+ expect ( overrideLonghand ( style ) ) . toEqual ( expected ) ;
40+ } ) ;
41+
42+ test ( 'should handle nested styles (e.g., @media queries)' , ( ) => {
43+ const style = {
44+ color : 'red' ,
45+ '@media (min-width: 768px)' : {
46+ paddingTop : '10px' ,
47+ padding : '20px' ,
48+ margin : '5px' ,
49+ } ,
50+ paddingLeft : '5px' ,
51+ } as CreateStyle ;
52+ const expected = {
53+ color : 'red' ,
54+ '@media (min-width: 768px)' : {
55+ padding : '20px' ,
56+ margin : '5px' ,
57+ } ,
58+ paddingLeft : '5px' ,
59+ } ;
60+ expect ( overrideLonghand ( style ) ) . toEqual ( expected ) ;
61+ } ) ;
62+ test ( 'should handle nested and flat styles overridden by shorthand properties' , ( ) => {
63+ const style = {
64+ paddingTop : '20px' ,
65+ padding : '30px' ,
66+ '@media (min-width: 768px)' : {
67+ paddingTop : '10px' ,
68+ padding : '20px' ,
69+ } ,
70+ paddingLeft : '5px' ,
71+ } as CreateStyle ;
72+ const expected = {
73+ padding : '30px' ,
74+ '@media (min-width: 768px)' : {
75+ padding : '20px' ,
76+ } ,
77+ paddingLeft : '5px' ,
78+ } ;
79+ expect ( overrideLonghand ( style ) ) . toEqual ( expected ) ;
80+ } ) ;
81+ } ) ;
You can’t perform that action at this time.
0 commit comments