Skip to content

Commit 0d03303

Browse files
authored
Merge pull request nus-cs2103-AY2021S1#106 from tohyuting/add-productTestCases
Add product test cases
2 parents 74575af + d4b9b8f commit 0d03303

11 files changed

Lines changed: 314 additions & 6 deletions

File tree

src/main/java/seedu/clinic/ui/SupplierCard.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package seedu.clinic.ui;
22

3+
import java.util.Comparator;
4+
35
import javafx.fxml.FXML;
46
import javafx.scene.control.Label;
57
import javafx.scene.layout.FlowPane;
@@ -33,11 +35,13 @@ public class SupplierCard extends UiPart<Region> {
3335
@FXML
3436
private Label phone;
3537
@FXML
36-
private Label remark;
38+
private FlowPane remark;
3739
@FXML
3840
private Label email;
3941
@FXML
4042
private FlowPane products;
43+
@FXML
44+
private FlowPane tags;
4145

4246
/**
4347
* Creates a {@code supplierCode} with the given {@code Supplier} and index to display.
@@ -48,8 +52,16 @@ public SupplierCard(Supplier supplier, int displayedIndex) {
4852
id.setText(displayedIndex + ". ");
4953
name.setText(supplier.getName().fullName);
5054
phone.setText(supplier.getPhone().value);
51-
remark.setText(supplier.getRemark().value);
55+
remark.getChildren().add(new Label(supplier.getRemark().value));
5256
email.setText(supplier.getEmail().value);
57+
supplier.getProducts().stream()
58+
.sorted(Comparator.comparing(product -> product.getProductName().fullName))
59+
.forEach(product -> {
60+
products.getChildren().add(new Label(product.getProductName().fullName));
61+
product.getProductTags().stream()
62+
.sorted(Comparator.comparing(tag -> tag.tagName))
63+
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
64+
});
5365
}
5466

5567
@Override

src/main/java/seedu/clinic/ui/WarehouseCard.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package seedu.clinic.ui;
22

3+
import java.util.Comparator;
4+
35
import javafx.fxml.FXML;
46
import javafx.scene.control.Label;
57
import javafx.scene.layout.FlowPane;
@@ -33,7 +35,7 @@ public class WarehouseCard extends UiPart<Region> {
3335
@FXML
3436
private Label phone;
3537
@FXML
36-
private Label remark;
38+
private FlowPane remark;
3739
@FXML
3840
private Label address;
3941
@FXML
@@ -48,8 +50,11 @@ public WarehouseCard(Warehouse warehouse, int displayedIndex) {
4850
id.setText(displayedIndex + ". ");
4951
name.setText(warehouse.getName().fullName);
5052
phone.setText(warehouse.getPhone().value);
51-
remark.setText(warehouse.getRemark().value);
53+
remark.getChildren().add(new Label(warehouse.getRemark().value));
5254
address.setText(warehouse.getAddress().value);
55+
warehouse.getProducts().stream()
56+
.sorted(Comparator.comparing(product -> product.toStringForWareHouse()))
57+
.forEach(product -> products.getChildren().add(new Label(product.toStringForWareHouse())));
5358
}
5459

5560
@Override

src/main/resources/view/DarkTheme.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,17 @@
350350
-fx-background-radius: 2;
351351
-fx-font-size: 11;
352352
}
353+
354+
#remark {
355+
-fx-hgap: 7;
356+
-fx-vgap: 3;
357+
}
358+
359+
#remark .label {
360+
-fx-text-fill: white;
361+
-fx-background-color: #3e7b91;
362+
-fx-padding: 1 3 1 3;
363+
-fx-border-radius: 2;
364+
-fx-background-radius: 2;
365+
-fx-font-size: 11;
366+
}

src/main/resources/view/SupplierListCard.fxml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
<Label fx:id="name" text="\$first" styleClass="cell_big_label" />
2929
</HBox>
3030
<FlowPane fx:id="products" />
31+
<FlowPane fx:id="tags" />
3132
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" />
3233
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
33-
<Label fx:id="remark" styleClass="cell_small_label" text="\$remark" />
34+
<FlowPane fx:id="remark" />
3435
</VBox>
3536
</GridPane>
3637
</HBox>

src/main/resources/view/WarehouseListCard.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<FlowPane fx:id="products" />
3131
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" />
3232
<Label fx:id="address" styleClass="cell_small_label" text="\$address" />
33-
<Label fx:id="remark" styleClass="cell_small_label" text="\$remark" />
33+
<FlowPane fx:id="remark" />
3434
</VBox>
3535
</GridPane>
3636
</HBox>

src/test/java/seedu/clinic/logic/commands/CommandTestUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public class CommandTestUtil {
4848
public static final String VALID_WAREHOUSE_PRODUCT_TAG_FEVER = "fever";
4949
public static final String VALID_WAREHOUSE_PRODUCT_TAG_HEADACHE = "headache";
5050

51+
// Product test samples
52+
public static final int VALID_PRODUCT_QUANTITY_A = 90;
53+
public static final int VALID_PRODUCT_QUANTITY_B = 600;
54+
5155
// empty string not allowed for addresses
5256
public static final String INVALID_WAREHOUSE_ADDRESS_DESC = " " + PREFIX_ADDRESS;
5357

@@ -62,6 +66,7 @@ public class CommandTestUtil {
6266
public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3";
6367
public static final String VALID_TAG_FEVER = "fever";
6468
public static final String VALID_TAG_ANTIBIOTICS = "antibiotics";
69+
public static final String VALID_TAG_PAINKILLER = "painkiller";
6570
public static final String VALID_REMARK_AMY = "Sells a diverse range of products";
6671
public static final String VALID_REMARK_BOB = "Long term partner";
6772
public static final String VALID_PRODUCT_NAME_PANADOL = "Panadol";
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package seedu.clinic.model.product;
2+
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
import static seedu.clinic.testutil.TypicalProductSupplier.SANITIZER_SUPPLIER;
6+
import static seedu.clinic.testutil.TypicalProductSupplier.SURGICAL_MASK_SUPPLIER;
7+
import static seedu.clinic.testutil.TypicalProductWarehouse.SANITIZER_WAREHOUSE;
8+
import static seedu.clinic.testutil.TypicalProductWarehouse.SURGICAL_MASK_WAREHOUSE;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
import seedu.clinic.testutil.ProductBuilderSupplier;
13+
import seedu.clinic.testutil.ProductBuilderWarehouse;
14+
15+
public class ProductTest {
16+
@Test
17+
public void isSameProductSupplier() {
18+
//same object -> returns true
19+
assertTrue(SANITIZER_SUPPLIER.equals(SANITIZER_SUPPLIER));
20+
21+
//null -> returns false
22+
assertFalse(SANITIZER_SUPPLIER.equals(null));
23+
24+
// different name -> returns false
25+
Product editedSanitizerSupplier = new ProductBuilderSupplier(SANITIZER_SUPPLIER)
26+
.withName("Lifebuoy").build();
27+
assertFalse(SANITIZER_SUPPLIER.equals(editedSanitizerSupplier));
28+
29+
//different name and tag -> returns false
30+
Product editedMaskSupplier = new ProductBuilderSupplier(SURGICAL_MASK_SUPPLIER).withName("housebrand")
31+
.withTags("protects").build();
32+
assertFalse(SURGICAL_MASK_SUPPLIER.equals(editedMaskSupplier));
33+
34+
//different tag, same name -> returns true
35+
Product editedMaskTagsSupplier = new ProductBuilderSupplier(SURGICAL_MASK_SUPPLIER)
36+
.withTags("protects").build();
37+
assertTrue(SURGICAL_MASK_SUPPLIER.equals(editedMaskTagsSupplier));
38+
}
39+
40+
@Test
41+
public void isSameProductWarehouse() {
42+
//same object -> returns true
43+
assertTrue(SANITIZER_WAREHOUSE.equals(SANITIZER_WAREHOUSE));
44+
45+
//null -> returns false
46+
assertFalse(SANITIZER_WAREHOUSE.equals(null));
47+
48+
// different name -> returns false
49+
Product editedSanitizerWarehouse = new ProductBuilderWarehouse(SANITIZER_WAREHOUSE)
50+
.withName("Lifebuoy").build();
51+
assertFalse(SANITIZER_WAREHOUSE.equals(editedSanitizerWarehouse));
52+
53+
//different name and quantity -> returns false
54+
Product editedMaskWarehouse = new ProductBuilderWarehouse(SURGICAL_MASK_WAREHOUSE)
55+
.withName("housebrand").withQuantity(100).build();
56+
assertFalse(SURGICAL_MASK_WAREHOUSE.equals(editedMaskWarehouse));
57+
58+
//different quantity, same name -> returns true
59+
Product editedMaskTagsWarehouse = new ProductBuilderWarehouse(SURGICAL_MASK_WAREHOUSE)
60+
.withQuantity(100).build();
61+
assertTrue(SURGICAL_MASK_WAREHOUSE.equals(editedMaskTagsWarehouse));
62+
}
63+
64+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package seedu.clinic.testutil;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
import seedu.clinic.model.attribute.Name;
7+
import seedu.clinic.model.attribute.Tag;
8+
import seedu.clinic.model.product.Product;
9+
import seedu.clinic.model.util.SampleDataUtil;
10+
11+
/**
12+
* A utility class to help with building Product objects for Supplier.
13+
*/
14+
public class ProductBuilderSupplier {
15+
public static final String DEFAULT_NAME = "Thermometer";
16+
public static final Set<Tag> DEFAULT_TAGS = new HashSet<>();
17+
18+
private Name productName;
19+
private Set<Tag> productTags;
20+
21+
/**
22+
* Creates a {@code ProductBuilderSupplier} with the default details.
23+
*/
24+
public ProductBuilderSupplier() {
25+
productName = new Name(DEFAULT_NAME);
26+
productTags = DEFAULT_TAGS;
27+
}
28+
29+
/**
30+
* Initializes the ProductBuilderSupplier with the data of {@code productToCopy}.
31+
*/
32+
public ProductBuilderSupplier(Product productToCopy) {
33+
productName = productToCopy.getProductName();
34+
productTags = productToCopy.getProductTags();
35+
}
36+
37+
/**
38+
* Sets the {@code Name} of the {@code Product} that we are building.
39+
*/
40+
public ProductBuilderSupplier withName(String name) {
41+
this.productName = new Name(name);
42+
return this;
43+
}
44+
45+
/**
46+
* Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code Product} that we are building.
47+
*/
48+
public ProductBuilderSupplier withTags(String... tags) {
49+
this.productTags = SampleDataUtil.getTagSet(tags);
50+
return this;
51+
}
52+
53+
public Product build() {
54+
return new Product(productName, productTags);
55+
}
56+
57+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package seedu.clinic.testutil;
2+
3+
import seedu.clinic.model.attribute.Name;
4+
import seedu.clinic.model.product.Product;
5+
6+
/**
7+
* A utility class to help with building Product objects for Warehouse.
8+
*/
9+
public class ProductBuilderWarehouse {
10+
public static final String DEFAULT_NAME = "Thermometer";
11+
public static final int DEFAULT_QUANTITY = 50;
12+
13+
private Name productName;
14+
private int productQuantity;
15+
16+
/**
17+
* Creates a {@code ProductBuilderWarehouse} with the default details.
18+
*/
19+
public ProductBuilderWarehouse() {
20+
productName = new Name(DEFAULT_NAME);
21+
productQuantity = DEFAULT_QUANTITY;
22+
}
23+
24+
/**
25+
* Initializes the ProductBuilderWarehouse with the data of {@code productToCopy}.
26+
*/
27+
public ProductBuilderWarehouse(Product productToCopy) {
28+
productName = productToCopy.getProductName();
29+
productQuantity = productToCopy.getProductQuantity();
30+
}
31+
32+
/**
33+
* Sets the {@code Name} of the {@code Product} that we are building.
34+
*/
35+
public ProductBuilderWarehouse withName(String name) {
36+
this.productName = new Name(name);
37+
return this;
38+
}
39+
40+
/**
41+
* Sets the quantity of the {@code Product} that we are building.
42+
*/
43+
public ProductBuilderWarehouse withQuantity(int productQuantity) {
44+
this.productQuantity = productQuantity;
45+
return this;
46+
}
47+
48+
public Product build() {
49+
return new Product(productName, productQuantity);
50+
}
51+
52+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package seedu.clinic.testutil;
2+
3+
import static seedu.clinic.logic.commands.CommandTestUtil.VALID_PRODUCT_NAME_ASPIRIN;
4+
import static seedu.clinic.logic.commands.CommandTestUtil.VALID_PRODUCT_NAME_PANADOL;
5+
import static seedu.clinic.logic.commands.CommandTestUtil.VALID_TAG_FEVER;
6+
import static seedu.clinic.logic.commands.CommandTestUtil.VALID_TAG_PAINKILLER;
7+
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
12+
import seedu.clinic.model.product.Product;
13+
14+
/**
15+
* A utility class containing a list of {@code Product} objects to be used in tests.
16+
*/
17+
public class TypicalProductSupplier {
18+
public static final Product DEFAULT_PRODUCT = new ProductBuilderSupplier().build();
19+
20+
//Manually Added
21+
22+
public static final Product SANITIZER_SUPPLIER = new ProductBuilderSupplier().withName("Dettol Sanitizer")
23+
.withTags("germsfree", "topchoice").build();
24+
public static final Product SURGICAL_MASK_SUPPLIER = new ProductBuilderSupplier().withName("Surgical mask")
25+
.withTags("cheap", "durable").build();
26+
public static final Product PLASTER_SUPPLIER = new ProductBuilderSupplier().withName("Plaster")
27+
.withTags("waterproof").build();
28+
public static final Product CHARCOAL_PILL_SUPPLIER = new ProductBuilderSupplier().withName("Charcoal Pills")
29+
.withTags("diarrhoea").build();
30+
public static final Product LATEX_GLOVES_SUPPLIER = new ProductBuilderSupplier().withName("Latex Gloves")
31+
.withTags("durable").build();
32+
public static final Product STETHOSCOPE_SUPPLIER = new ProductBuilderSupplier().withName("stethoscope")
33+
.withTags("professional").build();
34+
35+
// Manually added - Product's details found in {@code CommandTestUtil}
36+
public static final Product ASPIRIN_SUPPLIER = new ProductBuilderSupplier().withName(VALID_PRODUCT_NAME_ASPIRIN)
37+
.withTags(VALID_TAG_PAINKILLER).build();
38+
public static final Product PANADOL_SUPPLIER = new ProductBuilderSupplier().withName(VALID_PRODUCT_NAME_PANADOL)
39+
.withTags(VALID_TAG_FEVER, VALID_TAG_PAINKILLER).build();
40+
41+
private TypicalProductSupplier() {} // prevents instantiation
42+
43+
public static List<Product> getTypicalProductSupplier() {
44+
return new ArrayList<>(Arrays.asList(SANITIZER_SUPPLIER, SURGICAL_MASK_SUPPLIER, PLASTER_SUPPLIER,
45+
CHARCOAL_PILL_SUPPLIER, LATEX_GLOVES_SUPPLIER, STETHOSCOPE_SUPPLIER,
46+
ASPIRIN_SUPPLIER, PANADOL_SUPPLIER));
47+
}
48+
49+
}

0 commit comments

Comments
 (0)