-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrontendDeveloperTests.java
More file actions
168 lines (134 loc) · 5.12 KB
/
Copy pathFrontendDeveloperTests.java
File metadata and controls
168 lines (134 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// --== CS400 File Header Information ==--
// Name: Haozhe Wu
// CSL Username: haozhew
// Email: hwu435@wisc.edu
// Lecture #: 002 @1:00pm
// Notes to Grader: <any optional extra notes to your grader>
import javafx.scene.control.TextField;
import static org.junit.jupiter.api.Assertions.assertEquals;
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import edu.wisc.cs.cs400.JavaFXTester;
import org.junit.jupiter.api.Test;
/**
* Test class for FlightPlannerFrontend.java
*/
public class FrontendDeveloperTests extends JavaFXTester {
// this JavaFXTester class implements the TestFX FXRobot class, documented here:
// https://testfx.github.io/TestFX/docs/javadoc/testfx-core/javadoc/org.testfx/org/testfx/api/FxRobot.html
/**
* specify the Application being tested
*/
public FrontendDeveloperTests() {
super(FlightPlannerFrontend.class);
}
/**
* Test the basic scene
*/
@Test
public void test1() {
Label start = lookup("#start").query();
assertEquals("Departure", start.getText());
Label end = lookup("#end").query();
assertEquals("Destination", end.getText());
Label out = lookup("#out").query();
assertEquals("Welcome to Flight Planner", out.getText());
}
/**
* Test all the variables before any change or inputs
*/
@Test
public void test2() {
FlightPlannerFrontend FP = new FlightPlannerFrontend();
assertEquals(0, FP.numIntermediates);
TextField from = lookup("#from").query();
assertEquals("", from.getText());
TextField to = lookup("#to").query();
assertEquals("", to.getText());
// click search, because there is nothing in the from, the out should be "Please enter your
// Departure"
Button search = lookup("#search").query();
interact(() -> search.fireEvent(new ActionEvent()));
Label out = lookup("#out").query();
assertEquals("Please enter your Departure", out.getText());
}
/**
* Search the shortest path from an airport to another airport Because I used the BD placeholder
* here, so the only path in the whole class is msn -> ord
* <p>
* After all the tests, test the clear()
*/
@Test
public void test3() {
TextField from = lookup("#from").query();
from.setText("LAX");
TextField to = lookup("#to").query();
to.setText("DCA");
Button search = lookup("#search").query();
interact(() -> search.fireEvent(new ActionEvent()));
Label out = lookup("#out").query();
assertEquals(
"The shortest path from " + "LAX" + " to " + "DCA" + " is: " + "\n" + "1: LAX -> DCA",
out.getText());
// test the clear(), all the thing would back to default
Button clear = lookup("#clear").query();
interact(() -> clear.fireEvent(new ActionEvent()));
assertEquals("", from.getText());
assertEquals("", to.getText());
assertEquals("Welcome to Flight Planner", out.getText());
}
/**
* add an intermediate, and do a search
*/
@Test
public void test4() {
TextField from = lookup("#from").query();
from.setText("LAX");
Button add = lookup("#add").query();
interact(() -> add.fireEvent(new ActionEvent()));
TextField intermediate0 = lookup("#intermediate0").query();
intermediate0.setText("DCA");
TextField to = lookup("#to").query();
to.setText("ORD");
Button search = lookup("#search").query();
interact(() -> search.fireEvent(new ActionEvent()));
Label out = lookup("#out").query();
assertEquals("The shortest path from " + "LAX" + " to " + "ORD" + " is: " + "\n"
+ "1: LAX -> DCA" + "\n2: DCA -> ORD", out.getText());
}
/**
* fill the to leave the to blank and do the search, the out should display all the neighbors of
* to
* <p>
* then add an intermediate fill the from and intermediate but leave the to blank,
* <p>
* the out should display the intermediate's the neighbors
* <p>
* ** because I used the placeholder, so the neighbors should always be "aaaa, bbbb, cccc, dddd,
* aqwcf, qwf, qfqf" (Not anymore)
*/
@Test
public void test5() {
TextField from = lookup("#from").query();
from.setText("MSN");
Button search = lookup("#search").query();
interact(() -> search.fireEvent(new ActionEvent()));
Label out = lookup("#out").query();
assertEquals(
"There is no destination, but here are the neighbor airport of the last airport you typed: \n"
+ "ATL, CVG, DEN, DFW, DTW, EWR, MCO, MSP, ORD, SLC, ",
out.getText());
Button add = lookup("#add").query();
interact(() -> add.fireEvent(new ActionEvent()));
TextField intermediate0 = lookup("#intermediate0").query();
intermediate0.setText("DCA");
interact(() -> search.fireEvent(new ActionEvent()));
assertEquals(
"There is no destination, but here are the neighbor airport of the last airport you typed: \n"
+ "ATL, AUS, BDL, BNA, BOS, CAK, CHS, CLE, CLT, DAL, DEN, DFW, DTW, EWR, FLL, HOU, IAH, IND, JAX,"
+ " JFK, LAS, LAX, LGA, MCI, MCO, MDW, MIA, MKE, MSP, MSY, ORD, PBI, PDX, PHL, PHX, PIT, RSW, SEA, "
+ "SFO, SJU, SLC, STL, TPA, ",
out.getText());
}
}