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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2006-2010 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.config.IdentityManager;
  24. import com.dmdirc.config.InvalidIdentityFileException;
  25. import com.dmdirc.addons.ui_swing.dialogs.FeedbackDialog;
  26. import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
  27. import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
  28. import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
  29. import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
  30. import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
  31. import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
  32. import java.lang.reflect.InvocationTargetException;
  33. import javax.swing.SwingUtilities;
  34. import org.fest.swing.finder.WindowFinder;
  35. import org.fest.swing.fixture.DialogFixture;
  36. import org.fest.swing.fixture.FrameFixture;
  37. import org.junit.After;
  38. import org.junit.Before;
  39. import org.junit.BeforeClass;
  40. import org.junit.Test;
  41. public class MainFrameTest {
  42. private static FrameFixture window;
  43. private DialogFixture newwin;
  44. private static SwingController controller;
  45. @BeforeClass
  46. public static void setUpClass() throws InvalidIdentityFileException {
  47. IdentityManager.load();
  48. IdentityManager.getAddonIdentity().setOption("test", "debugEDT", "false");
  49. IdentityManager.getAddonIdentity().setOption("test", "windowMenuItems", "1");
  50. IdentityManager.getAddonIdentity().setOption("test", "windowMenuScrollInterval", "1");
  51. controller = new SwingController();
  52. controller.setDomain("test");
  53. controller.onLoad();
  54. }
  55. @Before
  56. public void setUp() {
  57. if (window == null) {
  58. window = new FrameFixture(controller.getMainWindow());
  59. window.show();
  60. }
  61. }
  62. @Test
  63. public void testNewServerDialog() {
  64. window.menuItemWithPath("Server", "New Server...").click();
  65. newwin = WindowFinder.findDialog(NewServerDialog.class)
  66. .withTimeout(5000).using(window.robot);
  67. newwin.requireVisible();
  68. }
  69. @Test
  70. public void testAboutDialog() {
  71. window.menuItemWithPath("Help", "About").click();
  72. newwin = WindowFinder.findDialog(AboutDialog.class)
  73. .withTimeout(5000).using(window.robot);
  74. newwin.requireVisible();
  75. }
  76. @Test
  77. public void testFeedbackDialog() {
  78. window.menuItemWithPath("Help", "Send Feedback").click();
  79. newwin = WindowFinder.findDialog(FeedbackDialog.class)
  80. .withTimeout(5000).using(window.robot);
  81. newwin.requireVisible();
  82. }
  83. @Test
  84. public void testPreferencesDialog() {
  85. window.menuItemWithPath("Settings", "Preferences").click();
  86. newwin = WindowFinder.findDialog(SwingPreferencesDialog.class)
  87. .withTimeout(5000).using(window.robot);
  88. newwin.requireVisible();
  89. }
  90. @Test
  91. public void testProfileManagerDialog() {
  92. window.menuItemWithPath("Settings", "Profile Manager").click();
  93. newwin = WindowFinder.findDialog(ProfileManagerDialog.class)
  94. .withTimeout(5000).using(window.robot);
  95. newwin.requireVisible();
  96. }
  97. @Test
  98. public void testActionsManagerDialog() {
  99. window.menuItemWithPath("Settings", "Actions Manager").click();
  100. newwin = WindowFinder.findDialog(ActionsManagerDialog.class)
  101. .withTimeout(5000).using(window.robot);
  102. newwin.requireVisible();
  103. }
  104. @Test
  105. public void testAliasManagerDialog() {
  106. window.menuItemWithPath("Settings", "Alias Manager").click();
  107. newwin = WindowFinder.findDialog(AliasManagerDialog.class)
  108. .withTimeout(5000).using(window.robot);
  109. newwin.requireVisible();
  110. }
  111. @Test
  112. public void testChannelServerSettings() {
  113. window.menuItemWithPath("Channel", "Channel Settings").requireDisabled();
  114. }
  115. @Test
  116. public void testServerServerSettings() {
  117. window.menuItemWithPath("Server", "Server settings").requireDisabled();
  118. }
  119. @After
  120. public void tearDown() throws InterruptedException, InvocationTargetException {
  121. SwingUtilities.invokeAndWait(new Runnable() {
  122. @Override
  123. public void run() {
  124. close();
  125. }
  126. });
  127. }
  128. protected void close() {
  129. if (newwin != null && newwin.target != null) {
  130. try {
  131. newwin.target.dispose();
  132. } catch (Throwable ex) {
  133. ex.printStackTrace();
  134. }
  135. }
  136. }
  137. }