You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainFrameTest.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing;
  23. import com.dmdirc.Main;
  24. import com.dmdirc.config.IdentityManager;
  25. import com.dmdirc.harness.ui.UIClassTestRunner;
  26. import com.dmdirc.harness.ui.UITestIface;
  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. import org.junit.Test;
  43. import org.junit.runner.RunWith;
  44. import static org.junit.Assert.*;
  45. @RunWith(UIClassTestRunner.class)
  46. public class MainFrameTest implements UITestIface {
  47. private static FrameFixture window;
  48. private DialogFixture newwin;
  49. @BeforeClass
  50. public static void setUpClass() {
  51. IdentityManager.load();
  52. Main.setUI(new SwingController());
  53. }
  54. @Before
  55. public void setUp() {
  56. if (window == null) {
  57. window = new FrameFixture(SwingController.getMainFrame());
  58. window.show();
  59. }
  60. }
  61. @Test
  62. public void testNewServerDialog() {
  63. window.menuItemWithPath("Server", "New Server...").click();
  64. newwin = WindowFinder.findDialog(NewServerDialog.class)
  65. .withTimeout(5000).using(window.robot);
  66. newwin.requireVisible();
  67. }
  68. @Test
  69. public void testAboutDialog() {
  70. window.menuItemWithPath("Help", "About").click();
  71. newwin = WindowFinder.findDialog(AboutDialog.class)
  72. .withTimeout(5000).using(window.robot);
  73. newwin.requireVisible();
  74. }
  75. @Test
  76. public void testFeedbackDialog() {
  77. window.menuItemWithPath("Help", "Send Feedback").click();
  78. newwin = WindowFinder.findDialog(FeedbackDialog.class)
  79. .withTimeout(5000).using(window.robot);
  80. newwin.requireVisible();
  81. }
  82. @Test
  83. public void testPreferencesDialog() {
  84. window.menuItemWithPath("Settings", "Preferences").click();
  85. newwin = WindowFinder.findDialog(SwingPreferencesDialog.class)
  86. .withTimeout(5000).using(window.robot);
  87. newwin.requireVisible();
  88. }
  89. @Test
  90. public void testProfileManagerDialog() {
  91. window.menuItemWithPath("Settings", "Profile Manager").click();
  92. newwin = WindowFinder.findDialog(ProfileManagerDialog.class)
  93. .withTimeout(5000).using(window.robot);
  94. newwin.requireVisible();
  95. }
  96. @Test
  97. public void testActionsManagerDialog() {
  98. window.menuItemWithPath("Settings", "Actions Manager").click();
  99. newwin = WindowFinder.findDialog(ActionsManagerDialog.class)
  100. .withTimeout(5000).using(window.robot);
  101. newwin.requireVisible();
  102. }
  103. @Test
  104. public void testAliasManagerDialog() {
  105. window.menuItemWithPath("Settings", "Alias Manager").click();
  106. newwin = WindowFinder.findDialog(AliasManagerDialog.class)
  107. .withTimeout(5000).using(window.robot);
  108. newwin.requireVisible();
  109. }
  110. @Test
  111. public void testChannelServerSettings() {
  112. window.menuItemWithPath("Channel", "Channel Settings").requireDisabled();
  113. }
  114. @Test
  115. public void testServerServerSettings() {
  116. window.menuItemWithPath("Server", "Server settings").requireDisabled();
  117. }
  118. @Override @After
  119. public void tearDown() throws InterruptedException, InvocationTargetException {
  120. SwingUtilities.invokeAndWait(new Runnable() {
  121. @Override
  122. public void run() {
  123. close();
  124. }
  125. });
  126. }
  127. protected void close() {
  128. if (newwin != null && newwin.target != null) {
  129. try {
  130. newwin.target.dispose();
  131. } catch (Throwable ex) {
  132. ex.printStackTrace();
  133. }
  134. }
  135. }
  136. }