Skip to content

Commit

Permalink
test(color_extension): adapt opacityThresholds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Mar 26, 2023
1 parent 1e26ae3 commit eca0cbb
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions test/utils/color_extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main() {
test('should return a valid threshold to color Map', () {
const color = Colors.blue;
const thresholds = {
1: Color(0x332196f3),
1: Color(0x002196f3),
4: Color(0x552196f3),
8: Color(0xaa2196f3),
12: Color(0xff2196f3),
Expand All @@ -19,13 +19,64 @@ void main() {
);
});

test(
'should return a valid threshold to color Map with custom minOpacity',
() {
const color = Colors.red;
const thresholds = {
1: Color(0x40f44336),
2: Color(0x70f44336),
4: Color(0x9ff44336),
6: Color(0xcff44336),
8: Color(0xfff44336),
};
expect(
color.opacityThresholds(
highestValue: 8,
samples: 4,
minOpacity: 0.25,
),
thresholds,
);
},
);

test('should throw a RangeError if samples is not greater than zero', () {
const color = Colors.blue;
expect(
() => color.opacityThresholds(highestValue: 12, samples: 0),
throwsA(_samplesRangeErrorPredicate),
);
expect(
() => color.opacityThresholds(highestValue: 12, samples: -1),
throwsRangeError,
throwsA(_samplesRangeErrorPredicate),
);
});

test('should throw a RangeError if minOpacity is out of bounds', () {
const color = Colors.blue;
expect(
() => color.opacityThresholds(
highestValue: 12,
samples: 3,
minOpacity: -0.1,
),
throwsA(_minOpacityRangeErrorPredicate),
);
expect(
() => color.opacityThresholds(
highestValue: 12,
samples: 3,
minOpacity: 1.01,
),
throwsA(_minOpacityRangeErrorPredicate),
);
});
});
});
}

final _samplesRangeErrorPredicate =
predicate((e) => e is RangeError && e.name == 'samples');
final _minOpacityRangeErrorPredicate =
predicate((e) => e is RangeError && e.name == 'minOpacity');

0 comments on commit eca0cbb

Please sign in to comment.