TF-1822: Write test for all func of FileUtils class
(cherry picked from commit 562f151134416c674467e5a59919ea37adbb7e5f)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import 'package:core/utils/file_utils.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
const String kApplicationDocumentsPath = 'applicationDocumentsPath';
|
||||
|
||||
void main() {
|
||||
const fileName = 'test_file';
|
||||
const fileContent = 'Hello, World!';
|
||||
|
||||
group('fileUtils test', () {
|
||||
setUp(() async {
|
||||
PathProviderPlatform.instance = FakePathProviderPlatform();
|
||||
});
|
||||
|
||||
test('Store private HTLM String to File', () async {
|
||||
|
||||
final file = await FileUtils().saveToFile(fileName, fileContent);
|
||||
|
||||
expect(await file.exists(), equals(true));
|
||||
|
||||
expect(await file.readAsString(), equals(fileContent));
|
||||
|
||||
file.delete();
|
||||
});
|
||||
|
||||
test('Get HTML String from File Private', () async {
|
||||
|
||||
/// Create a temporary file that will be deleted after `getFromFile` is done
|
||||
final file = await FileUtils().saveToFile(fileName, fileContent);
|
||||
|
||||
final htmlString = await FileUtils().getFromFile(fileName);
|
||||
|
||||
expect(htmlString.isNotEmpty, equals(true));
|
||||
|
||||
expect(htmlString, equals(fileContent));
|
||||
|
||||
file.delete();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class FakePathProviderPlatform extends Fake
|
||||
with MockPlatformInterfaceMixin
|
||||
implements PathProviderPlatform {
|
||||
@override
|
||||
Future<String?> getApplicationDocumentsPath() async {
|
||||
return kApplicationDocumentsPath;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user