-
-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for SVG and fixing height/width bug
- Reduced code by putting attributes in a local - Add { } around if's to make code friendlier to code coverage - Add more unit tests to get to 57.4% - Fix height/width bug in svgTagRender (using width for height) - Add height/width to the svgDataImagerRender for Picture.string - Refactored unit tests to simplify and reduce code - Add coverage and scratch directories to .gitignore
- Loading branch information
1 parent
c75e0df
commit d13eb9e
Showing
7 changed files
with
301 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
.pub-cache/ | ||
.pub/ | ||
build/ | ||
coverage/ | ||
scratch/ | ||
|
||
# Android related | ||
**/android/**/gradle-wrapper.jar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter_html_svg/flutter_html_svg.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import './test_utils.dart'; | ||
|
||
void main() { | ||
group("custom image asset tests:", () { | ||
const String svgString = svgRawString; | ||
String makeImgTag({ | ||
String? src, | ||
int? width, | ||
int? height, | ||
}) { | ||
String srcAttr = src != null ? 'src="$src"' : ''; | ||
String widthAttr = width != null ? 'width=$width' : ''; | ||
String heightAttr = height != null ? 'height=$height' : ''; | ||
|
||
return """ | ||
<img $widthAttr $heightAttr $srcAttr /> | ||
"""; | ||
} | ||
|
||
// Happy path (taken from SvgPicture examples) | ||
testMatchAndRender( | ||
"matches and renders img with asset", | ||
makeImgTag(src: "asset:fake.svg", width: 100, height: 100), | ||
svgAssetUriMatcher(), | ||
svgAssetImageRender(bundle: FakeAssetBundle()), | ||
TestResult.matchAndRenderSvgPicture); | ||
|
||
// Failure paths | ||
testMatchAndRender( | ||
"does not match", | ||
makeImgTag(src: "fake.svg"), | ||
svgAssetUriMatcher(), | ||
svgAssetImageRender(bundle: FakeAssetBundle()), | ||
TestResult.noMatch); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'package:flutter_html_svg/flutter_html_svg.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import './test_utils.dart'; | ||
|
||
void main() { | ||
group("custom image data uri tests:", () { | ||
String makeImgTag({ | ||
String? src, | ||
int? width, | ||
int? height, | ||
}) { | ||
String srcAttr = src != null ? 'src="$src"' : ''; | ||
String widthAttr = width != null ? 'width=$width' : ''; | ||
String heightAttr = height != null ? 'height=$height' : ''; | ||
|
||
return """ | ||
<img alt='dummy' $widthAttr $heightAttr $srcAttr /> | ||
"""; | ||
} | ||
|
||
// Happy path (taken from SvgPicture examples) | ||
testMatchAndRender( | ||
"matches and renders image/svg+xml with text encoding", | ||
makeImgTag( | ||
src: 'data:image/svg+xml,$svgEncoded', width: 100, height: 100), | ||
svgDataUriMatcher(encoding: null), | ||
svgDataImageRender(), | ||
TestResult.matchAndRenderSvgPicture); | ||
testMatchAndRender( | ||
"matches and renders image/svg+xml and base64 encoding", | ||
makeImgTag(src: 'data:image/svg+xml;base64,$svgBase64'), | ||
svgDataUriMatcher(), | ||
svgDataImageRender(), | ||
TestResult.matchAndRenderSvgPicture); | ||
|
||
// Failure paths | ||
testMatchAndRender("image tag with no attributes", makeImgTag(), | ||
svgDataUriMatcher(), svgDataImageRender(), TestResult.noMatch); | ||
testMatchAndRender( | ||
"does not match base64 image data uri", | ||
makeImgTag( | ||
src: | ||
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='), | ||
svgDataUriMatcher(), | ||
svgDataImageRender(), | ||
TestResult.noMatch); | ||
testMatchAndRender( | ||
"does not match non-svg mime data", | ||
makeImgTag(src: 'data:text/plain;base64,'), | ||
svgDataUriMatcher(), | ||
svgDataImageRender(), | ||
TestResult.noMatch); | ||
testMatchAndRender( | ||
"does not match non-data schema", | ||
makeImgTag(src: 'http:'), | ||
svgDataUriMatcher(), | ||
svgDataImageRender(), | ||
TestResult.noMatch); | ||
}); | ||
} |
Oops, something went wrong.