mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-05-20 14:56:37 +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:flutter_test/flutter_test.dart';
|
||||||
import 'package:rive/rive.dart';
|
import 'package:rive/rive.dart';
|
||||||
|
|
||||||
|
import 'src/utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late ByteData multipleArtboardsBytes;
|
late RiveFile riveFile;
|
||||||
|
|
||||||
void loadTestAssets() {
|
setUp(() {
|
||||||
multipleArtboardsBytes = ByteData.sublistView(
|
final riveBytes = loadFile('assets/rive-flutter-test-asset.riv');
|
||||||
File('assets/animations_0_6_2.riv').readAsBytesSync());
|
riveFile = RiveFile.import(riveBytes);
|
||||||
}
|
});
|
||||||
|
|
||||||
setUp(loadTestAssets);
|
|
||||||
|
|
||||||
test('Artboards can be read from files', () {
|
test('Artboards can be read from files', () {
|
||||||
RiveFile riveFile = RiveFile.import(multipleArtboardsBytes);
|
expect(riveFile.mainArtboard.name, 'Artboard 1');
|
||||||
expect(riveFile.mainArtboard.name, 'My Artboard');
|
expect(riveFile.artboards.length, 2);
|
||||||
|
expect(riveFile.artboardByName('Artboard 2'), isNotNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Animations can be read from artboards', () {
|
test('Animations can be read from artboards', () {
|
||||||
final riveFile = RiveFile.import(multipleArtboardsBytes);
|
|
||||||
final artboard = riveFile.mainArtboard;
|
final artboard = riveFile.mainArtboard;
|
||||||
expect(artboard.animations.length, 2);
|
expect(artboard.animations.length, 3);
|
||||||
expect(artboard.animations.first.name, 'First');
|
expect(artboard.animations.first.name, 'Animation 1');
|
||||||
expect(artboard.animations.last.name, 'Second');
|
expect(artboard.animations[1].name, 'Animation 2');
|
||||||
|
expect(artboard.animations.last.name, 'State Machine 1');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Animations can be read by name from artboards', () {
|
test('Animations can be read by name from artboards', () {
|
||||||
final riveFile = RiveFile.import(multipleArtboardsBytes);
|
|
||||||
final artboard = riveFile.mainArtboard;
|
final artboard = riveFile.mainArtboard;
|
||||||
expect(artboard.animationByName('First'), isNotNull);
|
expect(artboard.animationByName('Animation 1'), isNotNull);
|
||||||
expect(artboard.animationByName('Second'), isNotNull);
|
expect(artboard.animationByName('Animation 2'), isNotNull);
|
||||||
expect(artboard.animationByName('Does Not Exist'), isNull);
|
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:flutter_test/flutter_test.dart';
|
||||||
import 'package:rive/rive.dart';
|
import 'package:rive/rive.dart';
|
||||||
|
|
||||||
|
import 'src/utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late Artboard artboard;
|
late RiveFile riveFile;
|
||||||
|
|
||||||
void loadTestAssets() {
|
setUp(() {
|
||||||
final riveData = ByteData.sublistView(
|
final riveBytes = loadFile('assets/rive-flutter-test-asset.riv');
|
||||||
File('assets/one_shot_0_6_5.riv').readAsBytesSync(),
|
riveFile = RiveFile.import(riveBytes);
|
||||||
);
|
});
|
||||||
final riveFile = RiveFile.import(riveData);
|
|
||||||
artboard = riveFile.mainArtboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
setUp(loadTestAssets);
|
|
||||||
|
|
||||||
test('LinearAnimationInstance exposes direction is either +/-1', () {
|
test('LinearAnimationInstance exposes direction is either +/-1', () {
|
||||||
|
final artboard = riveFile.mainArtboard;
|
||||||
|
|
||||||
expect(artboard.hasAnimations, isTrue);
|
expect(artboard.hasAnimations, isTrue);
|
||||||
LinearAnimationInstance instance =
|
LinearAnimationInstance instance =
|
||||||
LinearAnimationInstance(artboard.animations.first as LinearAnimation);
|
LinearAnimationInstance(artboard.animations.first as LinearAnimation);
|
||||||
@ -31,6 +27,8 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('LinearAnimationInstance has a valid start and end time', () {
|
test('LinearAnimationInstance has a valid start and end time', () {
|
||||||
|
final artboard = riveFile.mainArtboard;
|
||||||
|
|
||||||
expect(artboard.hasAnimations, isTrue);
|
expect(artboard.hasAnimations, isTrue);
|
||||||
LinearAnimationInstance instance =
|
LinearAnimationInstance instance =
|
||||||
LinearAnimationInstance(artboard.animations.first as LinearAnimation);
|
LinearAnimationInstance(artboard.animations.first as LinearAnimation);
|
||||||
@ -49,6 +47,8 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('LinearAnimationInstance can be reset', () {
|
test('LinearAnimationInstance can be reset', () {
|
||||||
|
final artboard = riveFile.mainArtboard;
|
||||||
|
|
||||||
expect(artboard.hasAnimations, isTrue);
|
expect(artboard.hasAnimations, isTrue);
|
||||||
LinearAnimationInstance instance =
|
LinearAnimationInstance instance =
|
||||||
LinearAnimationInstance(artboard.animations.first as LinearAnimation);
|
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:flutter_test/flutter_test.dart';
|
||||||
import 'package:rive/rive.dart';
|
import 'package:rive/rive.dart';
|
||||||
|
|
||||||
|
import 'src/utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late ByteData multipleArtboardsBytes;
|
late RiveFile riveFile;
|
||||||
|
|
||||||
void loadTestAssets() {
|
setUp(() {
|
||||||
multipleArtboardsBytes = ByteData.sublistView(
|
final riveBytes = loadFile('assets/rive-flutter-test-asset.riv');
|
||||||
File('assets/multiple_artboards_0_6_2.riv').readAsBytesSync());
|
riveFile = RiveFile.import(riveBytes);
|
||||||
}
|
|
||||||
|
|
||||||
setUp(loadTestAssets);
|
|
||||||
|
|
||||||
test('Rive files load', () {
|
|
||||||
// Create a dummy RiveFile
|
|
||||||
RiveFile.import(multipleArtboardsBytes);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Rive files contain the correct number of artboards', () {
|
test('Rive files contain the correct number of artboards', () {
|
||||||
// Create a dummy RiveFile
|
expect(riveFile.artboards.length, 2);
|
||||||
final riveFile = RiveFile.import(multipleArtboardsBytes);
|
|
||||||
expect(riveFile.artboards.length, 4);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('A default artboard is available in a Rive file', () {
|
test('A default artboard is available in a Rive file', () {
|
||||||
// Create a dummy RiveFile
|
// Create a dummy RiveFile
|
||||||
final riveFile = RiveFile.import(multipleArtboardsBytes);
|
|
||||||
expect(riveFile.mainArtboard, isNotNull);
|
expect(riveFile.mainArtboard, isNotNull);
|
||||||
expect(riveFile.mainArtboard.name, 'Artboard 1');
|
expect(riveFile.mainArtboard.name, 'Artboard 1');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Artboards can be retrieved by name', () {
|
test('Artboards can be retrieved by name', () {
|
||||||
// Create a dummy RiveFile
|
|
||||||
final riveFile = RiveFile.import(multipleArtboardsBytes);
|
|
||||||
|
|
||||||
var artboard = riveFile.artboardByName('Artboard 1');
|
var artboard = riveFile.artboardByName('Artboard 1');
|
||||||
expect(artboard, isNotNull);
|
expect(artboard, isNotNull);
|
||||||
expect(artboard!.name, 'Artboard 1');
|
expect(artboard!.name, 'Artboard 1');
|
||||||
|
|
||||||
artboard = riveFile.artboardByName('Artboard 3');
|
artboard = riveFile.artboardByName('Artboard 2');
|
||||||
expect(artboard, isNotNull);
|
expect(artboard, isNotNull);
|
||||||
expect(artboard!.name, 'Artboard 3');
|
expect(artboard!.name, 'Artboard 2');
|
||||||
|
|
||||||
artboard = riveFile.artboardByName('Nonexistant');
|
artboard = riveFile.artboardByName('Nonexistant');
|
||||||
expect(artboard, isNull);
|
expect(artboard, isNull);
|
||||||
|
@ -1,28 +1,22 @@
|
|||||||
import 'dart:io';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:rive/rive.dart';
|
import 'package:rive/rive.dart';
|
||||||
|
|
||||||
|
import 'src/utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
late ByteData riveData;
|
late RiveFile riveFile;
|
||||||
|
|
||||||
void loadTestAssets() {
|
setUp(() {
|
||||||
riveData = ByteData.sublistView(
|
final riveBytes = loadFile('assets/rive-flutter-test-asset.riv');
|
||||||
File('assets/animations_0_6_2.riv').readAsBytesSync(),
|
riveFile = RiveFile.import(riveBytes);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
setUp(loadTestAssets);
|
|
||||||
|
|
||||||
test('SimpleAnimation exposes mix', () {
|
test('SimpleAnimation exposes mix', () {
|
||||||
// Load a Rive file
|
expect(riveFile.mainArtboard.name, 'Artboard 1');
|
||||||
final riveFile = RiveFile.import(riveData);
|
|
||||||
expect(riveFile.mainArtboard.name, 'My Artboard');
|
|
||||||
|
|
||||||
final firstController =
|
final firstController =
|
||||||
SimpleAnimation(riveFile.mainArtboard.animations.first.name);
|
SimpleAnimation(riveFile.mainArtboard.animations.first.name);
|
||||||
expect(firstController.animationName, 'First');
|
expect(firstController.animationName, 'Animation 1');
|
||||||
expect(firstController.mix, 1.0);
|
expect(firstController.mix, 1.0);
|
||||||
|
|
||||||
firstController.mix = 0.5;
|
firstController.mix = 0.5;
|
||||||
@ -35,8 +29,8 @@ void main() {
|
|||||||
expect(firstController.mix, 0.0);
|
expect(firstController.mix, 0.0);
|
||||||
|
|
||||||
final secondController =
|
final secondController =
|
||||||
SimpleAnimation(riveFile.mainArtboard.animations.last.name, mix: 0.8);
|
SimpleAnimation(riveFile.mainArtboard.animations[1].name, mix: 0.8);
|
||||||
expect(secondController.animationName, 'Second');
|
expect(secondController.animationName, 'Animation 2');
|
||||||
expect(secondController.mix, 0.8);
|
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