Skip to content

Commit

Permalink
Fix: URLCharityScraperTest is now valid
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 13, 2026
1 parent 6c44e69 commit 81e1d3f
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ntnu.systemutvikling.team6.scraper.scraperComponents;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -40,7 +42,7 @@ void updateDescriptionShouldReturnCorrectDescriptionWithoutReadMore() {
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(".information"))).thenReturn(List.of(p1, p2));

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

Expand All @@ -64,13 +66,13 @@ void updateDescriptionShouldReturnCorrectDescriptionWithReadMore() {
when(p1.getText()).thenReturn("Intro");
when(extra.getText()).thenReturn("Extra info");

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

when(scraper.findElements(By.cssSelector("a.read-more"))).thenReturn(List.of(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(".extra-info"))).thenReturn(List.of(extra));

scraper.updateDescription();

Expand Down Expand Up @@ -102,14 +104,18 @@ void updateCategoriesShouldReturnCorrectCategories() {
when(c1.getText()).thenReturn("Health");
when(c2.getText()).thenReturn("Education");

List<String> categories = new ArrayList<>();
categories.add("Health");
categories.add("Education");

when(scraper.findElements(By.cssSelector(".tag-label"))).thenReturn(List.of(c1, c2));

scraper.updateCategories();

assertEquals(
"Health,Education",
categories,
scraper.getCategories(),
"Should return a string that lists categories with ',' as a delimiter.");
"Should return an list that contain two string elements 'Health' and 'Education'.");
}

@Test
Expand Down

0 comments on commit 81e1d3f

Please sign in to comment.