Skip to content

Commit

Permalink
Update Help window and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yyihaoc committed Oct 23, 2024
1 parent 2618e0c commit 49b052d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/ui/HelpWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class HelpWindow extends UiPart<Stage> {
+ "4. Edit a Person\n"
+ " Edits an existing contact by index.\n"
+ " Format: edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [t/TELEGRAM] [r/ROLE]\n\n"
+ "5. Find by Name or Role\n"
+ " Finds contacts whose names or roles contain the specified keywords.\n"
+ " Format: find [n/NAME] [r/ROLE]\n\n"
+ "5. Find by Name or Role or Telegram\n"
+ " Finds contacts whose names or roles or telegram handles contain the specified keywords.\n"
+ " Format: find [n/NAME] [r/ROLE] [t/TELEGRAM]\n\n"
+ "6. View contact by telegram handle\n"
+ " View detailed information of a contact with the specified telegram handle\n"
+ " Format: view t/TELEGRAM\n\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void equals() {
secondRolePredicate, secondTelegramPredicate);
FindCommand findFourthCommand = new FindCommand(secondNamePredicate,
firstRolePredicate, firstTelegramPredicate);
FindCommand findFifthCommand = new FindCommand(firstNamePredicate, firstRolePredicate, secondTelegramPredicate);

// same object -> returns true
assertTrue(findFirstCommand.equals(findFirstCommand));
Expand All @@ -78,6 +79,9 @@ public void equals() {

// different role predicate only -> returns false
assertFalse(findFirstCommand.equals(findThirdCommand));

// different telegram predicate only -> returns false
assertFalse(findFirstCommand.equals(findFifthCommand));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package seedu.address.model.person;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.Test;

import seedu.address.testutil.PersonBuilder;

public class TelegramContainsKeywordsPredicateTest {

@Test
public void equals() {
List<String> firstPredicateKeywordList = Collections.singletonList("first");
List<String> secondPredicateKeywordList = Arrays.asList("first", "second");

TelegramContainsKeywordsPredicate firstPredicate = new TelegramContainsKeywordsPredicate(
firstPredicateKeywordList);
TelegramContainsKeywordsPredicate secondPredicate = new TelegramContainsKeywordsPredicate(
secondPredicateKeywordList);

// same object -> returns true
assertTrue(firstPredicate.equals(firstPredicate));

// same values -> returns true
TelegramContainsKeywordsPredicate firstPredicateCopy = new TelegramContainsKeywordsPredicate(
firstPredicateKeywordList);
assertTrue(firstPredicate.equals(firstPredicateCopy));

// different types -> returns false
assertFalse(firstPredicate.equals(1));

// null -> returns false
assertFalse(firstPredicate.equals(null));

// different person -> returns false
assertFalse(firstPredicate.equals(secondPredicate));
}

@Test
public void test_telegramContainsKeywords_returnsTrue() {
// One keyword
TelegramContainsKeywordsPredicate predicate = new TelegramContainsKeywordsPredicate(Collections
.singletonList("javierTan"));
assertTrue(predicate.test(new PersonBuilder().withTelegram("javierTan").build()));

// Multiple keywords
predicate = new TelegramContainsKeywordsPredicate(Arrays.asList("javiertan", "melinda"));
assertTrue(predicate.test(new PersonBuilder().withTelegram("melinda").build()));

// Mixed-case keywords
predicate = new TelegramContainsKeywordsPredicate(Arrays.asList("AbCd", "QqQQ"));
assertTrue(predicate.test(new PersonBuilder().withTelegram("abcd").build()));
}

@Test
public void test_nameDoesNotContainKeywords_returnsFalse() {
// Zero keywords
TelegramContainsKeywordsPredicate predicate = new TelegramContainsKeywordsPredicate(Collections.emptyList());
assertFalse(predicate.test(new PersonBuilder().withTelegram("alisa").build()));

// Non-matching keyword
predicate = new TelegramContainsKeywordsPredicate(Arrays.asList("ben"));
assertFalse(predicate.test(new PersonBuilder().withTelegram("boy").build()));

// Keywords match name, phone and role, but does not match telegram
predicate = new TelegramContainsKeywordsPredicate(Arrays.asList("Alice", "12345678", "alice", "member"));
assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("12345678")
.withTelegram("alicePauline").withRoles("member").build()));
}

@Test
public void toStringMethod() {
List<String> keywords = List.of("keyword1", "keyword2");
TelegramContainsKeywordsPredicate predicate = new TelegramContainsKeywordsPredicate(keywords);

String expected = TelegramContainsKeywordsPredicate.class.getCanonicalName() + "{keywords=" + keywords + "}";
assertEquals(expected, predicate.toString());
}
}

0 comments on commit 49b052d

Please sign in to comment.