|
@@ -24,134 +24,93 @@ package com.dmdirc.addons.ui_swing;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.config.IdentityManager;
|
26
|
26
|
import com.dmdirc.config.InvalidIdentityFileException;
|
27
|
|
-import com.dmdirc.addons.ui_swing.dialogs.FeedbackDialog;
|
28
|
|
-import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
|
29
|
|
-import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
|
30
|
|
-import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
|
31
|
|
-import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
|
32
|
|
-import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
|
33
|
|
-import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
|
34
|
|
-import java.lang.reflect.InvocationTargetException;
|
35
|
|
-import javax.swing.SwingUtilities;
|
36
|
|
-import org.fest.swing.finder.WindowFinder;
|
37
|
|
-import org.fest.swing.fixture.DialogFixture;
|
38
|
|
-import org.fest.swing.fixture.FrameFixture;
|
39
|
|
-import org.junit.After;
|
40
|
|
-import org.junit.Before;
|
41
|
|
-import org.junit.BeforeClass;
|
42
|
27
|
import org.junit.Test;
|
|
28
|
+import org.uispec4j.UISpecTestCase;
|
|
29
|
+import org.uispec4j.Window;
|
|
30
|
+import org.uispec4j.interception.WindowInterceptor;
|
|
31
|
+import static org.mockito.Mockito.*;
|
43
|
32
|
|
44
|
|
-public class MainFrameTest {
|
|
33
|
+public class MainFrameTest extends UISpecTestCase {
|
45
|
34
|
|
46
|
|
- private static FrameFixture window;
|
47
|
|
- private DialogFixture newwin;
|
48
|
|
- private static SwingController controller;
|
|
35
|
+ private static Window window;
|
|
36
|
+
|
|
37
|
+ static {
|
|
38
|
+ try {
|
|
39
|
+ IdentityManager.load();
|
|
40
|
+ } catch (InvalidIdentityFileException ex) {
|
|
41
|
+ //Ignore
|
|
42
|
+ }
|
|
43
|
+ SwingController controller = mock(SwingController.class);
|
|
44
|
+ final SwingWindowFactory windowFactory = mock(SwingWindowFactory.class);
|
|
45
|
+ when(controller.getDomain()).thenReturn("test");
|
|
46
|
+ when(controller.getWindowFactory()).thenReturn(windowFactory);
|
49
|
47
|
|
50
|
|
- @BeforeClass
|
51
|
|
- public static void setUpClass() throws InvalidIdentityFileException {
|
52
|
|
- IdentityManager.load();
|
53
|
|
- IdentityManager.getAddonIdentity().setOption("test", "debugEDT", "false");
|
54
|
|
- IdentityManager.getAddonIdentity().setOption("test", "windowMenuItems", "1");
|
55
|
48
|
IdentityManager.getAddonIdentity().setOption("test", "windowMenuScrollInterval", "1");
|
56
|
49
|
IdentityManager.getAddonIdentity().setOption("test", "desktopbackground", "");
|
57
|
50
|
IdentityManager.getAddonIdentity().setOption("test", "desktopbackgroundoption", "STRETCH");
|
58
|
|
- controller = new SwingController();
|
59
|
|
- controller.setDomain("test");
|
60
|
|
- controller.onLoad();
|
61
|
|
- }
|
|
51
|
+ IdentityManager.getAddonIdentity().setOption("test", "windowMenuItems", "1");
|
|
52
|
+ IdentityManager.getAddonIdentity().setOption("test", "windowMenuScrollInterval", "1");
|
62
|
53
|
|
63
|
|
- @Before
|
64
|
|
- public void setUp() {
|
65
|
|
- if (window == null) {
|
66
|
|
- window = new FrameFixture(controller.getMainWindow());
|
67
|
|
- window.show();
|
68
|
|
- }
|
|
54
|
+ window = new Window(new MainFrame(controller));
|
|
55
|
+ window.containsMenuBar().check();
|
69
|
56
|
}
|
70
|
57
|
|
71
|
58
|
@Test
|
72
|
59
|
public void testNewServerDialog() {
|
73
|
|
- window.menuItemWithPath("Server", "New Server...").click();
|
74
|
|
- newwin = WindowFinder.findDialog(NewServerDialog.class)
|
75
|
|
- .withTimeout(5000).using(window.robot);
|
76
|
|
- newwin.requireVisible();
|
|
60
|
+ Window popup = WindowInterceptor.run(window.getMenuBar()
|
|
61
|
+ .getMenu("Server").getSubMenu("New Server...").triggerClick());
|
|
62
|
+ popup.titleEquals("DMDirc: Connect to a new server").check();
|
77
|
63
|
}
|
78
|
|
-
|
|
64
|
+
|
79
|
65
|
@Test
|
80
|
66
|
public void testAboutDialog() {
|
81
|
|
- window.menuItemWithPath("Help", "About").click();
|
82
|
|
- newwin = WindowFinder.findDialog(AboutDialog.class)
|
83
|
|
- .withTimeout(5000).using(window.robot);
|
84
|
|
- newwin.requireVisible();
|
|
67
|
+ Window popup = WindowInterceptor.run(window.getMenuBar()
|
|
68
|
+ .getMenu("Help").getSubMenu("About").triggerClick());
|
|
69
|
+ popup.titleEquals("DMDirc: About").check();
|
85
|
70
|
}
|
86
|
|
-
|
|
71
|
+
|
87
|
72
|
@Test
|
88
|
73
|
public void testFeedbackDialog() {
|
89
|
|
- window.menuItemWithPath("Help", "Send Feedback").click();
|
90
|
|
- newwin = WindowFinder.findDialog(FeedbackDialog.class)
|
91
|
|
- .withTimeout(5000).using(window.robot);
|
92
|
|
- newwin.requireVisible();
|
|
74
|
+ Window popup = WindowInterceptor.run(window.getMenuBar()
|
|
75
|
+ .getMenu("Help").getSubMenu("Send Feedback").triggerClick());
|
|
76
|
+ popup.titleEquals("DMDirc: Feedback").check();
|
93
|
77
|
}
|
94
|
|
-
|
|
78
|
+
|
95
|
79
|
@Test
|
96
|
80
|
public void testPreferencesDialog() {
|
97
|
|
- window.menuItemWithPath("Settings", "Preferences").click();
|
98
|
|
- newwin = WindowFinder.findDialog(SwingPreferencesDialog.class)
|
99
|
|
- .withTimeout(5000).using(window.robot);
|
100
|
|
- newwin.requireVisible();
|
|
81
|
+ Window popup = WindowInterceptor.run(window.getMenuBar()
|
|
82
|
+ .getMenu("Settings").getSubMenu("Preferences").triggerClick());
|
|
83
|
+ popup.titleEquals("DMDirc: Preferences").check();
|
101
|
84
|
}
|
102
|
|
-
|
|
85
|
+
|
103
|
86
|
@Test
|
104
|
87
|
public void testProfileManagerDialog() {
|
105
|
|
- window.menuItemWithPath("Settings", "Profile Manager").click();
|
106
|
|
- newwin = WindowFinder.findDialog(ProfileManagerDialog.class)
|
107
|
|
- .withTimeout(5000).using(window.robot);
|
108
|
|
- newwin.requireVisible();
|
|
88
|
+ Window popup = WindowInterceptor.run(window.getMenuBar()
|
|
89
|
+ .getMenu("Settings").getSubMenu("Profile Manager").triggerClick());
|
|
90
|
+ popup.titleEquals("DMDirc: Profile Editor").check();
|
109
|
91
|
}
|
110
|
|
-
|
|
92
|
+
|
111
|
93
|
@Test
|
112
|
94
|
public void testActionsManagerDialog() {
|
113
|
|
- window.menuItemWithPath("Settings", "Actions Manager").click();
|
114
|
|
- newwin = WindowFinder.findDialog(ActionsManagerDialog.class)
|
115
|
|
- .withTimeout(5000).using(window.robot);
|
116
|
|
- newwin.requireVisible();
|
|
95
|
+ Window popup = WindowInterceptor.run(window.getMenuBar()
|
|
96
|
+ .getMenu("Settings").getSubMenu("Actions Manager").triggerClick());
|
|
97
|
+ popup.titleEquals("DMDirc: Actions Manager").check();
|
117
|
98
|
}
|
118
|
|
-
|
|
99
|
+
|
119
|
100
|
@Test
|
120
|
101
|
public void testAliasManagerDialog() {
|
121
|
|
- window.menuItemWithPath("Settings", "Alias Manager").click();
|
122
|
|
- newwin = WindowFinder.findDialog(AliasManagerDialog.class)
|
123
|
|
- .withTimeout(5000).using(window.robot);
|
124
|
|
- newwin.requireVisible();
|
|
102
|
+ Window popup = WindowInterceptor.run(window.getMenuBar()
|
|
103
|
+ .getMenu("Settings").getSubMenu("Alias Manager").triggerClick());
|
|
104
|
+ popup.titleEquals("DMDirc: Alias manager").check();
|
125
|
105
|
}
|
126
|
|
-
|
|
106
|
+
|
127
|
107
|
@Test
|
128
|
108
|
public void testChannelServerSettings() {
|
129
|
|
- window.menuItemWithPath("Channel", "Channel Settings").requireDisabled();
|
|
109
|
+ assertFalse(window.getMenuBar().getMenu("Channel").getSubMenu("Channel Settings").isEnabled());
|
130
|
110
|
}
|
131
|
|
-
|
|
111
|
+
|
132
|
112
|
@Test
|
133
|
113
|
public void testServerServerSettings() {
|
134
|
|
- window.menuItemWithPath("Server", "Server settings").requireDisabled();
|
135
|
|
- }
|
136
|
|
-
|
137
|
|
- @After
|
138
|
|
- public void tearDown() throws InterruptedException, InvocationTargetException {
|
139
|
|
- SwingUtilities.invokeAndWait(new Runnable() {
|
140
|
|
- @Override
|
141
|
|
- public void run() {
|
142
|
|
- close();
|
143
|
|
- }
|
144
|
|
- });
|
|
114
|
+ assertFalse(window.getMenuBar().getMenu("Server").getSubMenu("Server Settings").isEnabled());
|
145
|
115
|
}
|
146
|
|
-
|
147
|
|
- protected void close() {
|
148
|
|
- if (newwin != null && newwin.target != null) {
|
149
|
|
- try {
|
150
|
|
- newwin.target.dispose();
|
151
|
|
- } catch (Throwable ex) {
|
152
|
|
- ex.printStackTrace();
|
153
|
|
- }
|
154
|
|
- }
|
155
|
|
- }
|
156
|
|
-
|
157
|
116
|
}
|