mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-05-19 22:36:51 +08:00
Fixes tests
This commit is contained in:
@ -1,38 +1,36 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
|
||||
import 'src/utils.dart';
|
||||
|
||||
void main() {
|
||||
late ByteData multipleArtboardsBytes;
|
||||
late RiveFile riveFile;
|
||||
|
||||
void loadTestAssets() {
|
||||
multipleArtboardsBytes = ByteData.sublistView(
|
||||
File('assets/animations_0_6_2.riv').readAsBytesSync());
|
||||
}
|
||||
|
||||
setUp(loadTestAssets);
|
||||
setUp(() {
|
||||
final riveBytes = loadFile('assets/rive-flutter-test-asset.riv');
|
||||
riveFile = RiveFile.import(riveBytes);
|
||||
});
|
||||
|
||||
test('Artboards can be read from files', () {
|
||||
RiveFile riveFile = RiveFile.import(multipleArtboardsBytes);
|
||||
expect(riveFile.mainArtboard.name, 'My Artboard');
|
||||
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 riveFile = RiveFile.import(multipleArtboardsBytes);
|
||||
final artboard = riveFile.mainArtboard;
|
||||
expect(artboard.animations.length, 2);
|
||||
expect(artboard.animations.first.name, 'First');
|
||||
expect(artboard.animations.last.name, 'Second');
|
||||
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 riveFile = RiveFile.import(multipleArtboardsBytes);
|
||||
final artboard = riveFile.mainArtboard;
|
||||
expect(artboard.animationByName('First'), isNotNull);
|
||||
expect(artboard.animationByName('Second'), isNotNull);
|
||||
expect(artboard.animationByName('Animation 1'), isNotNull);
|
||||
expect(artboard.animationByName('Animation 2'), isNotNull);
|
||||
expect(artboard.animationByName('Does Not Exist'), isNull);
|
||||
expect(artboard.animationByName('First') is LinearAnimationInstance, true);
|
||||
expect(artboard.animationByName('Animation 1') is LinearAnimationInstance,
|
||||
true);
|
||||
});
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
test/assets/rive-flutter-test-asset.riv
Normal file
BIN
test/assets/rive-flutter-test-asset.riv
Normal file
Binary file not shown.
@ -1,23 +1,19 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
|
||||
import 'src/utils.dart';
|
||||
|
||||
void main() {
|
||||
late Artboard artboard;
|
||||
late RiveFile riveFile;
|
||||
|
||||
void loadTestAssets() {
|
||||
final riveData = ByteData.sublistView(
|
||||
File('assets/one_shot_0_6_5.riv').readAsBytesSync(),
|
||||
);
|
||||
final riveFile = RiveFile.import(riveData);
|
||||
artboard = riveFile.mainArtboard;
|
||||
}
|
||||
|
||||
setUp(loadTestAssets);
|
||||
setUp(() {
|
||||
final riveBytes = loadFile('assets/rive-flutter-test-asset.riv');
|
||||
riveFile = RiveFile.import(riveBytes);
|
||||
});
|
||||
|
||||
test('LinearAnimationInstance exposes direction is either +/-1', () {
|
||||
final artboard = riveFile.mainArtboard;
|
||||
|
||||
expect(artboard.hasAnimations, isTrue);
|
||||
LinearAnimationInstance instance =
|
||||
LinearAnimationInstance(artboard.animations.first as LinearAnimation);
|
||||
@ -31,6 +27,8 @@ void main() {
|
||||
});
|
||||
|
||||
test('LinearAnimationInstance has a valid start and end time', () {
|
||||
final artboard = riveFile.mainArtboard;
|
||||
|
||||
expect(artboard.hasAnimations, isTrue);
|
||||
LinearAnimationInstance instance =
|
||||
LinearAnimationInstance(artboard.animations.first as LinearAnimation);
|
||||
@ -49,6 +47,8 @@ void main() {
|
||||
});
|
||||
|
||||
test('LinearAnimationInstance can be reset', () {
|
||||
final artboard = riveFile.mainArtboard;
|
||||
|
||||
expect(artboard.hasAnimations, isTrue);
|
||||
LinearAnimationInstance instance =
|
||||
LinearAnimationInstance(artboard.animations.first as LinearAnimation);
|
||||
|
@ -1,48 +1,34 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
|
||||
import 'src/utils.dart';
|
||||
|
||||
void main() {
|
||||
late ByteData multipleArtboardsBytes;
|
||||
late RiveFile riveFile;
|
||||
|
||||
void loadTestAssets() {
|
||||
multipleArtboardsBytes = ByteData.sublistView(
|
||||
File('assets/multiple_artboards_0_6_2.riv').readAsBytesSync());
|
||||
}
|
||||
|
||||
setUp(loadTestAssets);
|
||||
|
||||
test('Rive files load', () {
|
||||
// Create a dummy RiveFile
|
||||
RiveFile.import(multipleArtboardsBytes);
|
||||
setUp(() {
|
||||
final riveBytes = loadFile('assets/rive-flutter-test-asset.riv');
|
||||
riveFile = RiveFile.import(riveBytes);
|
||||
});
|
||||
|
||||
test('Rive files contain the correct number of artboards', () {
|
||||
// Create a dummy RiveFile
|
||||
final riveFile = RiveFile.import(multipleArtboardsBytes);
|
||||
expect(riveFile.artboards.length, 4);
|
||||
expect(riveFile.artboards.length, 2);
|
||||
});
|
||||
|
||||
test('A default artboard is available in a Rive file', () {
|
||||
// Create a dummy RiveFile
|
||||
final riveFile = RiveFile.import(multipleArtboardsBytes);
|
||||
expect(riveFile.mainArtboard, isNotNull);
|
||||
expect(riveFile.mainArtboard.name, 'Artboard 1');
|
||||
});
|
||||
|
||||
test('Artboards can be retrieved by name', () {
|
||||
// Create a dummy RiveFile
|
||||
final riveFile = RiveFile.import(multipleArtboardsBytes);
|
||||
|
||||
var artboard = riveFile.artboardByName('Artboard 1');
|
||||
expect(artboard, isNotNull);
|
||||
expect(artboard!.name, 'Artboard 1');
|
||||
|
||||
artboard = riveFile.artboardByName('Artboard 3');
|
||||
artboard = riveFile.artboardByName('Artboard 2');
|
||||
expect(artboard, isNotNull);
|
||||
expect(artboard!.name, 'Artboard 3');
|
||||
expect(artboard!.name, 'Artboard 2');
|
||||
|
||||
artboard = riveFile.artboardByName('Nonexistant');
|
||||
expect(artboard, isNull);
|
||||
|
@ -1,28 +1,22 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
|
||||
import 'src/utils.dart';
|
||||
|
||||
void main() {
|
||||
late ByteData riveData;
|
||||
late RiveFile riveFile;
|
||||
|
||||
void loadTestAssets() {
|
||||
riveData = ByteData.sublistView(
|
||||
File('assets/animations_0_6_2.riv').readAsBytesSync(),
|
||||
);
|
||||
}
|
||||
|
||||
setUp(loadTestAssets);
|
||||
setUp(() {
|
||||
final riveBytes = loadFile('assets/rive-flutter-test-asset.riv');
|
||||
riveFile = RiveFile.import(riveBytes);
|
||||
});
|
||||
|
||||
test('SimpleAnimation exposes mix', () {
|
||||
// Load a Rive file
|
||||
final riveFile = RiveFile.import(riveData);
|
||||
expect(riveFile.mainArtboard.name, 'My Artboard');
|
||||
expect(riveFile.mainArtboard.name, 'Artboard 1');
|
||||
|
||||
final firstController =
|
||||
SimpleAnimation(riveFile.mainArtboard.animations.first.name);
|
||||
expect(firstController.animationName, 'First');
|
||||
expect(firstController.animationName, 'Animation 1');
|
||||
expect(firstController.mix, 1.0);
|
||||
|
||||
firstController.mix = 0.5;
|
||||
@ -35,8 +29,8 @@ void main() {
|
||||
expect(firstController.mix, 0.0);
|
||||
|
||||
final secondController =
|
||||
SimpleAnimation(riveFile.mainArtboard.animations.last.name, mix: 0.8);
|
||||
expect(secondController.animationName, 'Second');
|
||||
SimpleAnimation(riveFile.mainArtboard.animations[1].name, mix: 0.8);
|
||||
expect(secondController.animationName, 'Animation 2');
|
||||
expect(secondController.mix, 0.8);
|
||||
});
|
||||
}
|
||||
|
9
test/src/utils.dart
Normal file
9
test/src/utils.dart
Normal file
@ -0,0 +1,9 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
/// Loads a Rive file from the assets sub-folder
|
||||
ByteData loadFile(String filename) {
|
||||
final file = File(
|
||||
'./${Directory.current.path.endsWith('/test') ? '' : 'test/'}$filename');
|
||||
return ByteData.sublistView(file.readAsBytesSync());
|
||||
}
|
Reference in New Issue
Block a user