Skip to content

Commit

Permalink
TF-3514 Add unit test for getMediaTypeFromBase64ImageTag method
Browse files Browse the repository at this point in the history
Signed-off-by: dab246 <[email protected]>
  • Loading branch information
dab246 committed Mar 7, 2025
1 parent 5edc1d7 commit f100bdd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
47 changes: 47 additions & 0 deletions core/test/utils/string_convert_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,51 @@ void main() {
);
});
});

group('StringConvert::getMediaTypeFromBase64ImageTag::', () {
test('should return correct MediaType for valid JPEG base64 tag', () {
const validJpegTag = 'data:image/jpeg;base64,/9j/4AAQSkZJRg==';
final result = StringConvert.getMediaTypeFromBase64ImageTag(validJpegTag);
expect(result, isNotNull);
expect(result!.type, 'image');
expect(result.subtype, 'jpeg');
});

test('should return correct MediaType for valid PNG base64 tag', () {
const validPngTag = 'data:image/png;base64,iVBORw0KGgo===';
final result = StringConvert.getMediaTypeFromBase64ImageTag(validPngTag);
expect(result, isNotNull);
expect(result!.type, 'image');
expect(result.subtype, 'png');
});

test('should return null for string not starting with "data:"', () {
const invalidTag = 'image/jpeg;base64,/9j/4AAQSkZJRg==';
final result = StringConvert.getMediaTypeFromBase64ImageTag(invalidTag);
expect(result, isNull);
});

test('should return null for string without ";base64,"', () {
const invalidTag = 'data:image/jpeg,/9j/4AAQSkZJRg==';
final result = StringConvert.getMediaTypeFromBase64ImageTag(invalidTag);
expect(result, isNull);
});

test('should return null for invalid format', () {
const invalidTag = 'data:invalid;base64,data';
final result = StringConvert.getMediaTypeFromBase64ImageTag(invalidTag);
expect(result, isNull);
});

test('should return null for empty string', () {
const emptyTag = '';
final result = StringConvert.getMediaTypeFromBase64ImageTag(emptyTag);
expect(result, isNull);
});

test('should handle null input gracefully', () {
const String? nullTag = null;
expect(() => StringConvert.getMediaTypeFromBase64ImageTag(nullTag!), throwsA(isA<TypeError>()));
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ class UploadController extends BaseController {
}

List<Attachment> get inlineAttachmentsUploaded {
if (_uploadingStateInlineFiles.uploadingStateFiles.isEmpty) {
return [];
}
return _uploadingStateInlineFiles.uploadingStateFiles.fold<List<Attachment>>(
[],
(list, fileState) {
Expand All @@ -441,6 +444,9 @@ class UploadController extends BaseController {
}

List<FileInfo> get inlineAttachmentsPicked {
if (_uploadingStateInlineFiles.uploadingStateFiles.isEmpty) {
return [];
}
return _uploadingStateInlineFiles.uploadingStateFiles.fold<List<FileInfo>>(
[],
(list, fileState) {
Expand All @@ -454,6 +460,9 @@ class UploadController extends BaseController {
}

Map<String, Attachment> get mapInlineAttachments {
if (_uploadingStateInlineFiles.uploadingStateFiles.isEmpty) {
return {};
}
final mapInlineAttachments = _uploadingStateInlineFiles.uploadingStateFiles.fold<Map<String, Attachment>>(
{},
(map, fileState) {
Expand Down

0 comments on commit f100bdd

Please sign in to comment.