Skip to content

Merge #66 with develop. #67

Merged
merged 4 commits into from
Apr 14, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -37,49 +37,48 @@ void updateDescriptionShouldReturnCorrectDescriptionWithoutReadMore() {
WebElement p1 = mock(WebElement.class);
WebElement p2 = mock(WebElement.class);


when(p1.getText()).thenReturn("Short description");
when(p2.getText()).thenReturn("");

when(scraper.findElements(By.cssSelector(".information div p"))).thenReturn(List.of(p1, p2));

when(scraper.findElements(By.cssSelector("a.read-more"))).thenReturn(List.of());
when(scraper.findElements(By.cssSelector("a.read-more")))
.thenReturn(List.of());

when(scraper.findElements(By.cssSelector(".extra-info p"))).thenReturn(List.of());
when(scraper.findElements(By.cssSelector(".information")))
.thenReturn(List.of(p1, p2));

scraper.updateDescription();

String result = scraper.getDescription();

assertTrue(
result.contains("Short description"), "First paragraph should be 'Short description'");
assertFalse(result.isBlank(), "Second paragraph should be blank.");
assertFalse(result.isBlank(), "Blank paragraph should not be included.");
}

@Test
void updateDescriptionShouldReturnCorrectDescriptionWithReadMore() {
WebElement p1 = mock(WebElement.class);
WebElement extra = mock(WebElement.class);
WebElement readMore = mock(WebElement.class);

when(p1.getText()).thenReturn("Intro");
when(extra.getText()).thenReturn("Extra info");
@Test
void updateDescriptionShouldReturnCorrectDescriptionWithReadMore() {
WebElement p1 = mock(WebElement.class);
WebElement extra = mock(WebElement.class);
WebElement readMore = mock(WebElement.class);

when(scraper.findElements(By.cssSelector(".information div p"))).thenReturn(List.of(p1));
when(p1.getText()).thenReturn("Intro");
when(extra.getText()).thenReturn("Extra info");

when(scraper.findElements(By.cssSelector("a.read-more"))).thenReturn(List.of(readMore));
when(scraper.findElements(By.cssSelector("a.read-more"))).thenReturn(List.of(readMore));

when(scraper.findElement(By.cssSelector("a.read-more"))).thenReturn(readMore);
when(scraper.findElement(By.cssSelector("a.read-more"))).thenReturn(readMore);

when(scraper.findElements(By.cssSelector(".extra-info p"))).thenReturn(List.of(extra));
when(scraper.findElements(By.cssSelector(".information"))).thenReturn(List.of(p1, extra));

scraper.updateDescription();
scraper.updateDescription();

String result = scraper.getDescription();
String result = scraper.getDescription();

verify(readMore).click();
assertTrue(result.contains("Intro"), "First paragraph should be 'Intro'");
assertTrue(result.contains("Extra info"), "Second paragraph should be 'Extra info'");
}
verify(readMore).click();
assertTrue(result.contains("Intro"));
assertTrue(result.contains("Extra info"));
}

@Test
void updateLogoShouldReturnCorrectLogoURL() {
Expand Down Expand Up @@ -156,4 +155,43 @@ void scrapeCharityPageShouldCallAllRelevantMethods() {
// UpdateKeyValues should run
verify(spyScraper).updateKeyValues();
}

@Test
void updateLogoShouldHandleException() {
when(scraper.findElement(By.cssSelector(".logo > img"))).thenThrow(new RuntimeException("Not found"));

scraper.updateLogo();

assertNull(scraper.getLogoURL(), "Program should handle the exception and the logo should be null.");
}

@Test
void updateCategoriesShouldHandleException() {
when(scraper.findElements(By.cssSelector(".tag-label"))).thenThrow(new RuntimeException("Fail"));

scraper.updateCategories();

assertEquals("", scraper.getCategories(), "Program should handle the exception " +
"and the categories should be null.");
}

@Test
void updateKeyValuesShouldHandleException() {
when(scraper.findElement(any(By.class))).thenThrow(new RuntimeException("Fail"));

scraper.updateKeyValues();

assertEquals("", scraper.getKeyValues(), "Program should handle the exception and the " +
"exception and the key values should be empty.");
}

@Test
void updateDescriptionShouldHandleException() {
when(scraper.findElements(any(By.class))).thenThrow(new RuntimeException("Fail"));

scraper.updateDescription();

assertNull(scraper.getDescription(), "Program should handle the exception and the " +
"description should be null.");
}
}
Loading