@@ -21,11 +21,14 @@ import {
2121} from '@spectrum-charts/constants' ;
2222
2323import {
24+ getHighlightPoint ,
2425 getHighlightPointFill ,
2526 getHighlightPointSize ,
2627 getHighlightPointStroke ,
2728 getHighlightPointStrokeOpacity ,
2829 getHighlightPointStrokeWidth ,
30+ getSecondaryHighlightPoint ,
31+ getSelectionPoint ,
2932} from './linePointUtils' ;
3033import { defaultLineMarkOptions } from './lineTestUtils' ;
3134
@@ -121,3 +124,127 @@ describe('getHighlightPointStrokeWidth()', () => {
121124 expect ( rules [ 0 ] ) . toHaveProperty ( `test` , `datum.${ staticPoint } && datum.${ staticPoint } === true` ) ;
122125 } ) ;
123126} ) ;
127+
128+ describe ( 'getHighlightPoint()' , ( ) => {
129+ test ( 'should return symbol mark with correct name and description' , ( ) => {
130+ const mark = getHighlightPoint ( defaultLineMarkOptions ) ;
131+ expect ( mark . name ) . toBe ( 'line0_point_highlight' ) ;
132+ expect ( mark . description ) . toBe ( 'line0_point_highlight' ) ;
133+ } ) ;
134+
135+ test ( 'should return symbol mark with correct properties' , ( ) => {
136+ const mark = getHighlightPoint ( defaultLineMarkOptions ) ;
137+ expect ( mark . type ) . toBe ( 'symbol' ) ;
138+ expect ( mark . interactive ) . toBe ( false ) ;
139+ expect ( mark . from ) . toEqual ( { data : 'line0_highlightedData' } ) ;
140+ } ) ;
141+
142+ test ( 'should have correct encode structure' , ( ) => {
143+ const mark = getHighlightPoint ( defaultLineMarkOptions ) ;
144+ expect ( mark . encode ) . toBeDefined ( ) ;
145+ expect ( mark . encode ?. enter ) . toBeDefined ( ) ;
146+ expect ( mark . encode ?. update ) . toBeDefined ( ) ;
147+ expect ( mark . encode ?. enter ?. y ) . toEqual ( { field : 'value' , scale : 'yLinear' } ) ;
148+ expect ( mark . encode ?. enter ?. stroke ) . toEqual ( { field : DEFAULT_COLOR , scale : COLOR_SCALE } ) ;
149+ } ) ;
150+
151+ test ( 'should use custom name in mark name and description' , ( ) => {
152+ const customOptions = { ...defaultLineMarkOptions , name : 'customLine' } ;
153+ const mark = getHighlightPoint ( customOptions ) ;
154+ expect ( mark . name ) . toBe ( 'customLine_point_highlight' ) ;
155+ expect ( mark . description ) . toBe ( 'customLine_point_highlight' ) ;
156+ expect ( mark . from ) . toEqual ( { data : 'customLine_highlightedData' } ) ;
157+ } ) ;
158+ } ) ;
159+
160+ describe ( 'getSelectionPoint()' , ( ) => {
161+ test ( 'should return symbol mark with correct name and description' , ( ) => {
162+ const mark = getSelectionPoint ( defaultLineMarkOptions ) ;
163+ expect ( mark . name ) . toBe ( 'line0_point_select' ) ;
164+ expect ( mark . description ) . toBe ( 'line0_point_select' ) ;
165+ } ) ;
166+
167+ test ( 'should return symbol mark with correct properties' , ( ) => {
168+ const mark = getSelectionPoint ( defaultLineMarkOptions ) ;
169+ expect ( mark . type ) . toBe ( 'symbol' ) ;
170+ expect ( mark . interactive ) . toBe ( false ) ;
171+ expect ( mark . from ) . toEqual ( { data : 'line0_selectedData' } ) ;
172+ } ) ;
173+
174+ test ( 'should have correct encode structure' , ( ) => {
175+ const mark = getSelectionPoint ( defaultLineMarkOptions ) ;
176+ expect ( mark . encode ) . toBeDefined ( ) ;
177+ expect ( mark . encode ?. enter ) . toBeDefined ( ) ;
178+ expect ( mark . encode ?. update ) . toBeDefined ( ) ;
179+ expect ( mark . encode ?. enter ?. y ) . toEqual ( { field : 'value' , scale : 'yLinear' } ) ;
180+ expect ( mark . encode ?. enter ?. stroke ) . toEqual ( { field : DEFAULT_COLOR , scale : COLOR_SCALE } ) ;
181+ } ) ;
182+
183+ test ( 'should use custom name in mark name and description' , ( ) => {
184+ const customOptions = { ...defaultLineMarkOptions , name : 'customLine' } ;
185+ const mark = getSelectionPoint ( customOptions ) ;
186+ expect ( mark . name ) . toBe ( 'customLine_point_select' ) ;
187+ expect ( mark . description ) . toBe ( 'customLine_point_select' ) ;
188+ expect ( mark . from ) . toEqual ( { data : 'customLine_selectedData' } ) ;
189+ } ) ;
190+
191+ test ( 'should use selectedData instead of highlightedData' , ( ) => {
192+ const highlightMark = getHighlightPoint ( defaultLineMarkOptions ) ;
193+ const selectionMark = getSelectionPoint ( defaultLineMarkOptions ) ;
194+ expect ( highlightMark . from ) . toEqual ( { data : 'line0_highlightedData' } ) ;
195+ expect ( selectionMark . from ) . toEqual ( { data : 'line0_selectedData' } ) ;
196+ expect ( highlightMark . name ) . toContain ( 'highlight' ) ;
197+ expect ( selectionMark . name ) . toContain ( 'select' ) ;
198+ } ) ;
199+ } ) ;
200+
201+ describe ( 'getSecondaryHighlightPoint()' , ( ) => {
202+ const secondaryMetric = 'trendlineValue' ;
203+
204+ test ( 'should return symbol mark with correct name and description' , ( ) => {
205+ const mark = getSecondaryHighlightPoint ( defaultLineMarkOptions , secondaryMetric ) ;
206+ expect ( mark . name ) . toBe ( 'line0_secondaryPoint' ) ;
207+ expect ( mark . description ) . toBe ( 'line0_secondaryPoint' ) ;
208+ } ) ;
209+
210+ test ( 'should return symbol mark with correct properties' , ( ) => {
211+ const mark = getSecondaryHighlightPoint ( defaultLineMarkOptions , secondaryMetric ) ;
212+ expect ( mark . type ) . toBe ( 'symbol' ) ;
213+ expect ( mark . interactive ) . toBe ( false ) ;
214+ expect ( mark . from ) . toEqual ( { data : 'line0_highlightedData' } ) ;
215+ } ) ;
216+
217+ test ( 'should have correct encode structure with secondary metric' , ( ) => {
218+ const mark = getSecondaryHighlightPoint ( defaultLineMarkOptions , secondaryMetric ) ;
219+ expect ( mark . encode ) . toBeDefined ( ) ;
220+ expect ( mark . encode ?. enter ) . toBeDefined ( ) ;
221+ expect ( mark . encode ?. update ) . toBeDefined ( ) ;
222+ expect ( mark . encode ?. enter ?. y ) . toEqual ( { field : secondaryMetric , scale : 'yLinear' } ) ;
223+ expect ( mark . encode ?. enter ?. fill ) . toEqual ( { signal : BACKGROUND_COLOR } ) ;
224+ expect ( mark . encode ?. enter ?. stroke ) . toEqual ( { field : DEFAULT_COLOR , scale : COLOR_SCALE } ) ;
225+ } ) ;
226+
227+ test ( 'should use custom name in mark name and description' , ( ) => {
228+ const customOptions = { ...defaultLineMarkOptions , name : 'customLine' } ;
229+ const mark = getSecondaryHighlightPoint ( customOptions , secondaryMetric ) ;
230+ expect ( mark . name ) . toBe ( 'customLine_secondaryPoint' ) ;
231+ expect ( mark . description ) . toBe ( 'customLine_secondaryPoint' ) ;
232+ expect ( mark . from ) . toEqual ( { data : 'customLine_highlightedData' } ) ;
233+ } ) ;
234+
235+ test ( 'should use the secondary metric for y-axis encoding' , ( ) => {
236+ const metric1 = 'metric1' ;
237+ const metric2 = 'metric2' ;
238+ const mark1 = getSecondaryHighlightPoint ( defaultLineMarkOptions , metric1 ) ;
239+ const mark2 = getSecondaryHighlightPoint ( defaultLineMarkOptions , metric2 ) ;
240+ expect ( mark1 . encode ?. enter ?. y ) . toEqual ( { field : metric1 , scale : 'yLinear' } ) ;
241+ expect ( mark2 . encode ?. enter ?. y ) . toEqual ( { field : metric2 , scale : 'yLinear' } ) ;
242+ } ) ;
243+
244+ test ( 'should use highlightedData like the primary highlight point' , ( ) => {
245+ const mark = getSecondaryHighlightPoint ( defaultLineMarkOptions , secondaryMetric ) ;
246+ const highlightMark = getHighlightPoint ( defaultLineMarkOptions ) ;
247+ expect ( mark . from ) . toEqual ( highlightMark . from ) ;
248+ expect ( mark . from ) . toEqual ( { data : 'line0_highlightedData' } ) ;
249+ } ) ;
250+ } ) ;
0 commit comments