Files
rive-flutter/test/artboard_test.dart
HayesGordon e34fc4cc41 feat: adds play and pause to artboard
An oversight from our side. We've previously recommended setting `isActive` to false on the StateMachine or Animation. But this will not propagate down to nested artboards.

Diffs=
e64daefff feat: adds play and pause to artboard (#7078)
2828b7b01 propagate volume to nested artboards (#7067)
4a9947630 Stop audio in iOS when backgrounded. (#7055)

Co-authored-by: Gordon <pggordonhayes@gmail.com>
2024-04-19 09:34:59 +00:00

52 lines
1.8 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:rive/rive.dart';
import 'src/utils.dart';
void main() {
late RiveFile riveFile;
setUp(() {
final riveBytes = loadFile('assets/rive-flutter-test-asset.riv');
riveFile = RiveFile.import(riveBytes);
});
test('Artboards can be read from files', () {
expect(riveFile.mainArtboard.name, 'Artboard 1');
expect(riveFile.artboards.length, 2);
expect(riveFile.artboardByName('Artboard 2'), isNotNull);
});
test('Animations can be read from artboards', () {
final artboard = riveFile.mainArtboard;
expect(artboard.animations.length, 3);
expect(artboard.animations.first.name, 'Animation 1');
expect(artboard.animations[1].name, 'Animation 2');
expect(artboard.animations.last.name, 'State Machine 1');
});
test('Animations can be read by name from artboards', () {
final artboard = riveFile.mainArtboard;
expect(artboard.animationByName('Animation 1'), isNotNull);
expect(artboard.animationByName('Animation 2'), isNotNull);
expect(artboard.animationByName('Does Not Exist'), isNull);
expect(artboard.animationByName('Animation 1') is LinearAnimationInstance,
true);
});
test('Linear animations can be retreived ffrom artboards', () {
final artboard = riveFile.mainArtboard;
expect(artboard.linearAnimations.toList().length, 2);
expect(artboard.stateMachines.toList().length, 1);
});
test('Pausing/Playing an artboard', () {
final artboard = riveFile.mainArtboard.instance();
expect(artboard.isPlaying, true, reason: "Should be true by default");
artboard.pause();
expect(artboard.isPlaying, false, reason: "Should be false after pause");
artboard.play();
expect(artboard.isPlaying, true, reason: "Should be true after play");
});
}