Skip to content

Commit

Permalink
fix: unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Aug 12, 2024
1 parent 2ba2ad9 commit 08e46b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ public static Mono<String> injectSrcset(String html,
static String buildSizesAttr() {
var sb = new StringBuilder();
var delimiter = ", ";
for (ThumbnailSize size : ThumbnailSize.values()) {
sb.append("(max-width: ").append(size.getWidth()).append("px) ")
var sizes = ThumbnailSize.values();
for (int i = 0; i < sizes.length; i++) {
var size = sizes[i];
sb.append("(max-width: ").append(size.getWidth()).append("px)")
.append(" ")
.append(size.getWidth())
.append("px")
.append(delimiter);
.append("px");
if (i < sizes.length - 1) {
sb.append(delimiter);
}
}
sb.deleteCharAt(sb.length() - delimiter.length());
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ void injectSrcset() {
""";
var result = HtmlThumbnailSrcsetInjector.injectSrcset(html,
src -> Mono.just(src + " 480w, " + src + " 800w")).block();
assertThat(result).isEqualTo("""
assertThat(result).isEqualToIgnoringWhitespace("""
<div>
<img src="image1.jpg" alt="test" srcset="image1.jpg 480w, image1.jpg 800w">
<img src="image1.jpg" alt="test" srcset="image1.jpg 480w, image1.jpg 800w"\
sizes="(max-width: 400px) 400px, (max-width: 800px) 800px,\
(max-width: 1200px) 1200px, (max-width: 1600px) 1600px">
<img src="image2.jpg" srcset="image2-small.jpg 480w, image2-large.jpg 800w">
</div>
""");
Expand Down

0 comments on commit 08e46b2

Please sign in to comment.