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.

ActionEditorDialogTest.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2006-2007 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.ui.swing.dialogs.actioneditor;
  23. import com.dmdirc.actions.Action;
  24. import com.dmdirc.actions.ActionManager;
  25. import com.dmdirc.config.IdentityManager;
  26. import com.dmdirc.harness.ui.ClassFinder;
  27. import com.dmdirc.ui.swing.components.ImageButton;
  28. import java.awt.Component;
  29. import javax.swing.JButton;
  30. import javax.swing.JPanel;
  31. import org.fest.swing.core.EventMode;
  32. import org.fest.swing.core.matcher.JButtonByTextMatcher;
  33. import org.fest.swing.core.matcher.JLabelByTextMatcher;
  34. import org.fest.swing.fixture.DialogFixture;
  35. import org.fest.swing.fixture.JLabelFixture;
  36. import org.fest.swing.fixture.JPanelFixture;
  37. import org.junit.After;
  38. import org.junit.Before;
  39. import org.junit.Test;
  40. import static org.junit.Assert.*;
  41. public class ActionEditorDialogTest {
  42. private DialogFixture window;
  43. @Before
  44. public void setUp() {
  45. IdentityManager.load();
  46. ActionManager.init();
  47. if (!ActionManager.getGroups().containsKey("amd-ui-test1")) {
  48. ActionManager.makeGroup("amd-ui-test1");
  49. }
  50. }
  51. @After
  52. public void tearDown() {
  53. if (window != null) {
  54. window.cleanUp();
  55. }
  56. if (ActionManager.getGroups().containsKey("amd-ui-test1")) {
  57. ActionManager.removeGroup("amd-ui-test1");
  58. }
  59. }
  60. @Test
  61. public void testName() {
  62. setupWindow(null);
  63. window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).textBox()
  64. .requireEnabled().requireEditable().requireEmpty();
  65. window.button(JButtonByTextMatcher.withText("OK")).requireDisabled();
  66. }
  67. @Test
  68. public void testBasicTriggers() {
  69. setupWindow(null);
  70. window.panel(new ClassFinder<JPanel>(ActionNamePanel.class, null)).textBox()
  71. .enterText("test1");
  72. final JPanelFixture triggers = window.panel(
  73. new ClassFinder<JPanel>(ActionTriggersPanel.class, null));
  74. final int items = triggers.comboBox().target.getItemCount();
  75. triggers.comboBox().selectItem("Channel message received");
  76. triggers.button(JButtonByTextMatcher.withText("Add")).requireEnabled().click();
  77. final JLabelFixture label = triggers
  78. .label(JLabelByTextMatcher.withText("Channel message received"));
  79. label.requireVisible();
  80. assertTrue(items > triggers.comboBox().target.getItemCount());
  81. triggers.button(new ClassFinder<JButton>(ImageButton.class, null)).click();
  82. for (Component comp : triggers.panel(new ClassFinder<JPanel>(ActionTriggersListPanel.class,
  83. null)).target.getComponents()) {
  84. assertNotSame(label.target, comp);
  85. }
  86. assertEquals(items, triggers.comboBox().target.getItemCount());
  87. }
  88. protected void setupWindow(final Action action) {
  89. window = new DialogFixture(ActionEditorDialog.getActionEditorDialog(null,
  90. "amd-ui-test1", action));
  91. window.robot.settings().eventMode(EventMode.AWT);
  92. window.robot.settings().delayBetweenEvents(150);
  93. window.show();
  94. }
  95. public static junit.framework.Test suite() {
  96. return new junit.framework.JUnit4TestAdapter(ActionEditorDialogTest.class);
  97. }
  98. }