Skip to content

Commit 2794d4a

Browse files
committed
fix(series import): extract price when its enclosed within children tags.
Fix #1229
1 parent edeff10 commit 2794d4a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/ru/mystamps/web/feature/series/importing/extractor/JsoupSiteParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ protected String extractPrice(Element body) {
216216
}
217217

218218
String price = elem.ownText();
219+
if (StringUtils.isBlank(price)) {
220+
price = elem.text();
221+
}
222+
219223
LOG.debug("Extracted price: '{}'", price);
220224
return price;
221225
}

src/test/java/ru/mystamps/web/feature/series/importing/extractor/JsoupSiteParserTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,24 @@ public void extractPriceShouldIgnoreTextOfChildrenTags() {
648648
.isEqualTo(expectedValue);
649649
}
650650

651+
@Test
652+
public void extractPriceShouldFallbackToTextOfChildrenTags() {
653+
parser.setPriceLocator("#price");
654+
655+
String expectedPrice = String.valueOf(Random.price());
656+
String expectedValue = "price:" + expectedPrice;
657+
String html = String.format(
658+
"<span id='price'><b>price:</b><b>%s</b></span>",
659+
expectedPrice
660+
);
661+
Element doc = createDocumentFromText(html);
662+
663+
String price = parser.extractPrice(doc);
664+
665+
assertThat(price).as("couldn't extract price from '%s'", doc)
666+
.isEqualTo(expectedValue);
667+
}
668+
651669
//
652670
// Tests for extractCurrency()
653671
//

0 commit comments

Comments
 (0)