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

Fikset feilen, måtte endre litt på test-caset

parent 5e7e9e2c
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,7 @@ public class TodoListControllerTest extends ApplicationTest { ...@@ -40,7 +40,7 @@ public class TodoListControllerTest extends ApplicationTest {
private TodoPersistence todoPersistence = new TodoPersistence(); private TodoPersistence todoPersistence = new TodoPersistence();
private TodoList todoList; private TodoList todoList;
private TodoItem item1, item2; private TodoItem item1, item2, item3;
@BeforeEach @BeforeEach
public void setupItems() { public void setupItems() {
...@@ -59,6 +59,7 @@ public class TodoListControllerTest extends ApplicationTest { ...@@ -59,6 +59,7 @@ public class TodoListControllerTest extends ApplicationTest {
Iterator<TodoItem> todoItems = todoList.iterator(); Iterator<TodoItem> todoItems = todoList.iterator();
item1 = new TodoItem().as(todoItems.next()); item1 = new TodoItem().as(todoItems.next());
item2 = new TodoItem().as(todoItems.next()); item2 = new TodoItem().as(todoItems.next());
item3 = new TodoItem().as(todoItems.next());
} }
@Test @Test
...@@ -66,14 +67,13 @@ public class TodoListControllerTest extends ApplicationTest { ...@@ -66,14 +67,13 @@ public class TodoListControllerTest extends ApplicationTest {
assertNotNull(this.controller); assertNotNull(this.controller);
assertNotNull(this.todoList); assertNotNull(this.todoList);
// initial todo items // initial todo items
checkTodoItems(this.todoList, item1, item2); checkTodoListItems(item1, item2, item3);
} }
@Test @Test
public void testTodoListView_initialItems() { public void testTodoListView_initialItems() {
final ListView<TodoItem> todoListView = lookup("#todoItemsView").query();
// initial todo items, note the unchecked one comes first // initial todo items, note the unchecked one comes first
checkTodoItems(todoListView.getItems(), item2, item1); checkTodoListViewItems(item2, item3, item1);
} }
@Test @Test
...@@ -83,25 +83,24 @@ public class TodoListControllerTest extends ApplicationTest { ...@@ -83,25 +83,24 @@ public class TodoListControllerTest extends ApplicationTest {
clickOn("#newTodoItemButton"); clickOn("#newTodoItemButton");
TodoItem newItem = new TodoItem().text(newItemText); TodoItem newItem = new TodoItem().text(newItemText);
// item is added last in underlying todo list // item is added last in underlying todo list
checkTodoListItems(item1, item2, newItem); checkTodoListItems(item1, item2, item3, newItem);
// item is last of the unchecked items in list view // item is last of the unchecked items in list view
checkTodoListViewItems(item2, newItem, item1); checkTodoListViewItems(item2, item3, newItem, item1);
// check element is selected // check element is selected
checkSelectedTodoItem(1); checkSelectedTodoItem(2);
} }
@Test @Test
public void testDeleteTodoItem() { public void testDeleteTodoItem() {
// final ListView<TodoItem> todoListView = lookup("#todoItemsView").query(); // select the second item in the list view, which is the third item in the model
// todoListView.getSelectionModel().select(1);
clickOn(findTodoItemListCellNode(cell -> true, ".label", 1)); clickOn(findTodoItemListCellNode(cell -> true, ".label", 1));
clickOn("#deleteTodoItemButton"); clickOn("#deleteTodoItemButton");
// item3 is removed, item1 and item2 is left
checkTodoListItems(item1, item2);
// item2 is removed, only item1 is left // item2 is removed, only item1 is left
checkTodoListItems(item1); checkTodoListViewItems(item2, item1);
// item2 is removed, only item1 is left // check same index in list view is selected
checkTodoListViewItems(item1); checkSelectedTodoItem(1);
// check remaining item is selected
checkSelectedTodoItem(0);
} }
@Test @Test
...@@ -109,21 +108,24 @@ public class TodoListControllerTest extends ApplicationTest { ...@@ -109,21 +108,24 @@ public class TodoListControllerTest extends ApplicationTest {
clickOn(findTodoItemListCellNode(cell -> !cell.getItem().isChecked(), ".check-box", 0)); clickOn(findTodoItemListCellNode(cell -> !cell.getItem().isChecked(), ".check-box", 0));
TodoItem newItem2 = item2.withChecked(true); TodoItem newItem2 = item2.withChecked(true);
// item is changed // item is changed
checkTodoListItems(item1, newItem2); checkTodoListItems(item1, newItem2, item3);
// items in list view change order // items in list view change order
checkTodoListViewItems(item1, newItem2); checkTodoListViewItems(item3, item1, newItem2);
} }
@Test @Test
public void testDragTodoItem() { public void testDragTodoItem() {
Predicate<TodoItemListCell> draggableCell = cell -> cell.lookup(".label") != null; Predicate<TodoItemListCell> draggableCell = cell -> cell.lookup(".label") != null;
// drag the first item in the list view, which is the second item in the model
TodoItemListCell sourceTodoItemListCell = findTodoItemListCell(draggableCell, 0); TodoItemListCell sourceTodoItemListCell = findTodoItemListCell(draggableCell, 0);
// drop on the second item in the list view, which is the third item in the model
TodoItemListCell targetTodoItemListCell = findTodoItemListCell(draggableCell, 1); TodoItemListCell targetTodoItemListCell = findTodoItemListCell(draggableCell, 1);
drag(sourceTodoItemListCell).dropTo(targetTodoItemListCell); drag(sourceTodoItemListCell).dropTo(targetTodoItemListCell);
// item order is changed // item order is changed
checkTodoListItems(item2, item1); checkTodoListItems(item1, item3, item2);
// items in list view do not change order // items in list view do not change order
checkTodoListViewItems(item1, item2); checkTodoListViewItems(item3, item2, item1);
} }
// utility methods // utility methods
...@@ -141,7 +143,7 @@ public class TodoListControllerTest extends ApplicationTest { ...@@ -141,7 +143,7 @@ public class TodoListControllerTest extends ApplicationTest {
private Node waitForNode(Predicate<Node> nodeTest, int num) { private Node waitForNode(Predicate<Node> nodeTest, int num) {
Node[] nodes = new Node[1]; Node[] nodes = new Node[1];
try { try {
WaitForAsyncUtils.waitFor(500, TimeUnit.MILLISECONDS, WaitForAsyncUtils.waitFor(1000, TimeUnit.MILLISECONDS,
() -> { () -> {
while (true) { while (true) {
if ((nodes[0] = findNode(nodeTest, num)) != null) { if ((nodes[0] = findNode(nodeTest, num)) != null) {
...@@ -186,7 +188,7 @@ public class TodoListControllerTest extends ApplicationTest { ...@@ -186,7 +188,7 @@ public class TodoListControllerTest extends ApplicationTest {
private void checkTodoItems(Iterable<TodoItem> it, TodoItem... items) { private void checkTodoItems(Iterable<TodoItem> it, TodoItem... items) {
int i = 0; int i = 0;
for (TodoItem item : items) { for (TodoItem item : it) {
assertTrue(i < items.length); assertTrue(i < items.length);
checkTodoItem(item, items[i].isChecked(), items[i].getText()); checkTodoItem(item, items[i].isChecked(), items[i].getText());
i++; i++;
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
}, { }, {
"text" : "Item 2", "text" : "Item 2",
"checked" : false "checked" : false
}, {
"text" : "Item 3",
"checked" : false
} ] } ]
} ] } ]
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment