Skip to content

Commit

Permalink
Merge pull request #92 from xuwen-ho/copyCOmmand
Browse files Browse the repository at this point in the history
Improve code coverage and update UG wrt Copy Command
  • Loading branch information
YowSiaoKang authored Apr 3, 2024
2 parents e71fb18 + ca87cf5 commit 371d477
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 22 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion
testImplementation 'org.mockito:mockito-core:3.11.2'

testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
}
Expand Down
23 changes: 23 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ Examples:
* `list` followed by `delete 2` deletes the 2nd person in the address book.
* `find Betsy` followed by `delete 1` deletes the 1st person in the results of the `find` command.

### Copying emails : `copy`

Copies the email addresses of all people in the currently filtered list to the clipboard.

<div markdown="block" class="alert alert-info">

**Notes about the command:**<br>

* This command cannot be used when the assignment list is being displayed. Switch back to the volunteer list by using the `list` command before using `copy`.

* The email addresses will be copied in a comma-separated format, e.g. `[email protected], [email protected], ...`.

* If there are no people in the filtered list, an error message will be shown.

</div>

Format: `copy`

Examples:
* `list` followed by `copy` copies all email addresses in the address book.
* `find n/john` followed by `copy` copies the email addresses of people whose names contain "john".

### Assigning volunteers : `assign`
Adds an assignment to the address book.

Expand Down Expand Up @@ -253,6 +275,7 @@ Action | Format, Examples
--------|------------------
**Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/AVAILABILITY [t/TAG]…​` <br> e.g., `add n/James Ho p/22224444 e/[email protected] a/25/05/2024 t/friend t/colleague`
**Clear** | `clear`
**Copy** | `copy`
**Delete** | `delete INDEX`<br> e.g., `delete 3`
**Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/AVAILABILITY] [t/TAG]…​`<br> e.g.,`edit 2 n/James Lee e/[email protected]`
**Find** | `find KEYWORD [n/NAME] [a/AVAILABILITY] [MORE_KEYWORDS]`<br> e.g., `find James Jake`
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class Messages {
"Multiple values specified for the following single-valued field(s): ";
public static final String MESSAGE_CONFIRMATION = "Are you sure that you want to proceed with that action? "
+ "[y/N]";

public static final String MESSAGE_CONFIRMATION_CANCELLED = "Command execution has been cancelled.";
public static final String MESSAGE_EMPTY_LIST = "There is no person currently displayed";

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/logic/commands/CopyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public CommandResult execute(Model model) throws CommandException {
String emailString = extractEmails(lastShownList);

if (!GraphicsEnvironment.isHeadless()) {
copyToClipboard(emailString);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

copyToClipboard(emailString, clipboard);
}

return new CommandResult(String.format(MESSAGE_COPY_SUCCESS));
Expand Down Expand Up @@ -72,13 +74,12 @@ public String extractEmails(List<Person> filteredPersons) {
*
* @param desiredText The text to be copied to the clipboard.
*/
public void copyToClipboard(String desiredText) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
public void copyToClipboard(String desiredText, Clipboard targetClipboard) {

// Create a StringSelection object to hold the text
StringSelection selection = new StringSelection(desiredText);

// Set the contents of the clipboard to the StringSelection
clipboard.setContents(selection, null);
targetClipboard.setContents(selection, null);
}
}
13 changes: 0 additions & 13 deletions src/main/resources/view/PersonListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@
</VBox>
</HBox>

<!-- <VBox alignment="CENTER_LEFT" GridPane.columnIndex="0">-->
<!-- <HBox alignment="CENTER_LEFT">-->
<!-- <Label fx:id="id" styleClass="cell_big_label">-->
<!-- <minWidth>-->
<!-- &lt;!&ndash; Ensures that the label text is never truncated &ndash;&gt;-->
<!-- <Region fx:constant="USE_PREF_SIZE" />-->
<!-- </minWidth>-->
<!-- </Label>-->
<!-- <Label fx:id="details" text="\$first" styleClass="cell_small_label" >-->
<!-- </Label>-->
<!-- </HBox>-->
<!-- </VBox>-->

<VBox alignment="CENTER_LEFT" GridPane.columnIndex="1">
<padding>
<Insets top="5" right="5" bottom="5" left="5" />
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/view/PersonListPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>

<!--<VBox xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">-->
<!-- <ListView fx:id="personListView" VBox.vgrow="ALWAYS" />-->
<!--</VBox>-->

<VBox xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<GridPane HBox.hgrow="ALWAYS">
<columnConstraints>
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/seedu/address/logic/commands/CopyCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static seedu.address.logic.Messages.MESSAGE_EMPTY_LIST;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import static seedu.address.testutil.TypicalPersons.getTypicalPersons;
import static seedu.address.testutil.TypicalPersons.getTypicalPersonsEmails;

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.util.List;

import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -67,4 +73,14 @@ public void extractEmailsMethod() {
assertTrue(emails.equals(expectedEmails));
}

@Test
public void testCopyToClipboard() {
Clipboard mockClipboard = mock(Clipboard.class);
String text = "test text";

CopyCommand copyCommand = new CopyCommand();
copyCommand.copyToClipboard(text, mockClipboard);

verify(mockClipboard).setContents(any(StringSelection.class), isNull());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.logic.commands.AddAssignmentCommand;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.CopyCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.EditCommand.EditPersonDescriptor;
Expand Down Expand Up @@ -51,6 +52,11 @@ public void parseCommand_clear() throws Exception {
assertTrue(parser.parseCommand(ClearCommand.COMMAND_WORD + " 3") instanceof ClearCommand);
}

@Test
public void parseCommand_copy() throws Exception {
assertTrue(parser.parseCommand(CopyCommand.COMMAND_WORD) instanceof CopyCommand);
}

@Test
public void parseCommand_delete() throws Exception {
DeleteCommand command = (DeleteCommand) parser.parseCommand(
Expand Down

0 comments on commit 371d477

Please sign in to comment.