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 { ...@@ -31,7 +31,7 @@ public class TodoItem {
* *
* @param other the other TodoItem, from which properties are copied * @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.checked = other.checked;
this.text = other.text; this.text = other.text;
} }
...@@ -49,7 +49,7 @@ public class TodoItem { ...@@ -49,7 +49,7 @@ public class TodoItem {
} }
public TodoItem as(TodoItem other) { public TodoItem as(TodoItem other) {
set(other); setAs(other);
return this; return this;
} }
......
...@@ -31,10 +31,10 @@ public class TodoListItem extends TodoItem { ...@@ -31,10 +31,10 @@ public class TodoListItem extends TodoItem {
} }
@Override @Override
public void set(TodoItem other) { public void setAs(TodoItem other) {
boolean oldChecked = isChecked(); boolean oldChecked = isChecked();
String oldText = getText(); String oldText = getText();
super.set(other); super.setAs(other);
if (oldChecked != other.isChecked() || oldText != other.getText() if (oldChecked != other.isChecked() || oldText != other.getText()
|| oldText != null && !(oldText.equals(other.getText()))) { || oldText != null && !(oldText.equals(other.getText()))) {
todoList.fireTodoListChanged(this); todoList.fireTodoListChanged(this);
......
...@@ -180,9 +180,9 @@ public class TodoListTest { ...@@ -180,9 +180,9 @@ public class TodoListTest {
assertEquals(3, receivedNotificationCount); assertEquals(3, receivedNotificationCount);
item.setChecked(true); item.setChecked(true);
assertEquals(4, receivedNotificationCount); 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); 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); assertEquals(5, receivedNotificationCount);
// test removeTodoListListener, too // test removeTodoListListener, too
newList.removeTodoListListener(listener); newList.removeTodoListListener(listener);
......
...@@ -33,7 +33,7 @@ public class TodoItemListCell extends ListCell<TodoItem> { ...@@ -33,7 +33,7 @@ public class TodoItemListCell extends ListCell<TodoItem> {
todoItemControl = new HBox(); todoItemControl = new HBox();
checkedView = new CheckBox(); checkedView = new CheckBox();
checkedView.selectedProperty().addListener((prop, oldValue, newValue) -> { checkedView.selectedProperty().addListener((prop, oldValue, newValue) -> {
getItem().set(new TodoItem() getItem().setAs(new TodoItem()
.checked(checkedView.isSelected()) .checked(checkedView.isSelected())
// use editor text if it's active, otherwise existing text // use editor text if it's active, otherwise existing text
.text(isEditing() ? textEditor.getText() : getItem().getText()) .text(isEditing() ? textEditor.getText() : getItem().getText())
......
...@@ -7,8 +7,6 @@ import javafx.scene.Parent; ...@@ -7,8 +7,6 @@ import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.stage.Stage; 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.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
...@@ -16,6 +14,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; ...@@ -16,6 +14,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.testfx.framework.junit5.ApplicationTest; import org.testfx.framework.junit5.ApplicationTest;
import todolist.core.TodoItem;
import todolist.core.TodoList;
public class TodoAppTest extends ApplicationTest { public class TodoAppTest extends ApplicationTest {
...@@ -67,6 +67,20 @@ public class TodoAppTest extends ApplicationTest { ...@@ -67,6 +67,20 @@ public class TodoAppTest extends ApplicationTest {
checkTodoListViewItems(item2, newItem, item1); 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 @Test
public void testCheckTodoItem() { public void testCheckTodoItem() {
TodoItemListCell todoItemListCell = findTodoItemListCell(cell -> ! cell.getItem().isChecked()); 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