Merge pull request #135 from inventree/unit-testing

Unit testing

(cherry picked from commit d55f594342)
This commit is contained in:
Oliver 2022-05-22 10:11:36 +10:00 committed by Oliver Walters
parent 10b435f4fa
commit cfc9f09b80
35 changed files with 893 additions and 317 deletions

View file

@ -7,8 +7,22 @@
* supressing trailing zeroes
*/
import "dart:io";
import "package:audioplayers/audioplayers.dart";
import "package:inventree/app_settings.dart";
import "package:one_context/one_context.dart";
/*
* Display a debug message if we are in testing mode, or running in debug mode
*/
void debug(dynamic msg) {
if (Platform.environment.containsKey("FLUTTER_TEST")) {
print("DEBUG: ${msg.toString()}");
}
}
String simpleNumberString(double number) {
// Ref: https://stackoverflow.com/questions/55152175/how-to-remove-trailing-zeros-using-dart
@ -16,22 +30,19 @@ String simpleNumberString(double number) {
return number.toStringAsFixed(number.truncateToDouble() == number ? 0 : 1);
}
Future<void> successTone() async {
/*
* Play an audio file from the requested path.
*
* Note: If OneContext module fails the 'hasContext' check,
* we will not attempt to play the sound
*/
Future<void> playAudioFile(String path) async {
final bool en = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
if (en) {
final player = AudioCache();
player.play("sounds/barcode_scan.mp3");
if (!OneContext.hasContext) {
return;
}
final player = AudioCache();
player.play(path);
}
Future <void> failureTone() async {
final bool en = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
if (en) {
final player = AudioCache();
player.play("sounds/barcode_error.mp3");
}
}