Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
todo-list-example
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IT1901
todo-list-example
Commits
c0ef8575
Commit
c0ef8575
authored
4 years ago
by
Hallvard Trætteberg
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up test code
parent
4d8863d8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
todolist/fxui/src/test/java/todolist/ui/TodoListControllerTest.java
+39
-25
39 additions, 25 deletions
...xui/src/test/java/todolist/ui/TodoListControllerTest.java
with
39 additions
and
25 deletions
todolist/fxui/src/test/java/todolist/ui/TodoListControllerTest.java
+
39
−
25
View file @
c0ef8575
...
@@ -2,8 +2,9 @@ package todolist.ui;
...
@@ -2,8 +2,9 @@ package todolist.ui;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
java.util.function.Predicate
;
import
java.util.function.Predicate
;
import
javafx.fxml.FXMLLoader
;
import
javafx.fxml.FXMLLoader
;
import
javafx.scene.Node
;
import
javafx.scene.Node
;
...
@@ -18,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
...
@@ -18,6 +19,7 @@ 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
org.testfx.util.WaitForAsyncUtils
;
import
todolist.core.TodoItem
;
import
todolist.core.TodoItem
;
import
todolist.core.TodoList
;
import
todolist.core.TodoList
;
import
todolist.core.TodoModel
;
import
todolist.core.TodoModel
;
...
@@ -53,11 +55,6 @@ public class TodoListControllerTest extends ApplicationTest {
...
@@ -53,11 +55,6 @@ public class TodoListControllerTest extends ApplicationTest {
assertTrue
(
todoModel
.
iterator
().
hasNext
());
assertTrue
(
todoModel
.
iterator
().
hasNext
());
this
.
todoList
=
todoModel
.
iterator
().
next
();
this
.
todoList
=
todoModel
.
iterator
().
next
();
this
.
controller
.
setTodoList
(
this
.
todoList
);
this
.
controller
.
setTodoList
(
this
.
todoList
);
try
{
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
e
)
{
// ignore
}
// same as in test-todomodel.json
// same as in test-todomodel.json
Iterator
<
TodoItem
>
todoItems
=
todoList
.
iterator
();
Iterator
<
TodoItem
>
todoItems
=
todoList
.
iterator
();
item1
=
new
TodoItem
().
as
(
todoItems
.
next
());
item1
=
new
TodoItem
().
as
(
todoItems
.
next
());
...
@@ -97,9 +94,7 @@ public class TodoListControllerTest extends ApplicationTest {
...
@@ -97,9 +94,7 @@ public class TodoListControllerTest extends ApplicationTest {
public
void
testDeleteTodoItem
()
{
public
void
testDeleteTodoItem
()
{
// final ListView<TodoItem> todoListView = lookup("#todoItemsView").query();
// final ListView<TodoItem> todoListView = lookup("#todoItemsView").query();
// todoListView.getSelectionModel().select(1);
// todoListView.getSelectionModel().select(1);
TodoItemListCell
todoItemListCell
=
findTodoItemListCell
(
1
);
clickOn
(
findTodoItemListCellNode
(
cell
->
true
,
".label"
,
1
));
clickOn
(
todoItemListCell
.
lookup
(
".label"
));
clickOn
(
"#deleteTodoItemButton"
);
clickOn
(
"#deleteTodoItemButton"
);
// item2 is removed, only item1 is left
// item2 is removed, only item1 is left
checkTodoListItems
(
item1
);
checkTodoListItems
(
item1
);
...
@@ -111,8 +106,7 @@ public class TodoListControllerTest extends ApplicationTest {
...
@@ -111,8 +106,7 @@ public class TodoListControllerTest extends ApplicationTest {
@Test
@Test
public
void
testCheckTodoItemListCell
()
{
public
void
testCheckTodoItemListCell
()
{
TodoItemListCell
todoItemListCell
=
findTodoItemListCell
(
cell
->
!
cell
.
getItem
().
isChecked
());
clickOn
(
findTodoItemListCellNode
(
cell
->
!
cell
.
getItem
().
isChecked
(),
".check-box"
,
0
));
clickOn
(
todoItemListCell
.
lookup
(
".check-box"
));
TodoItem
newItem2
=
item2
.
withChecked
(
true
);
TodoItem
newItem2
=
item2
.
withChecked
(
true
);
// item is changed
// item is changed
checkTodoListItems
(
item1
,
newItem2
);
checkTodoListItems
(
item1
,
newItem2
);
...
@@ -137,22 +131,42 @@ public class TodoListControllerTest extends ApplicationTest {
...
@@ -137,22 +131,42 @@ public class TodoListControllerTest extends ApplicationTest {
return
findTodoItemListCell
(
cell
->
true
,
num
);
return
findTodoItemListCell
(
cell
->
true
,
num
);
}
}
private
TodoItemListCell
findTodoItemListCell
(
Predicate
<
TodoItemListCell
>
test
)
{
private
Node
findNode
(
Predicate
<
Node
>
nodeTest
,
int
num
)
{
return
findTodoItemListCell
(
test
,
0
);
int
count
=
0
;
for
(
Node
node
:
lookup
(
nodeTest
).
queryAll
())
{
if
(
nodeTest
.
test
(
node
)
&&
count
++
==
num
)
{
return
node
;
}
}
return
null
;
}
}
private
TodoItemListCell
findTodoItemListCell
(
Predicate
<
TodoItemListCell
>
test
,
int
num
)
{
private
Node
waitForNode
(
Predicate
<
Node
>
nodeTest
,
int
num
)
{
Collection
<
Node
>
nodes
=
lookup
(
node
->
node
instanceof
TodoItemListCell
).
queryAll
();
// ".list-cell").queryAll();
Node
[]
nodes
=
new
Node
[
1
];
for
(
Node
node
:
nodes
)
{
try
{
if
(
node
instanceof
TodoItemListCell
)
{
WaitForAsyncUtils
.
waitFor
(
500
,
TimeUnit
.
MILLISECONDS
,
TodoItemListCell
todoItemListCell
=
(
TodoItemListCell
)
node
;
()
->
{
if
(
test
.
test
(
todoItemListCell
)
&&
num
--
==
0
)
{
while
(
true
)
{
return
todoItemListCell
;
if
((
nodes
[
0
]
=
findNode
(
nodeTest
,
num
))
!=
null
)
{
return
true
;
}
}
Thread
.
sleep
(
10
);
}
}
}
}
fail
(
"Didn't find TodoItemListCell #"
+
num
+
" in "
+
nodes
);
);
return
null
;
}
catch
(
TimeoutException
e
)
{
fail
(
"No appropriate node available"
);
}
return
nodes
[
0
];
}
private
TodoItemListCell
findTodoItemListCell
(
Predicate
<
TodoItemListCell
>
test
,
int
num
)
{
return
(
TodoItemListCell
)
waitForNode
(
node
->
node
instanceof
TodoItemListCell
&&
test
.
test
((
TodoItemListCell
)
node
),
num
);
}
private
Node
findTodoItemListCellNode
(
Predicate
<
TodoItemListCell
>
test
,
String
selector
,
int
num
)
{
Node
listCell
=
waitForNode
(
node
->
node
instanceof
TodoItemListCell
&&
(
selector
==
null
||
node
.
lookup
(
selector
)
!=
null
)
&&
test
.
test
((
TodoItemListCell
)
node
),
num
);
return
listCell
.
lookup
(
selector
);
}
}
private
void
checkTodoItem
(
TodoItem
item
,
Boolean
checked
,
String
text
)
{
private
void
checkTodoItem
(
TodoItem
item
,
Boolean
checked
,
String
text
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment