diff --git "a/docs/M\303\270tedokumenter/Thursdays Meeting 2026.04.09 (With LA).pdf" "b/docs/M\303\270tedokumenter/Thursdays Meeting 2026.04.09 (With LA).pdf" new file mode 100644 index 0000000..0756fa4 Binary files /dev/null and "b/docs/M\303\270tedokumenter/Thursdays Meeting 2026.04.09 (With LA).pdf" differ diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/URLCharityScraperTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/URLCharityScraperTest.java index 82c28cb..20373ac 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/URLCharityScraperTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/URLCharityScraperTest.java @@ -37,14 +37,15 @@ 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(); @@ -52,34 +53,32 @@ void updateDescriptionShouldReturnCorrectDescriptionWithoutReadMore() { 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() { @@ -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."); + } }