@@ -26,7 +26,10 @@ vi.mock("@mui/x-charts", () => ({
2626 MarkPlot : ( ) => < div data-testid = "mark-plot" /> ,
2727 ChartsXAxis : ( ) => < div data-testid = "x-axis" /> ,
2828 ChartsYAxis : ( ) => < div data-testid = "y-axis" /> ,
29- ChartsLegend : ( ) => < div data-testid = "legend" />
29+ ChartsLegend : ( ) => < div data-testid = "legend" /> ,
30+ ChartsReferenceLine : ( props : any ) => (
31+ < div data-testid = "reference-line" data-x = { props . x } />
32+ )
3033} ) ) ;
3134
3235vi . mock ( "../../hooks/useStyle" , ( ) => ( {
@@ -37,7 +40,8 @@ vi.mock("./xyPlot.utilities", () => ({
3740 buildPlotDataSet : vi . fn ( ) ,
3841 buildSeries : vi . fn ( ) ,
3942 buildXAxes : vi . fn ( ) ,
40- buildYAxes : vi . fn ( )
43+ buildYAxes : vi . fn ( ) ,
44+ buildMarkerDataSet : vi . fn ( )
4145} ) ) ;
4246
4347const mockStyle = {
@@ -46,6 +50,7 @@ const mockStyle = {
4650
4751const baseProps : any = {
4852 traces : [ ] ,
53+ marker : [ ] ,
4954 axes : [ ] ,
5055 pvData : [ ] ,
5156 title : "Test Title" ,
@@ -111,22 +116,63 @@ describe("XYPlotComponent", () => {
111116 baseProps . pvData ,
112117 baseProps . visible
113118 ) ;
114- expect ( utils . buildPlotDataSet ) . toHaveBeenCalledWith ( baseProps . pvData ) ;
119+
120+ expect ( utils . buildPlotDataSet ) . toHaveBeenCalledWith (
121+ baseProps . pvData ,
122+ baseProps . traces
123+ ) ;
124+
125+ expect ( utils . buildMarkerDataSet ) . toHaveBeenCalledWith (
126+ baseProps . pvData ,
127+ baseProps . marker
128+ ) ;
115129 } ) ;
116130
117131 it ( "adds x index when no x-axis data" , ( ) => {
118132 ( utils . buildXAxes as any ) . mockReturnValue ( {
119- xAxis : [ ] ,
133+ xAxis : [ { id : "0" , dataKey : "x" } ] ,
120134 hasXAxisData : false
121135 } ) ;
122136
123- ( utils . buildPlotDataSet as any ) . mockReturnValue ( [ { y : 10 } , { y : 20 } ] ) ;
137+ const mockDataset = [ { y : 10 } , { y : 20 } ] ;
138+ ( utils . buildPlotDataSet as any ) . mockReturnValue ( mockDataset ) ;
139+
140+ render ( < XYPlotComponent { ...baseProps } /> ) ;
141+
142+ // Verify the component rendered (dataset was transformed)
143+ expect ( screen . getByTestId ( "charts-provider" ) ) . toBeInTheDocument ( ) ;
144+ } ) ;
145+
146+ it ( "does not render X-axis when xAxis.visible is false" , ( ) => {
147+ const propsWithHiddenXAxis = {
148+ ...baseProps ,
149+ xAxis : { visible : false }
150+ } ;
151+
152+ render ( < XYPlotComponent { ...propsWithHiddenXAxis } /> ) ;
153+
154+ expect ( screen . queryByTestId ( "x-axis" ) ) . not . toBeInTheDocument ( ) ;
155+ } ) ;
124156
157+ it ( "renders X-axis by default" , ( ) => {
125158 render ( < XYPlotComponent { ...baseProps } /> ) ;
126159
127- const call = ( utils . buildPlotDataSet as any ) . mock . results [ 0 ] . value ;
160+ expect ( screen . getByTestId ( "x-axis" ) ) . toBeInTheDocument ( ) ;
161+ } ) ;
162+
163+ it ( "renders only visible Y-axes" , ( ) => {
164+ ( utils . buildYAxes as any ) . mockReturnValue ( {
165+ yAxes : [
166+ { id : "0" , visible : true } ,
167+ { id : "1" , visible : false }
168+ ] ,
169+ yAxesStyle : { }
170+ } ) ;
171+
172+ render ( < XYPlotComponent { ...baseProps } /> ) ;
128173
129- expect ( call ) . toBeDefined ( ) ;
174+ const yAxes = screen . getAllByTestId ( "y-axis" ) ;
175+ expect ( yAxes ) . toHaveLength ( 1 ) ;
130176 } ) ;
131177
132178 it ( "renders legend when enabled" , ( ) => {
@@ -151,6 +197,53 @@ describe("XYPlotComponent", () => {
151197 ) ;
152198 } ) ;
153199
200+ it ( "renders markers when marker data exists" , ( ) => {
201+ const mockMarkers = [
202+ {
203+ pvName : "marker1" ,
204+ pvValue : 5 ,
205+ visible : true ,
206+ color : { colorString : "red" }
207+ }
208+ ] ;
209+
210+ ( utils . buildMarkerDataSet as any ) . mockReturnValue ( mockMarkers ) ;
211+
212+ render ( < XYPlotComponent { ...baseProps } marker = { mockMarkers } /> ) ;
213+
214+ expect ( screen . getByTestId ( "charts-surface" ) ) . toBeInTheDocument ( ) ;
215+ } ) ;
216+
217+ it ( "only renders visible markers with pvValue" , ( ) => {
218+ const mockMarkers = [
219+ {
220+ pvName : "m1" ,
221+ pvValue : 5 ,
222+ visible : true ,
223+ color : { colorString : "red" }
224+ } ,
225+ {
226+ pvName : "m2" ,
227+ pvValue : null ,
228+ visible : true ,
229+ color : { colorString : "blue" }
230+ } ,
231+ {
232+ pvName : "m3" ,
233+ pvValue : 10 ,
234+ visible : false ,
235+ color : { colorString : "green" }
236+ }
237+ ] ;
238+
239+ ( utils . buildMarkerDataSet as any ) . mockReturnValue ( mockMarkers ) ;
240+
241+ render ( < XYPlotComponent { ...baseProps } /> ) ;
242+
243+ const markers = screen . getAllByTestId ( "reference-line" ) ;
244+ expect ( markers ) . toHaveLength ( 1 ) ;
245+ } ) ;
246+
154247 it ( "passes slotProps logic to LinePlot" , ( ) => {
155248 const traces = [ { traceType : 0 } , { traceType : 1 } ] ;
156249
@@ -173,4 +266,23 @@ describe("XYPlotComponent", () => {
173266 expect ( lineFn ( { seriesId : "1" } ) ) . toEqual ( { } ) ;
174267 expect ( lineFn ( { seriesId : "2" } ) ) . toEqual ( { stroke : "transparent" } ) ;
175268 } ) ;
269+
270+ it ( "handles undefined traces gracefully" , ( ) => {
271+ const propsWithUndefinedTraces = {
272+ ...baseProps ,
273+ traces : undefined
274+ } ;
275+
276+ expect ( ( ) =>
277+ render ( < XYPlotComponent { ...propsWithUndefinedTraces } /> )
278+ ) . not . toThrow ( ) ;
279+ } ) ;
280+
281+ it ( "handles empty pvData" , ( ) => {
282+ ( utils . buildPlotDataSet as any ) . mockReturnValue ( [ ] ) ;
283+
284+ render ( < XYPlotComponent { ...baseProps } pvData = { [ ] } /> ) ;
285+
286+ expect ( screen . queryByTestId ( "charts-provider" ) ) . not . toBeInTheDocument ( ) ;
287+ } ) ;
176288} ) ;
0 commit comments