Skip to content
Snippets Groups Projects
Commit 42dec364 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

La til UI test for slett todo-element ifm. video

parent 3eb32253
No related branches found
No related tags found
No related merge requests found
......@@ -31,7 +31,7 @@ public class TodoItem {
*
* @param other the other TodoItem, from which properties are copied
*/
public void set(TodoItem other) {
public void setAs(TodoItem other) {
this.checked = other.checked;
this.text = other.text;
}
......@@ -49,7 +49,7 @@ public class TodoItem {
}
public TodoItem as(TodoItem other) {
set(other);
setAs(other);
return this;
}
......
......@@ -31,10 +31,10 @@ public class TodoListItem extends TodoItem {
}
@Override
public void set(TodoItem other) {
public void setAs(TodoItem other) {
boolean oldChecked = isChecked();
String oldText = getText();
super.set(other);
super.setAs(other);
if (oldChecked != other.isChecked() || oldText != other.getText()
|| oldText != null && !(oldText.equals(other.getText()))) {
todoList.fireTodoListChanged(this);
......
......@@ -180,9 +180,9 @@ public class TodoListTest {
assertEquals(3, receivedNotificationCount);
item.setChecked(true);
assertEquals(4, receivedNotificationCount);
item.set(new TodoItem().checked(true).text("enda en endret verdi"));
item.setAs(new TodoItem().checked(true).text("enda en endret verdi"));
assertEquals(5, receivedNotificationCount);
item.set(new TodoItem().checked(true).text("enda en endret verdi"));
item.setAs(new TodoItem().checked(true).text("enda en endret verdi"));
assertEquals(5, receivedNotificationCount);
// test removeTodoListListener, too
newList.removeTodoListListener(listener);
......
......@@ -33,7 +33,7 @@ public class TodoItemListCell extends ListCell<TodoItem> {
todoItemControl = new HBox();
checkedView = new CheckBox();
checkedView.selectedProperty().addListener((prop, oldValue, newValue) -> {
getItem().set(new TodoItem()
getItem().setAs(new TodoItem()
.checked(checkedView.isSelected())
// use editor text if it's active, otherwise existing text
.text(isEditing() ? textEditor.getText() : getItem().getText())
......
......@@ -7,8 +7,6 @@ import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.stage.Stage;
import todolist.core.TodoItem;
import todolist.core.TodoList;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
......@@ -16,6 +14,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testfx.framework.junit5.ApplicationTest;
import todolist.core.TodoItem;
import todolist.core.TodoList;
public class TodoAppTest extends ApplicationTest {
......@@ -67,6 +67,20 @@ public class TodoAppTest extends ApplicationTest {
checkTodoListViewItems(item2, newItem, item1);
}
@Test
public void testDeleteTodoItem() {
// final ListView<TodoItem> todoListView = lookup("#todoListView").query();
// todoListView.getSelectionModel().select(1);
TodoItemListCell todoItemListCell = findTodoItemListCell(1);
clickOn(todoItemListCell.lookup(".label"));
clickOn("#deleteTodoItemButton");
// item2 is removed, only item1 is left
checkTodoListItems(item1);
// item2 is removed, only item1 is left
checkTodoListViewItems(item1);
}
@Test
public void testCheckTodoItem() {
TodoItemListCell todoItemListCell = findTodoItemListCell(cell -> ! cell.getItem().isChecked());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment