11import { render , fireEvent , screen } from "@testing-library/preact" ;
2- import StartEditingButtonComponent , {
3- getEditButtonPosition ,
4- } from "../startEditingButton" ;
2+ import StartEditingButtonComponent , { getEditButtonPosition } from "../startEditingButton" ;
53import Config from "../../../configManager/configManager" ;
64import { asyncRender } from "../../../__test__/utils" ;
75
86describe ( "StartEditingButtonComponent" , ( ) => {
97 let visualBuilderContainer : HTMLDivElement ;
108
119 beforeEach ( ( ) => {
12- document . getElementsByTagName ( " html" ) [ 0 ] . innerHTML = "" ;
10+ document . getElementsByTagName ( ' html' ) [ 0 ] . innerHTML = '' ;
1311 Config . reset ( ) ;
1412 Config . set ( "stackDetails.apiKey" , "bltapikey" ) ;
1513 Config . set ( "stackDetails.environment" , "bltenvironment" ) ;
@@ -40,9 +38,7 @@ describe("StartEditingButtonComponent", () => {
4038 } ) ;
4139
4240 test ( "should update the href when clicked" , async ( ) => {
43- const { getByTestId } = await asyncRender (
44- < StartEditingButtonComponent />
45- ) ;
41+ const { getByTestId } = await asyncRender ( < StartEditingButtonComponent /> ) ;
4642 const button = getByTestId ( "vcms-start-editing-btn" ) ;
4743
4844 expect ( button ?. getAttribute ( "href" ) ) . toBe (
@@ -52,108 +48,93 @@ describe("StartEditingButtonComponent", () => {
5248
5349 test ( "should not render when enable is false" , async ( ) => {
5450 Config . set ( "editInVisualBuilderButton.enable" , false ) ;
55- const { container } = await asyncRender (
56- < StartEditingButtonComponent />
57- ) ;
51+ const { container } = await asyncRender ( < StartEditingButtonComponent /> ) ;
5852 expect ( container ) . toBeEmptyDOMElement ( ) ;
5953 } ) ;
6054
6155 test ( "should render when enable is true" , async ( ) => {
6256 Config . set ( "editInVisualBuilderButton.enable" , true ) ;
63- const { getByTestId } = await asyncRender (
64- < StartEditingButtonComponent />
65- ) ;
57+ const { getByTestId } = await asyncRender ( < StartEditingButtonComponent /> ) ;
6658 const button = getByTestId ( "vcms-start-editing-btn" ) ;
6759 expect ( button ) . toBeInTheDocument ( ) ;
6860 } ) ;
6961
70- test . each ( [ "bottom-right" , "bottom-left" , "top-left" , "top-right" ] ) (
71- "should return valid position %s" ,
72- ( position ) => {
73- expect ( getEditButtonPosition ( position ) ) . toBe ( position ) ;
74- }
75- ) ;
62+ test . each ( [
63+ 'bottom-right' ,
64+ 'bottom-left' ,
65+ 'top-left' ,
66+ 'top-right'
67+ ] ) ( 'should return valid position %s' , ( position ) => {
68+ expect ( getEditButtonPosition ( position ) ) . toBe ( position ) ;
69+ } ) ;
7670
7771 test . each ( [
78- " invalid-position" ,
79- " center" ,
80- "" ,
72+ ' invalid-position' ,
73+ ' center' ,
74+ '' ,
8175 undefined ,
8276 null ,
8377 123 ,
8478 { } ,
8579 [ ] ,
8680 false ,
87- ] ) (
88- "should return bottom-right for invalid input: %s" ,
89- ( invalidPosition ) => {
90- expect ( getEditButtonPosition ( invalidPosition ) ) . toBe ( "bottom-right" ) ;
91- }
92- ) ;
93-
81+ ] ) ( 'should return bottom-right for invalid input: %s' , ( invalidPosition ) => {
82+ expect ( getEditButtonPosition ( invalidPosition ) ) . toBe ( 'bottom-right' ) ;
83+ } ) ;
84+
9485 test ( "should render with default values when editInVisualBuilderButton config is missing" , async ( ) => {
9586 Config . reset ( ) ;
9687 Config . set ( "stackDetails.apiKey" , "bltapikey" ) ;
9788 Config . set ( "stackDetails.environment" , "bltenvironment" ) ;
9889
99- const { getByTestId } = await asyncRender (
100- < StartEditingButtonComponent />
101- ) ;
90+ const { getByTestId } = await asyncRender ( < StartEditingButtonComponent /> ) ;
10291 const button = getByTestId ( "vcms-start-editing-btn" ) ;
103-
104- expect ( Config . get ( ) . editInVisualBuilderButton . position ) . toBe (
105- "bottom-right"
106- ) ;
92+
93+ expect ( Config . get ( ) . editInVisualBuilderButton . position ) . toBe ( "bottom-right" )
10794 expect ( button ) . toBeInTheDocument ( ) ;
10895 } ) ;
10996
11097 test ( "should update href with current URL when mouse enters button" , async ( ) => {
111- Object . defineProperty ( window , " location" , {
112- value : new URL ( " http://localhost:3000" ) ,
98+ Object . defineProperty ( window , ' location' , {
99+ value : new URL ( ' http://localhost:3000' ) ,
113100 } ) ;
114-
115- const { getByTestId } = await asyncRender (
116- < StartEditingButtonComponent />
117- ) ;
101+
102+ const { getByTestId } = await asyncRender ( < StartEditingButtonComponent /> ) ;
118103 const button = getByTestId ( "vcms-start-editing-btn" ) ;
119104 const initialHref = button . getAttribute ( "href" ) ;
120-
121- Object . defineProperty ( window , " location" , {
122- value : new URL ( " http://localhost:3000/about" ) ,
123- writable : true ,
105+
106+ Object . defineProperty ( window , ' location' , {
107+ value : new URL ( ' http://localhost:3000/about' ) ,
108+ writable : true
124109 } ) ;
125110
126111 fireEvent . mouseEnter ( button ) ;
127-
112+
128113 const updatedHref = button . getAttribute ( "href" ) ;
129114 expect ( updatedHref ) . not . toBe ( initialHref ) ;
130- expect ( updatedHref ) . toContain (
131- encodeURIComponent ( "http://localhost:3000/about" )
132- ) ;
115+ expect ( updatedHref ) . toContain ( encodeURIComponent ( "http://localhost:3000/about" ) ) ;
133116 } ) ;
134117
135118 test ( "should update href with current URL when button is focused" , async ( ) => {
136- Object . defineProperty ( window , " location" , {
137- value : new URL ( " http://localhost:3000" ) ,
119+ Object . defineProperty ( window , ' location' , {
120+ value : new URL ( ' http://localhost:3000' ) ,
138121 } ) ;
139-
140- const { getByTestId } = await asyncRender (
141- < StartEditingButtonComponent />
142- ) ;
122+
123+ const { getByTestId } = await asyncRender ( < StartEditingButtonComponent /> ) ;
143124 const button = getByTestId ( "vcms-start-editing-btn" ) ;
144125 const initialHref = button . getAttribute ( "href" ) ;
145-
146- Object . defineProperty ( window , " location" , {
147- value : new URL ( " http://localhost:3000/contact" ) ,
148- writable : true ,
126+
127+ Object . defineProperty ( window , ' location' , {
128+ value : new URL ( ' http://localhost:3000/contact' ) ,
129+ writable : true
149130 } ) ;
150131
151132 fireEvent . focus ( button ) ;
152-
133+
153134 const updatedHref = button . getAttribute ( "href" ) ;
154135 expect ( updatedHref ) . not . toBe ( initialHref ) ;
155- expect ( updatedHref ) . toContain (
156- encodeURIComponent ( "http://localhost:3000/contact" )
157- ) ;
136+ expect ( updatedHref ) . toContain ( encodeURIComponent ( "http://localhost:3000/contact" ) ) ;
158137 } ) ;
159- } ) ;
138+
139+
140+ } ) ;
0 commit comments