From 4b08d0bf140f0b3f332c6aa0f00f46dbbdc9ee33 Mon Sep 17 00:00:00 2001 From: Peter Trost Date: Tue, 17 Dec 2024 19:35:51 +0100 Subject: [PATCH] test: Add line chart painter test for minY == maxY --- .../line_chart/line_chart_painter_test.dart | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/test/chart/line_chart/line_chart_painter_test.dart b/test/chart/line_chart/line_chart_painter_test.dart index ea8792a09..5a4079d7d 100644 --- a/test/chart/line_chart/line_chart_painter_test.dart +++ b/test/chart/line_chart/line_chart_painter_test.dart @@ -226,6 +226,111 @@ void main() { } expect(exception != null, true); }); + + test('test 3 minY == maxY', () { + const viewSize = Size(400, 400); + + final bar1 = LineChartBarData( + spots: const [ + FlSpot(0, 4), + FlSpot(1, 3), + FlSpot(2, 2), + FlSpot(3, 1), + FlSpot(4, 0), + ], + showingIndicators: [ + 0, + 2, + 3, + ], + ); + final bar2 = LineChartBarData( + spots: const [ + FlSpot(0, 5), + FlSpot(1, 3), + FlSpot(2, 2), + FlSpot(3, 5), + FlSpot(4, 0), + ], + ); + + final lineChartBarsData = [bar1, bar2]; + final (minX, maxX, minY, maxY) = LineChartHelper().calculateMaxAxisValues( + lineChartBarsData, + ); + + final data = LineChartData( + minX: minX, + maxX: maxX, + minY: minY, + maxY: minY, + lineBarsData: lineChartBarsData, + clipData: const FlClipData.all(), + extraLinesData: ExtraLinesData( + horizontalLines: [ + HorizontalLine(y: 1), + ], + verticalLines: [ + VerticalLine(x: 4), + ], + ), + betweenBarsData: [ + BetweenBarsData(fromIndex: 0, toIndex: 1), + ], + showingTooltipIndicators: [ + ShowingTooltipIndicators([ + LineBarSpot(bar1, 0, bar1.spots.first), + LineBarSpot(bar2, 1, bar2.spots.first), + ]), + ], + lineTouchData: LineTouchData( + getTouchedSpotIndicator: + (LineChartBarData barData, List spotIndexes) { + return spotIndexes.asMap().entries.map((entry) { + final i = entry.key; + if (i == 0) { + return null; + } + return const TouchedSpotIndicatorData( + FlLine(color: MockData.color0), + FlDotData(), + ); + }).toList(); + }, + ), + ); + + final lineChartPainter = LineChartPainter(); + final holder = + PaintHolder(data, data, TextScaler.noScaling); + + final mockUtils = MockUtils(); + Utils.changeInstance(mockUtils); + when(mockUtils.getThemeAwareTextStyle(any, any)) + .thenAnswer((realInvocation) => textStyle1); + when(mockUtils.calculateRotationOffset(any, any)) + .thenAnswer((realInvocation) => Offset.zero); + when(mockUtils.convertRadiusToSigma(any)) + .thenAnswer((realInvocation) => 4.0); + when(mockUtils.getEfficientInterval(any, any)) + .thenAnswer((realInvocation) => 1.0); + when(mockUtils.getBestInitialIntervalValue(any, any, any)) + .thenAnswer((realInvocation) => 1.0); + + final mockBuildContext = MockBuildContext(); + final mockCanvasWrapper = MockCanvasWrapper(); + when(mockCanvasWrapper.size).thenAnswer((realInvocation) => viewSize); + when(mockCanvasWrapper.canvas).thenReturn(MockCanvas()); + lineChartPainter.paint( + mockBuildContext, + mockCanvasWrapper, + holder, + ); + + verify(mockCanvasWrapper.clipRect(any)).called(1); + verify(mockCanvasWrapper.drawDot(any, any, any)).called(12); + verify(mockCanvasWrapper.drawPath(any, any)).called(3); + }); }); group('clipToBorder()', () {