-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from muhdbhz/bugfix-listinglabels
ListingCard: Fix Ui to accomodate malicious input + update tests
- Loading branch information
Showing
2 changed files
with
133 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.HashSet; | ||
|
@@ -73,26 +72,6 @@ public void start(Stage stage) { | |
stage.show(); | ||
} | ||
|
||
@Test | ||
void listingCard_uiComponentsAreVisible() { | ||
assertNotNull(listingCard.getName()); | ||
assertNotNull(listingCard.getPrice()); | ||
assertNotNull(listingCard.getArea()); | ||
assertNotNull(listingCard.getRegion()); | ||
assertNotNull(listingCard.getAddress()); | ||
assertNotNull(listingCard.getSeller()); | ||
assertNotNull(listingCard.getBuyers()); | ||
|
||
assertTrue(listingCard.getName().isVisible()); | ||
assertTrue(listingCard.getPrice().isVisible()); | ||
assertTrue(listingCard.getArea().isVisible()); | ||
assertTrue(listingCard.getRegion().isVisible()); | ||
assertTrue(listingCard.getAddress().isVisible()); | ||
assertTrue(listingCard.getSeller().isVisible()); | ||
assertTrue(listingCard.getBuyers().isVisible()); | ||
} | ||
|
||
|
||
@Test | ||
void listingCard_displayCorrectDetails() { | ||
// Assert that the listing object is not null | ||
|
@@ -120,6 +99,36 @@ void listingCard_displayCorrectDetails() { | |
|
||
} | ||
|
||
@Test | ||
void listingCard_displayTruncatedCorrectDetails() { | ||
ListingCard listingCard = new ListingCard(createSampleTruncatedListing(), 1); | ||
|
||
// Assert that the listing object is not null | ||
assertNotNull(listingCard.listing); | ||
|
||
// Check if the displayed name, price, area, region, address, and seller labels are correct | ||
// after truncation | ||
assertEquals("1. ", listingCard.getId().getText()); | ||
assertEquals("Sample Listingggggggggggggggggggggggggggggggg...", | ||
listingCard.getName().getText()); | ||
assertEquals("$500000000000000...", listingCard.getPrice().getText()); | ||
assertEquals("1000000000... m²", listingCard.getArea().getText()); | ||
assertEquals("NORTH", listingCard.getRegion().getText()); | ||
assertEquals("123 Main Sttttttttttttttttttttttttttttttttttttttttttttt...", | ||
listingCard.getAddress().getText()); | ||
assertEquals("John Sellerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...", | ||
listingCard.getSeller().getText()); | ||
|
||
|
||
// Check if the number of buyers is correctly displayed | ||
FlowPane buyersFlowPane = listingCard.getBuyers(); | ||
assertEquals(1, buyersFlowPane.getChildren().size()); | ||
|
||
// Check if the buyer name is accurate (after truncation) | ||
Label buyerOne = (Label) buyersFlowPane.getChildren().get(0); | ||
assertEquals("John Buyerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...", buyerOne.getText()); | ||
} | ||
|
||
@Test | ||
void listingCard_handlesDifferentIndexes() { | ||
// Test ListingCard with various indexes | ||
|
@@ -149,6 +158,25 @@ private Listing createSampleListing() { | |
); | ||
} | ||
|
||
/** | ||
* Helper method to create a sample Listing object for testing (with truncation). | ||
*/ | ||
private Listing createSampleTruncatedListing() { | ||
Set<Person> buyersSet = new HashSet<>(); | ||
buyersSet.add(createSampleTruncatedBuyerOne()); | ||
|
||
return new Listing( | ||
new Name("Sample Listinggggggggggggggggggggggggggggggggggggggggggggggggggggggggg"), | ||
new Address("123 Main Sttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"), | ||
new Price("50000000000000000000000000000000000", | ||
new BigDecimal("50000000000000000000000000000000000")), | ||
new Area("100000000000000000000000000000000000000000000000000000"), | ||
Region.NORTH, | ||
createSampleTruncatedSeller(), | ||
buyersSet | ||
); | ||
} | ||
|
||
/** | ||
* Helper method to create a sample Seller object for testing. | ||
*/ | ||
|
@@ -165,6 +193,21 @@ private Person createSampleSeller() { | |
); | ||
} | ||
|
||
/** | ||
* Helper method to create a sample Seller object for testing (with truncation). | ||
*/ | ||
private Person createSampleTruncatedSeller() { | ||
Set<Tag> tagSet = new HashSet<>(); | ||
|
||
return new Seller( | ||
new Name("John Sellerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"), | ||
new Phone("98765432"), | ||
new Email("[email protected]"), | ||
tagSet, | ||
new Appointment(new Date("02-01-23"), new From("1100"), new To("1200")) | ||
); | ||
} | ||
|
||
/** | ||
* Helper method to create a sample Buyer object for testing. | ||
*/ | ||
|
@@ -182,6 +225,21 @@ private Person createSampleBuyerOne() { | |
); | ||
} | ||
|
||
/** | ||
* Helper method to create a sample Buyer object for testing (with truncation). | ||
*/ | ||
private Person createSampleTruncatedBuyerOne() { | ||
Set<Tag> tagSet = new HashSet<>(); | ||
|
||
return new Buyer( | ||
new Name("John Buyerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"), | ||
new Phone("91234567"), | ||
new Email("[email protected]"), | ||
tagSet, | ||
new Appointment(new Date("01-01-23"), new From("10:00"), new To("11:00")) | ||
); | ||
} | ||
|
||
/** | ||
* Helper method to create a sample Buyer object for testing. | ||
*/ | ||
|