@@ -134,44 +134,53 @@ describe('paths', () => {
134134 const arrowheadWidth = 3 ;
135135
136136 it ( 'should create an arrow generator function' , ( ) => {
137- const arrowGenerator = arrow ( mockXScale , mockYScale , height , arrowheadLength , arrowheadWidth ) ;
137+ const arrowGenerator = arrow ( mockXScale , mockYScale , arrowheadLength , arrowheadWidth ) ;
138138 expect ( typeof arrowGenerator ) . toBe ( 'function' ) ;
139139 } ) ;
140140
141141 it ( 'should generate correct SVG path for horizontal arrow' , ( ) => {
142- const arrowGenerator = arrow ( mockXScale , mockYScale , height , arrowheadLength , arrowheadWidth ) ;
142+ const arrowGenerator = arrow ( mockXScale , mockYScale , arrowheadLength , arrowheadWidth ) ;
143143 const startData = { index : 0 , value : 10 } ;
144144 const endData = { index : 2 , value : 10 } ;
145145 const result = arrowGenerator ( startData , endData ) ;
146146
147- // Should contain move to start, line to base, and arrowhead
148- expect ( result ) . toContain ( 'M5 50' ) ; // Start point
149- expect ( result ) . toContain ( 'L20 50' ) ; // Base point
150- expect ( result ) . toContain ( 'M25 50' ) ; // End point
147+ // Calculate expected coordinates:
148+ // startX = mockXScale(0) = 0, startY = mockYScale(10) = 50
149+ // endX = mockXScale(2) = 20, endY = mockYScale(10) = 50
150+ // baseX = endX - arrowheadLength * Math.cos(0) = 20 - 5 = 15
151+ expect ( result ) . toContain ( 'M0 50' ) ; // Start point
152+ expect ( result ) . toContain ( 'L15 50' ) ; // Line to base point
153+ expect ( result ) . toContain ( 'M20 50' ) ; // End point
151154 } ) ;
152155
153156 it ( 'should generate correct SVG path for vertical arrow' , ( ) => {
154- const arrowGenerator = arrow ( mockXScale , mockYScale , height , arrowheadLength , arrowheadWidth ) ;
157+ const arrowGenerator = arrow ( mockXScale , mockYScale , arrowheadLength , arrowheadWidth ) ;
155158 const startData = { index : 0 , value : 10 } ;
156159 const endData = { index : 0 , value : 20 } ;
157160 const result = arrowGenerator ( startData , endData ) ;
158161
159- expect ( result ) . toContain ( 'M5 50' ) ; // Start point
160- expect ( result ) . toContain ( 'M5 0' ) ; // End point
162+ // Calculate expected coordinates:
163+ // startX = mockXScale(0) = 0, startY = mockYScale(10) = 50
164+ // endX = mockXScale(0) = 0, endY = mockYScale(20) = 100
165+ expect ( result ) . toContain ( 'M0 50' ) ; // Start point
166+ expect ( result ) . toContain ( 'M0 100' ) ; // End point
161167 } ) ;
162168
163169 it ( 'should generate correct SVG path for diagonal arrow' , ( ) => {
164- const arrowGenerator = arrow ( mockXScale , mockYScale , height , arrowheadLength , arrowheadWidth ) ;
170+ const arrowGenerator = arrow ( mockXScale , mockYScale , arrowheadLength , arrowheadWidth ) ;
165171 const startData = { index : 0 , value : 10 } ;
166172 const endData = { index : 1 , value : 20 } ;
167173 const result = arrowGenerator ( startData , endData ) ;
168174
169- expect ( result ) . toContain ( 'M5 50' ) ; // Start point
170- expect ( result ) . toContain ( 'M15 0' ) ; // End point
175+ // Calculate expected coordinates:
176+ // startX = mockXScale(0) = 0, startY = mockYScale(10) = 50
177+ // endX = mockXScale(1) = 10, endY = mockYScale(20) = 100
178+ expect ( result ) . toContain ( 'M0 50' ) ; // Start point
179+ expect ( result ) . toContain ( 'M10 100' ) ; // End point
171180 } ) ;
172181
173182 it ( 'should use default arrowhead dimensions when not provided' , ( ) => {
174- const arrowGenerator = arrow ( mockXScale , mockYScale , height ) ;
183+ const arrowGenerator = arrow ( mockXScale , mockYScale ) ;
175184 const startData = { index : 0 , value : 10 } ;
176185 const endData = { index : 1 , value : 10 } ;
177186 const result = arrowGenerator ( startData , endData ) ;
@@ -181,22 +190,27 @@ describe('paths', () => {
181190 } ) ;
182191
183192 it ( 'should handle same start and end points' , ( ) => {
184- const arrowGenerator = arrow ( mockXScale , mockYScale , height , arrowheadLength , arrowheadWidth ) ;
193+ const arrowGenerator = arrow ( mockXScale , mockYScale , arrowheadLength , arrowheadWidth ) ;
185194 const startData = { index : 1 , value : 10 } ;
186195 const endData = { index : 1 , value : 10 } ;
187196 const result = arrowGenerator ( startData , endData ) ;
188197
189- expect ( result ) . toContain ( 'M15 50' ) ; // Same start and end
198+ // Calculate expected coordinates:
199+ // startX = endX = mockXScale(1) = 10, startY = endY = mockYScale(10) = 50
200+ expect ( result ) . toContain ( 'M10 50' ) ; // Same start and end
190201 } ) ;
191202
192203 it ( 'should handle negative values' , ( ) => {
193- const arrowGenerator = arrow ( mockXScale , mockYScale , height , arrowheadLength , arrowheadWidth ) ;
204+ const arrowGenerator = arrow ( mockXScale , mockYScale , arrowheadLength , arrowheadWidth ) ;
194205 const startData = { index : 0 , value : - 5 } ;
195206 const endData = { index : 1 , value : 5 } ;
196207 const result = arrowGenerator ( startData , endData ) ;
197208
198- expect ( result ) . toContain ( 'M5 125' ) ; // Start point with negative value
199- expect ( result ) . toContain ( 'M15 75' ) ; // End point
209+ // Calculate expected coordinates:
210+ // startX = mockXScale(0) = 0, startY = mockYScale(-5) = -25
211+ // endX = mockXScale(1) = 10, endY = mockYScale(5) = 25
212+ expect ( result ) . toContain ( 'M0 -25' ) ; // Start point with negative value
213+ expect ( result ) . toContain ( 'M10 25' ) ; // End point
200214 } ) ;
201215 } ) ;
202216} ) ;
0 commit comments