@@ -2,78 +2,163 @@ import { describe, it, expect, vi, Mock } from "vitest";
22import { getPsuedoEditableElementStyles } from "../getPsuedoEditableStylesElement" ;
33import getCamelCaseStyles from "../getCamelCaseStyles" ;
44import getStyleOfAnElement from "../getStyleOfAnElement" ;
5+ import { getPsuedoEditableEssentialStyles } from "../getPsuedoEditableEssentialStyles" ;
56
67vi . mock ( "../getCamelCaseStyles" ) ;
78vi . mock ( "../getStyleOfAnElement" ) ;
9+ vi . mock ( "../getPsuedoEditableEssentialStyles" ) ;
810
911describe ( "getPsuedoEditableElementStyles" , ( ) => {
10- it ( "should return styles with absolute position and correct top and left values " , ( ) => {
12+ it ( "should return merged styles from getStyleOfAnElement and getPsuedoEditableEssentialStyles " , ( ) => {
1113 const mockElement = {
1214 getBoundingClientRect : vi . fn ( ) . mockReturnValue ( {
1315 top : 100 ,
1416 left : 200 ,
17+ height : 50 ,
1518 } ) ,
1619 } as unknown as HTMLElement ;
1720
18- window . scrollY = 50 ;
19- window . scrollX = 30 ;
20-
2121 const mockStyles = {
2222 color : "red" ,
23- fontSize : "16px" ,
23+ "font-size" : "16px" ,
24+ } ;
25+
26+ const mockEssentialStyles = {
27+ position : "absolute" ,
28+ top : "150px" ,
29+ left : "230px" ,
30+ height : "auto" ,
31+ "white-space" : "normal" ,
32+ "text-transform" : "none" ,
33+ "text-overflow" : "visible" ,
34+ "text-wrap-mode" : "wrap" ,
35+ "min-height" : "50px" ,
2436 } ;
2537
2638 ( getStyleOfAnElement as Mock ) . mockReturnValue ( mockStyles ) ;
39+ ( getPsuedoEditableEssentialStyles as Mock ) . mockReturnValue (
40+ mockEssentialStyles
41+ ) ;
2742
2843 const result = getPsuedoEditableElementStyles ( mockElement ) ;
2944
45+ expect ( getPsuedoEditableEssentialStyles ) . toHaveBeenCalledWith ( {
46+ rect : { top : 100 , left : 200 , height : 50 } ,
47+ camelCase : undefined ,
48+ } ) ;
49+
3050 expect ( result ) . toEqual ( {
3151 color : "red" ,
32- fontSize : "16px" ,
52+ "font-size" : "16px" ,
3353 position : "absolute" ,
3454 top : "150px" ,
3555 left : "230px" ,
3656 height : "auto" ,
37- whiteSpace : "pre-line" ,
38- textTransform : "none" ,
57+ "white-space" : "normal" ,
58+ "text-transform" : "none" ,
59+ "text-overflow" : "visible" ,
60+ "text-wrap-mode" : "wrap" ,
61+ "min-height" : "50px" ,
3962 } ) ;
4063 } ) ;
4164
42- it ( "should return camel case styles if camelCase is true" , ( ) => {
65+ it ( "should apply camelCase conversion when camelCase is true" , ( ) => {
4366 const mockElement = {
4467 getBoundingClientRect : vi . fn ( ) . mockReturnValue ( {
4568 top : 100 ,
4669 left : 200 ,
70+ height : 50 ,
4771 } ) ,
4872 } as unknown as HTMLElement ;
4973
50- window . scrollY = 50 ;
51- window . scrollX = 30 ;
52-
5374 const mockStyles = {
5475 color : "red" ,
55- fontSize : "16px" ,
76+ "font-size" : "16px" ,
5677 } ;
5778
5879 const mockCamelCaseStyles = {
5980 color : "red" ,
6081 fontSize : "16px" ,
6182 } ;
6283
84+ const mockEssentialStyles = {
85+ position : "absolute" ,
86+ top : "150px" ,
87+ left : "230px" ,
88+ height : "auto" ,
89+ whiteSpace : "normal" ,
90+ textTransform : "none" ,
91+ textOverflow : "visible" ,
92+ textWrapMode : "wrap" ,
93+ minHeight : "50px" ,
94+ } ;
95+
6396 ( getStyleOfAnElement as Mock ) . mockReturnValue ( mockStyles ) ;
6497 ( getCamelCaseStyles as Mock ) . mockReturnValue ( mockCamelCaseStyles ) ;
98+ ( getPsuedoEditableEssentialStyles as Mock ) . mockReturnValue (
99+ mockEssentialStyles
100+ ) ;
65101
66102 const result = getPsuedoEditableElementStyles ( mockElement , true ) ;
67103
104+ expect ( getCamelCaseStyles ) . toHaveBeenCalledWith ( mockStyles ) ;
105+ expect ( getPsuedoEditableEssentialStyles ) . toHaveBeenCalledWith ( {
106+ rect : { top : 100 , left : 200 , height : 50 } ,
107+ camelCase : true ,
108+ } ) ;
109+
68110 expect ( result ) . toEqual ( {
69111 color : "red" ,
70112 fontSize : "16px" ,
71113 position : "absolute" ,
72114 top : "150px" ,
73115 left : "230px" ,
74116 height : "auto" ,
75- whiteSpace : "pre-line " ,
117+ whiteSpace : "normal " ,
76118 textTransform : "none" ,
119+ textOverflow : "visible" ,
120+ textWrapMode : "wrap" ,
121+ minHeight : "50px" ,
122+ } ) ;
123+ } ) ;
124+
125+ it ( "should handle merging where essential styles override element styles" , ( ) => {
126+ const mockElement = {
127+ getBoundingClientRect : vi . fn ( ) . mockReturnValue ( {
128+ top : 100 ,
129+ left : 200 ,
130+ height : 50 ,
131+ } ) ,
132+ } as unknown as HTMLElement ;
133+
134+ const mockStyles = {
135+ color : "red" ,
136+ position : "relative" , // This should be overridden by essential styles
137+ height : "100px" , // This should be overridden by essential styles
138+ } ;
139+
140+ const mockEssentialStyles = {
141+ position : "absolute" ,
142+ top : "150px" ,
143+ left : "230px" ,
144+ height : "auto" ,
145+ "min-height" : "50px" ,
146+ } ;
147+
148+ ( getStyleOfAnElement as Mock ) . mockReturnValue ( mockStyles ) ;
149+ ( getPsuedoEditableEssentialStyles as Mock ) . mockReturnValue (
150+ mockEssentialStyles
151+ ) ;
152+
153+ const result = getPsuedoEditableElementStyles ( mockElement ) ;
154+
155+ expect ( result ) . toEqual ( {
156+ color : "red" ,
157+ position : "absolute" , // Overridden by essential styles
158+ top : "150px" ,
159+ left : "230px" ,
160+ height : "auto" , // Overridden by essential styles
161+ "min-height" : "50px" ,
77162 } ) ;
78163 } ) ;
79- } ) ;
164+ } ) ;
0 commit comments