// ignore_for_file: deprecated_member_use_from_same_package import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:rive/rive.dart'; import 'src/utils.dart'; class MockAssetBundle extends Mock implements AssetBundle {} void main() { setUpAll(() {}); group("Test finding components on artboard", () { test('Find a component of a specific type with a specific name.', () async { final riveBytes = loadFile('assets/component_discovery.riv'); final riveFile = RiveFile.import(riveBytes); final artboard = riveFile.mainArtboard.instance(); final nestedArtboard = artboard.component("NestedArtboardFindMe"); expect(nestedArtboard, isNotNull); expect(nestedArtboard!.name, "NestedArtboardFindMe"); final textRun = artboard.component("TextRunFindMe"); expect(textRun, isNotNull); expect(textRun!.name, "TextRunFindMe"); final shapeEllipse = artboard.component("EllipseFindMe"); expect(shapeEllipse, isNotNull); expect(shapeEllipse!.name, "EllipseFindMe"); final shapeRectangle = artboard.component("RectangleFindMe"); expect(shapeRectangle, isNotNull); expect(shapeRectangle!.name, "RectangleFindMe"); final notFoundComponent = artboard.component("DoesNotExist"); expect(notFoundComponent, isNull); }); test('Get a component that matches the given predicate', () async { final riveBytes = loadFile('assets/component_discovery.riv'); final riveFile = RiveFile.import(riveBytes); final artboard = riveFile.mainArtboard.instance(); final nestedArtboard = artboard.getComponentWhereOrNull( (component) => component.name.startsWith("NestedArtboard")); expect(nestedArtboard, isNotNull); expect(nestedArtboard!.name, "NestedArtboardFindMe"); final textRun = artboard.getComponentWhereOrNull( (component) => component.name.startsWith("TextRun")); expect(textRun, isNotNull); expect(textRun!.name, "TextRunFindMe"); final shapeEllipse = artboard.getComponentWhereOrNull( (component) => component.name.startsWith("Ellipse")); expect(shapeEllipse, isNotNull); expect(shapeEllipse!.name, "EllipseFindMe"); final shapeRectangle = artboard.getComponentWhereOrNull( (component) => component.name.startsWith("Rectangle")); expect(shapeRectangle, isNotNull); expect(shapeRectangle!.name, "RectangleFindMe"); final notFoundComponent = artboard.getComponentWhereOrNull( (component) => component.name.startsWith("DoesNotExist")); expect(notFoundComponent, isNull); }); }); }