Reputation: 17397
I'd like to know how to unit test the border radius of a container.
I've a box decoration like this:
BoxDecoration getBoxDecoration(ChatThemeData theme) {
return BoxDecoration(
color: isSender
? theme.colorScheme.myBubble
: theme.colorScheme.otherBubble,
borderRadius: BorderRadius.only(
bottomLeft: const Radius.circular(8),
topLeft: tail && !isSender ? Radius.zero : Radius.circular(8),
bottomRight: const Radius.circular(8),
topRight: tail && isSender ? Radius.zero : Radius.circular(8),
),
);
}
and would like to unit test that the border radius is in fact 0 and on the correct side. However I cannot find that property.
testWidgets('Should have tail on the correct side when necessary', (tester) async {
final msgSender = getMsg('hey', MessageTypes.TEXT, isSender: true);
final msgOther = getMsg('hey', MessageTypes.TEXT, isSender: true);
// no tail sender
await tester.pumpWidget(
getWidget(msgSender, onSelected: () {}, tail: false),
);
var ctnrFound = find.byKey(Key('bubble'));
var ctnr = tester.widget<Container>(ctnrFound);
// expect(ctnr., )
});
Upvotes: 0
Views: 593
Reputation: 8258
Does this do what you want?
final decoration = ctnr.decoration as BoxDecoration;
final borderRadius = decoration.borderRadius as BorderRadius;
expect(borderRadius.bottomLeft, Radius.circular(8));
expect(borderRadius.topLeft, Radius.zero);
expect(borderRadius.bottomRight, Radius.circular(8));
expect(borderRadius.topRight, Radius.zero);
Upvotes: 4