Skip to content

Commit

Permalink
Merge branch 'main' into PE-5029-suspend-data-item-validation-for-cli…
Browse files Browse the repository at this point in the history
…-uploads-during-download-to-investigate-root-cause
  • Loading branch information
thiagocarvalhodev committed Dec 14, 2023
2 parents e9a8827 + a317308 commit 1aa43a9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
8 changes: 8 additions & 0 deletions lib/src/utils/path_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ String getFileExtension({
}
}

String getFileTypeFromMime({required String contentType}) {
return contentType.substring(contentType.lastIndexOf('/') + 1);
}

String getBasenameWithoutExtension({required String filePath}) {
return path.basenameWithoutExtension(filePath);
}

Future<String> _getDefaultIOSDir() async {
final iosDirectory = await path_provider.getApplicationDocumentsDirectory();
final iosDownloadsDirectory = Directory('${iosDirectory.path}/Downloads/');
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ardrive_io
description: A new Flutter package project.
version: 1.4.1
version: 1.4.3
homepage:
publish_to: none

Expand All @@ -13,7 +13,7 @@ dependencies:
sdk: flutter
file_picker:
git:
url: https://github.com/ar-io/flutter_file_picker
url: https://github.com/ardriveapp/flutter_file_picker
ref: master
path_provider: ^2.0.11
permission_handler: ^11.0.0
Expand All @@ -25,7 +25,7 @@ dependencies:
security_scoped_resource: ^0.0.1
file_saver:
git:
url: https://github.com/thiagocarvalhodev/file_saver
url: https://github.com/ardriveapp/file_saver
ref: fix-extension
device_info_plus: ^9.0.3
async: ^2.9.0
Expand Down
60 changes: 57 additions & 3 deletions test/src/utils/path_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:ardrive_io/src/utils/path_utils.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('test method getFolderNameFromPath', () {
group('getFolderNameFromPath method', () {
test('should return correct folder name', () {
expect(getBasenameFromPath('some-folder'), 'some-folder');
expect(getBasenameFromPath('/some-folder'), 'some-folder');
Expand All @@ -17,7 +17,7 @@ void main() {
throwsA(const TypeMatcher<EntityPathException>()));
});
});
group('test method getDirname', () {
group('getDirname method', () {
test('should return correct dirname', () {
expect(getDirname('/some-folder/file'), '/some-folder');
expect(getDirname('/some-folder/path/file.png'), '/some-folder/path');
Expand All @@ -32,7 +32,7 @@ void main() {
});
});

group('test method getFileExtension', () {
group('getFileExtension method', () {
test('should return the extension from contentType and return with the .',
() {
/// .pdf
Expand Down Expand Up @@ -112,4 +112,58 @@ void main() {
expect(ext, 'conf');
});
});

group('getFileTypeFromMime method', () {
test('should return the file type from mimetype', () {
final type = getFileTypeFromMime(contentType: 'application/pdf');
expect(type, 'pdf');
});

test('should return the file type for a different mimetype', () {
final type = getFileTypeFromMime(contentType: 'image/jpeg');
expect(type, 'jpeg');
});

test('should return null for an empty string', () {
final type = getFileTypeFromMime(contentType: '');
expect(type, '');
});
});

group('getBasenameWithoutExtension method', () {
test('should return the basename without extension', () {
final basename = getBasenameWithoutExtension(
filePath: '/hola/que/tal/file.pdf',
);
expect(basename, 'file');
});

test('should return the basename without extension', () {
final basename = getBasenameWithoutExtension(
filePath: '/hola/que/tal/file.pdf.txt',
);
expect(basename, 'file.pdf');
});

test('should return the basename for a different file path', () {
final basename = getBasenameWithoutExtension(
filePath: '/another/path/to/different.file',
);
expect(basename, 'different');
});

test('should return the basename for a file path without extension', () {
final basename = getBasenameWithoutExtension(
filePath: '/path/to/file',
);
expect(basename, 'file');
});

test('should return an empty string for an empty string', () {
final basename = getBasenameWithoutExtension(
filePath: '',
);
expect(basename, '');
});
});
}

0 comments on commit 1aa43a9

Please sign in to comment.