1.0.0
This commit is contained in:
79
test/extensions/bar_chart_data_extensions_test.dart
Normal file
79
test/extensions/bar_chart_data_extensions_test.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:fl_chart/src/extensions/bar_chart_data_extension.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../chart/data_pool.dart';
|
||||
|
||||
void main() {
|
||||
group('BarChartDataExtension.calculateGroupsX', () {
|
||||
test('calculates correct positions for basic alignments', () {
|
||||
expect(
|
||||
MockData.barChartData1
|
||||
.copyWith(alignment: BarChartAlignment.start)
|
||||
.calculateGroupsX(100),
|
||||
[9.0, 43.0, 77.0],
|
||||
);
|
||||
|
||||
expect(
|
||||
MockData.barChartData1
|
||||
.copyWith(alignment: BarChartAlignment.end)
|
||||
.calculateGroupsX(100),
|
||||
[23.0, 57.0, 91.0],
|
||||
);
|
||||
|
||||
expect(
|
||||
MockData.barChartData1
|
||||
.copyWith(alignment: BarChartAlignment.center)
|
||||
.calculateGroupsX(100),
|
||||
[16.0, 50.0, 84.0],
|
||||
);
|
||||
|
||||
expect(
|
||||
MockData.barChartData1
|
||||
.copyWith(alignment: BarChartAlignment.spaceBetween)
|
||||
.calculateGroupsX(100),
|
||||
[9.0, 50.0, 91.0],
|
||||
);
|
||||
|
||||
expect(
|
||||
MockData.barChartData1
|
||||
.copyWith(alignment: BarChartAlignment.spaceAround)
|
||||
.calculateGroupsX(100),
|
||||
[16.666666666666668, 50.0, 83.33333333333334],
|
||||
);
|
||||
|
||||
expect(
|
||||
MockData.barChartData1
|
||||
.copyWith(alignment: BarChartAlignment.spaceEvenly)
|
||||
.calculateGroupsX(100),
|
||||
[20.5, 50.0, 79.5],
|
||||
);
|
||||
});
|
||||
|
||||
for (final alignment in [
|
||||
BarChartAlignment.start,
|
||||
BarChartAlignment.end,
|
||||
BarChartAlignment.center,
|
||||
]) {
|
||||
test(
|
||||
'spaces evenly when a groupX exceeds view width for $alignment',
|
||||
() {
|
||||
expect(
|
||||
MockData.barChartData1
|
||||
.copyWith(alignment: alignment)
|
||||
.calculateGroupsX(60),
|
||||
[10.5, 30.0, 49.5],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
test('Throws Assertion error when barGroups is empty', () {
|
||||
expect(
|
||||
() => MockData.barChartData1
|
||||
.copyWith(barGroups: []).calculateGroupsX(100),
|
||||
throwsAssertionError,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
30
test/extensions/border_extension_test.dart
Normal file
30
test/extensions/border_extension_test.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:fl_chart/src/extensions/border_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('Border isVisible()', () {
|
||||
test('test 1', () {
|
||||
final border = Border(
|
||||
left: BorderSide(
|
||||
color: Colors.red.withValues(alpha: 0.00001),
|
||||
width: 10,
|
||||
),
|
||||
);
|
||||
expect(border.isVisible(), true);
|
||||
});
|
||||
|
||||
test('test 2', () {
|
||||
final border = Border.all(width: 0);
|
||||
expect(border.isVisible(), false);
|
||||
});
|
||||
|
||||
test('test 3', () {
|
||||
final border = Border.all(
|
||||
color: Colors.red.withValues(alpha: 0),
|
||||
width: 10,
|
||||
);
|
||||
expect(border.isVisible(), false);
|
||||
});
|
||||
});
|
||||
}
|
||||
18
test/extensions/color_extensions_test.dart
Normal file
18
test/extensions/color_extensions_test.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fl_chart/src/extensions/color_extension.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('test darken', () {
|
||||
expect(
|
||||
const Color(0x11111111).darken(),
|
||||
isSameColorAs(const Color(0x110a0a0a)),
|
||||
);
|
||||
|
||||
expect(
|
||||
const Color(0x11111111).darken(100),
|
||||
isSameColorAs(const Color(0x11000000)),
|
||||
);
|
||||
});
|
||||
}
|
||||
19
test/extensions/edge_insets_extension_test.dart
Normal file
19
test/extensions/edge_insets_extension_test.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:fl_chart/src/extensions/edge_insets_extension.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('test onlyTopBottom', () {
|
||||
const input = EdgeInsets.symmetric(horizontal: 10, vertical: 20);
|
||||
|
||||
expect(
|
||||
input.onlyTopBottom,
|
||||
const EdgeInsets.symmetric(vertical: 20),
|
||||
);
|
||||
|
||||
expect(
|
||||
input.onlyLeftRight,
|
||||
const EdgeInsets.symmetric(horizontal: 10),
|
||||
);
|
||||
});
|
||||
}
|
||||
39
test/extensions/fl_border_data_extension_test.dart
Normal file
39
test/extensions/fl_border_data_extension_test.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:fl_chart/src/extensions/fl_border_data_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('test allSidesPadding', () {
|
||||
expect(
|
||||
FlBorderData(
|
||||
show: false,
|
||||
border: Border.all(
|
||||
color: Colors.red,
|
||||
width: 10,
|
||||
),
|
||||
).allSidesPadding,
|
||||
EdgeInsets.zero,
|
||||
);
|
||||
|
||||
expect(
|
||||
FlBorderData(
|
||||
show: true,
|
||||
border: Border(
|
||||
left: const BorderSide(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
top: BorderSide(
|
||||
width: 10,
|
||||
color: Colors.red.withValues(alpha: 0.5),
|
||||
),
|
||||
bottom: const BorderSide(
|
||||
width: 4,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
).allSidesPadding,
|
||||
const EdgeInsets.fromLTRB(1, 10, 0, 4),
|
||||
);
|
||||
});
|
||||
}
|
||||
19
test/extensions/fl_titles_data_extension_test.dart
Normal file
19
test/extensions/fl_titles_data_extension_test.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:fl_chart/src/extensions/fl_titles_data_extension.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../chart/data_pool.dart';
|
||||
|
||||
void main() {
|
||||
test('test allSidesPadding', () {
|
||||
expect(
|
||||
MockData.flTitlesData1.copyWith(show: false).allSidesPadding,
|
||||
EdgeInsets.zero,
|
||||
);
|
||||
|
||||
expect(
|
||||
MockData.flTitlesData1.allSidesPadding,
|
||||
const EdgeInsets.fromLTRB(27, 16, 16, 16),
|
||||
);
|
||||
});
|
||||
}
|
||||
111
test/extensions/gradient_extension_test.dart
Normal file
111
test/extensions/gradient_extension_test.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'package:fl_chart/src/extensions/gradient_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('GradientExtension.getSafeColorStops', () {
|
||||
group('returns linearly calculated stops', () {
|
||||
test('when no stops are provided', () {
|
||||
expect(
|
||||
const _TestGradient(
|
||||
colors: [Colors.red, Colors.blue],
|
||||
).getSafeColorStops(),
|
||||
[0, 1],
|
||||
);
|
||||
|
||||
expect(
|
||||
const _TestGradient(
|
||||
colors: [Colors.red, Colors.blue, Colors.green],
|
||||
).getSafeColorStops(),
|
||||
[0, 0.5, 1],
|
||||
);
|
||||
});
|
||||
|
||||
test('when less stops than colors are provided', () {
|
||||
expect(
|
||||
const _TestGradient(
|
||||
colors: [Colors.red, Colors.blue, Colors.green],
|
||||
stops: [0.2, 0.8],
|
||||
).getSafeColorStops(),
|
||||
[0, 0.5, 1],
|
||||
);
|
||||
});
|
||||
|
||||
test('when more stops than colors are provided', () {
|
||||
expect(
|
||||
const _TestGradient(
|
||||
colors: [Colors.red, Colors.blue],
|
||||
stops: [0.2, 0.8, 0.9],
|
||||
).getSafeColorStops(),
|
||||
[0, 1],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('returns stops when same length as colors', () {
|
||||
expect(
|
||||
const _TestGradient(
|
||||
colors: [Colors.red, Colors.blue],
|
||||
stops: [0.1, 0.8],
|
||||
).getSafeColorStops(),
|
||||
[0.1, 0.8],
|
||||
);
|
||||
});
|
||||
|
||||
group('throws ArgumentError', () {
|
||||
group('when colors is empty', () {
|
||||
test('without stops', () {
|
||||
expect(
|
||||
() => const _TestGradient(colors: []).getSafeColorStops(),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
|
||||
test('with stops', () {
|
||||
expect(
|
||||
() => const _TestGradient(
|
||||
colors: [],
|
||||
stops: [0.1, 0.8],
|
||||
).getSafeColorStops(),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('when colors length is 1', () {
|
||||
test('without stops', () {
|
||||
expect(
|
||||
() => const _TestGradient(
|
||||
colors: [Colors.red],
|
||||
).getSafeColorStops(),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
|
||||
test('with stops', () {
|
||||
expect(
|
||||
() => const _TestGradient(
|
||||
colors: [Colors.red],
|
||||
stops: [0.1, 0.8],
|
||||
).getSafeColorStops(),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class _TestGradient extends Gradient {
|
||||
const _TestGradient({required super.colors, super.stops});
|
||||
|
||||
@override
|
||||
Shader createShader(Rect rect, {TextDirection? textDirection}) =>
|
||||
throw UnimplementedError();
|
||||
|
||||
@override
|
||||
Gradient scale(double t) => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
Gradient withOpacity(double opacity) => throw UnimplementedError();
|
||||
}
|
||||
55
test/extensions/paint_extension_test.dart
Normal file
55
test/extensions/paint_extension_test.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import 'package:fl_chart/src/extensions/paint_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../chart/data_pool.dart';
|
||||
|
||||
void main() {
|
||||
test('test transparentIfWidthIsZero', () {
|
||||
final paint = Paint()
|
||||
..color = MockData.color0
|
||||
..strokeWidth = 4
|
||||
..transparentIfWidthIsZero();
|
||||
expect(paint.strokeWidth, 4);
|
||||
expect(MockData.color0, paint.color);
|
||||
|
||||
paint
|
||||
..strokeWidth = 0.5
|
||||
..transparentIfWidthIsZero();
|
||||
expect(paint.strokeWidth, 0.5);
|
||||
expect(MockData.color0, paint.color);
|
||||
|
||||
paint
|
||||
..strokeWidth = 0.0
|
||||
..transparentIfWidthIsZero();
|
||||
expect(paint.strokeWidth, 0.0);
|
||||
expect(MockData.color0.withValues(alpha: 0), paint.color);
|
||||
});
|
||||
|
||||
test('test setColorOrGradient', () {
|
||||
final paint = Paint()
|
||||
..color = MockData.color0
|
||||
..setColorOrGradient(null, MockData.gradient1, MockData.rect1);
|
||||
expect(paint.shader, isNotNull);
|
||||
|
||||
paint.setColorOrGradient(MockData.color0, null, MockData.rect1);
|
||||
expect(paint.color, MockData.color0);
|
||||
expect(paint.shader, isNull);
|
||||
});
|
||||
|
||||
test('test setColorOrGradientForLine', () {
|
||||
final paint = Paint()
|
||||
..color = MockData.color0
|
||||
..setColorOrGradientForLine(
|
||||
null,
|
||||
MockData.gradient1,
|
||||
from: MockData.rect1.topLeft,
|
||||
to: MockData.rect1.bottomRight,
|
||||
);
|
||||
expect(paint.shader, isNotNull);
|
||||
|
||||
paint.setColorOrGradient(MockData.color0, null, MockData.rect1);
|
||||
expect(paint.color, MockData.color0);
|
||||
expect(paint.shader, isNull);
|
||||
});
|
||||
}
|
||||
25
test/extensions/path_extension_test.dart
Normal file
25
test/extensions/path_extension_test.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fl_chart/src/extensions/path_extension.dart';
|
||||
import 'package:fl_chart/src/utils/path_drawing/dash_path.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../helper_methods.dart';
|
||||
|
||||
void main() {
|
||||
test('test transparentIfWidthIsZero', () {
|
||||
final path1 = Path()
|
||||
..moveTo(0, 0)
|
||||
..lineTo(10, 0);
|
||||
expect(
|
||||
path1.toDashedPath(null),
|
||||
path1,
|
||||
);
|
||||
|
||||
final path2 =
|
||||
dashPath(path1, dashArray: CircularIntervalList<double>([10.0, 5.0]));
|
||||
|
||||
expect(HelperMethods.equalsPaths(path1.toDashedPath([10, 5]), path2), true);
|
||||
});
|
||||
}
|
||||
16
test/extensions/rrect_extension_test.dart
Normal file
16
test/extensions/rrect_extension_test.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fl_chart/src/extensions/rrect_extension.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../chart/data_pool.dart';
|
||||
|
||||
void main() {
|
||||
test('test getRect', () {
|
||||
expect(
|
||||
MockData.rRect1.getRect(),
|
||||
const Rect.fromLTRB(1, 1, 1, 1),
|
||||
);
|
||||
});
|
||||
}
|
||||
42
test/extensions/side_titles_extension_test.dart
Normal file
42
test/extensions/side_titles_extension_test.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:fl_chart/src/chart/base/axis_chart/axis_chart_data.dart';
|
||||
import 'package:fl_chart/src/extensions/side_titles_extension.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('test totalReservedSize', () {
|
||||
expect(
|
||||
const AxisTitles(
|
||||
axisNameSize: 12,
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 20,
|
||||
),
|
||||
).totalReservedSize,
|
||||
20,
|
||||
);
|
||||
|
||||
expect(
|
||||
const AxisTitles(
|
||||
axisNameWidget: Text('asdf'),
|
||||
axisNameSize: 12,
|
||||
sideTitles: SideTitles(
|
||||
reservedSize: 20,
|
||||
),
|
||||
).totalReservedSize,
|
||||
12,
|
||||
);
|
||||
|
||||
expect(
|
||||
const AxisTitles(
|
||||
axisNameWidget: Text('asdf'),
|
||||
axisNameSize: 12,
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 20,
|
||||
),
|
||||
).totalReservedSize,
|
||||
32,
|
||||
);
|
||||
});
|
||||
}
|
||||
24
test/extensions/size_extension_test.dart
Normal file
24
test/extensions/size_extension_test.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fl_chart/src/extensions/size_extension.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('test rotateByQuarterTurns extension.', () {
|
||||
expect(const Size(100, 200).rotateByQuarterTurns(0), const Size(100, 200));
|
||||
expect(const Size(100, 200).rotateByQuarterTurns(1), const Size(200, 100));
|
||||
expect(const Size(100, 200).rotateByQuarterTurns(2), const Size(100, 200));
|
||||
expect(const Size(100, 200).rotateByQuarterTurns(3), const Size(200, 100));
|
||||
expect(const Size(100, 200).rotateByQuarterTurns(4), const Size(100, 200));
|
||||
expect(const Size(100, 200).rotateByQuarterTurns(5), const Size(200, 100));
|
||||
expect(const Size(100, 200).rotateByQuarterTurns(6), const Size(100, 200));
|
||||
expect(
|
||||
() => const Size(100, 200).rotateByQuarterTurns(-1),
|
||||
throwsArgumentError,
|
||||
);
|
||||
expect(
|
||||
() => const Size(100, 200).rotateByQuarterTurns(-3),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
}
|
||||
58
test/extensions/text_align_extension_test.dart
Normal file
58
test/extensions/text_align_extension_test.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:fl_chart/src/extensions/text_align_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('test getFinalHorizontalAlignment extension.', () {
|
||||
const textAlignLeft = TextAlign.left;
|
||||
const textAlignRight = TextAlign.right;
|
||||
|
||||
expect(
|
||||
textAlignLeft.getFinalHorizontalAlignment(TextDirection.rtl),
|
||||
HorizontalAlignment.left,
|
||||
);
|
||||
expect(
|
||||
textAlignLeft.getFinalHorizontalAlignment(TextDirection.ltr),
|
||||
HorizontalAlignment.left,
|
||||
);
|
||||
|
||||
expect(
|
||||
textAlignRight.getFinalHorizontalAlignment(TextDirection.rtl),
|
||||
HorizontalAlignment.right,
|
||||
);
|
||||
expect(
|
||||
textAlignRight.getFinalHorizontalAlignment(TextDirection.ltr),
|
||||
HorizontalAlignment.right,
|
||||
);
|
||||
|
||||
const textAlignStart = TextAlign.start;
|
||||
expect(
|
||||
textAlignStart.getFinalHorizontalAlignment(TextDirection.ltr),
|
||||
HorizontalAlignment.left,
|
||||
);
|
||||
expect(
|
||||
textAlignStart.getFinalHorizontalAlignment(TextDirection.rtl),
|
||||
HorizontalAlignment.right,
|
||||
);
|
||||
|
||||
const textAlignEnd = TextAlign.end;
|
||||
expect(
|
||||
textAlignEnd.getFinalHorizontalAlignment(TextDirection.rtl),
|
||||
HorizontalAlignment.left,
|
||||
);
|
||||
expect(
|
||||
textAlignEnd.getFinalHorizontalAlignment(TextDirection.ltr),
|
||||
HorizontalAlignment.right,
|
||||
);
|
||||
|
||||
const textAlignCenter = TextAlign.center;
|
||||
expect(
|
||||
textAlignCenter.getFinalHorizontalAlignment(TextDirection.rtl),
|
||||
HorizontalAlignment.center,
|
||||
);
|
||||
expect(
|
||||
textAlignCenter.getFinalHorizontalAlignment(TextDirection.ltr),
|
||||
HorizontalAlignment.center,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user