|
@@ -0,0 +1,220 @@
|
|
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
|
+
|
|
23
|
+package com.dmdirc.addons.ui_swing.dialogs.actionsmanager;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.actions.Action;
|
|
26
|
+import com.dmdirc.actions.ActionGroup;
|
|
27
|
+import com.dmdirc.actions.CoreActionType;
|
|
28
|
+import com.dmdirc.actions.interfaces.ActionType;
|
|
29
|
+import java.util.ArrayList;
|
|
30
|
+import java.util.Arrays;
|
|
31
|
+import org.junit.Before;
|
|
32
|
+import org.junit.Test;
|
|
33
|
+import org.uispec4j.Panel;
|
|
34
|
+import org.uispec4j.Table;
|
|
35
|
+import org.uispec4j.Trigger;
|
|
36
|
+import org.uispec4j.UISpecTestCase;
|
|
37
|
+import org.uispec4j.Window;
|
|
38
|
+import org.uispec4j.interception.WindowHandler;
|
|
39
|
+import org.uispec4j.interception.WindowInterceptor;
|
|
40
|
+import static org.junit.Assume.*;
|
|
41
|
+import static org.mockito.Mockito.*;
|
|
42
|
+
|
|
43
|
+public class ActionsGroupPanelTest extends UISpecTestCase {
|
|
44
|
+
|
|
45
|
+ private static Action action1, action2, action3, action4;
|
|
46
|
+
|
|
47
|
+ @Before
|
|
48
|
+ @Override
|
|
49
|
+ public void setUp() {
|
|
50
|
+ action1 = mock(Action.class);
|
|
51
|
+ when(action1.getName()).thenReturn("name 1");
|
|
52
|
+ when(action1.getTriggers()).thenReturn(new ActionType[] {
|
|
53
|
+ CoreActionType.ACTION_CREATED, CoreActionType.ACTION_DELETED,
|
|
54
|
+ });
|
|
55
|
+ when(action1.getResponse()).thenReturn(new String[0]);
|
|
56
|
+
|
|
57
|
+ action2 = mock(Action.class);
|
|
58
|
+ when(action2.getName()).thenReturn("name 2");
|
|
59
|
+ when(action2.getTriggers()).thenReturn(new ActionType[] {
|
|
60
|
+ CoreActionType.ACTION_CREATED
|
|
61
|
+ });
|
|
62
|
+ when(action2.getResponse()).thenReturn(new String[0]);
|
|
63
|
+
|
|
64
|
+ action3 = mock(Action.class);
|
|
65
|
+ when(action3.getName()).thenReturn("name 3");
|
|
66
|
+ when(action3.getTriggers()).thenReturn(new ActionType[] {
|
|
67
|
+ CoreActionType.ACTION_CREATED, CoreActionType.ACTION_DELETED,
|
|
68
|
+ });
|
|
69
|
+ when(action3.getResponse()).thenReturn(new String[] {
|
|
70
|
+ "Response line 1",
|
|
71
|
+ "Response line 2",
|
|
72
|
+ "Response line 3",
|
|
73
|
+ });
|
|
74
|
+
|
|
75
|
+ action4 = mock(Action.class);
|
|
76
|
+ when(action4.getName()).thenReturn("name 4");
|
|
77
|
+ when(action4.getTriggers()).thenReturn(new ActionType[] {
|
|
78
|
+ CoreActionType.ACTION_CREATED
|
|
79
|
+ });
|
|
80
|
+ when(action4.getResponse()).thenReturn(new String[] {
|
|
81
|
+ "Response line 1",
|
|
82
|
+ "Response line 2",
|
|
83
|
+ "Response line 3",
|
|
84
|
+ });
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ @Test
|
|
88
|
+ public void testTable() {
|
|
89
|
+ final ActionGroup group = mock(ActionGroup.class);
|
|
90
|
+ when(group.getActions()).thenReturn(Arrays.asList(new Action[]{
|
|
91
|
+ action1, action2, action3, action4,
|
|
92
|
+ }));
|
|
93
|
+
|
|
94
|
+ final Panel panel = new Panel(new ActionsGroupPanel(null, group));
|
|
95
|
+ final Table table = panel.getTable();
|
|
96
|
+
|
|
97
|
+ assertTrue(table.getHeader().contentEquals("Name", "Trigger", "Response"));
|
|
98
|
+
|
|
99
|
+ assertTrue(table.contentEquals(new String[][]{
|
|
100
|
+ {"name 1", "Action created", ""},
|
|
101
|
+ {"name 2", "Action created", ""},
|
|
102
|
+ {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
|
|
103
|
+ {"name 4", "Action created", "Response line 1, Response line 2, Response line 3"},
|
|
104
|
+ }));
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ @Test
|
|
108
|
+ public void testDeletingCancel() {
|
|
109
|
+ final ActionGroup group = mock(ActionGroup.class);
|
|
110
|
+ when(group.getActions()).thenReturn(new ArrayList<Action>(Arrays.asList(new Action[]{
|
|
111
|
+ action1, action2, action3, action4,
|
|
112
|
+ })));
|
|
113
|
+
|
|
114
|
+ final Panel panel = new Panel(new ActionsGroupPanel(null, group));
|
|
115
|
+ final Table table = panel.getTable();
|
|
116
|
+
|
|
117
|
+ table.selectRow(1);
|
|
118
|
+
|
|
119
|
+ WindowInterceptor.init(panel.getButton("Delete").triggerClick())
|
|
120
|
+ .process(new WindowHandler() {
|
|
121
|
+
|
|
122
|
+ @Override
|
|
123
|
+ public Trigger process(final Window window) throws Exception {
|
|
124
|
+ assumeTrue("Confirm deletion".equals(window.getTitle()));
|
|
125
|
+
|
|
126
|
+ return window.getButton("No").triggerClick();
|
|
127
|
+ }
|
|
128
|
+ }).run();
|
|
129
|
+
|
|
130
|
+ assertTrue(table.contentEquals(new String[][]{
|
|
131
|
+ {"name 1", "Action created", ""},
|
|
132
|
+ {"name 2", "Action created", ""},
|
|
133
|
+ {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
|
|
134
|
+ {"name 4", "Action created", "Response line 1, Response line 2, Response line 3"},
|
|
135
|
+ }));
|
|
136
|
+ verify(group, never()).deleteAction((Action) anyObject());
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ public void testDeletingOk() {
|
|
140
|
+ final ActionGroup group = mock(ActionGroup.class);
|
|
141
|
+ when(group.getActions()).thenReturn(new ArrayList<Action>(Arrays.asList(new Action[]{
|
|
142
|
+ action1, action2, action3, action4,
|
|
143
|
+ })));
|
|
144
|
+
|
|
145
|
+ final Panel panel = new Panel(new ActionsGroupPanel(null, group));
|
|
146
|
+ final Table table = panel.getTable();
|
|
147
|
+
|
|
148
|
+ table.selectRow(1);
|
|
149
|
+
|
|
150
|
+ WindowInterceptor.init(panel.getButton("Delete").triggerClick())
|
|
151
|
+ .process(new WindowHandler() {
|
|
152
|
+
|
|
153
|
+ @Override
|
|
154
|
+ public Trigger process(final Window window) throws Exception {
|
|
155
|
+ assumeTrue("Confirm deletion".equals(window.getTitle()));
|
|
156
|
+
|
|
157
|
+ return window.getButton("Yes").triggerClick();
|
|
158
|
+ }
|
|
159
|
+ }).run();
|
|
160
|
+
|
|
161
|
+ verify(group).deleteAction(same(action2));
|
|
162
|
+ }
|
|
163
|
+
|
|
164
|
+ public void testDeletingSorted() {
|
|
165
|
+ final ActionGroup group = mock(ActionGroup.class);
|
|
166
|
+ when(group.getActions()).thenReturn(new ArrayList<Action>(Arrays.asList(new Action[]{
|
|
167
|
+ action1, action2, action3, action4,
|
|
168
|
+ })));
|
|
169
|
+
|
|
170
|
+ final Panel panel = new Panel(new ActionsGroupPanel(null, group));
|
|
171
|
+ final Table table = panel.getTable();
|
|
172
|
+
|
|
173
|
+ table.getHeader().click("Name");
|
|
174
|
+
|
|
175
|
+ table.selectRow(1);
|
|
176
|
+
|
|
177
|
+ WindowInterceptor.init(panel.getButton("Delete").triggerClick())
|
|
178
|
+ .process(new WindowHandler() {
|
|
179
|
+
|
|
180
|
+ @Override
|
|
181
|
+ public Trigger process(final Window window) throws Exception {
|
|
182
|
+ assumeTrue("Confirm deletion".equals(window.getTitle()));
|
|
183
|
+
|
|
184
|
+ return window.getButton("Yes").triggerClick();
|
|
185
|
+ }
|
|
186
|
+ }).run();
|
|
187
|
+
|
|
188
|
+ verify(group).deleteAction(same(action3));
|
|
189
|
+ }
|
|
190
|
+
|
|
191
|
+ public void testTableDeleting() {
|
|
192
|
+ final ActionGroup group = mock(ActionGroup.class);
|
|
193
|
+ when(group.getActions()).thenReturn(new ArrayList<Action>(Arrays.asList(new Action[]{
|
|
194
|
+ action1, action2, action3, action4,
|
|
195
|
+ })));
|
|
196
|
+
|
|
197
|
+ final Panel panel = new Panel(new ActionsGroupPanel(null, group));
|
|
198
|
+ final Table table = panel.getTable();
|
|
199
|
+
|
|
200
|
+ assertTrue(table.contentEquals(new String[][]{
|
|
201
|
+ {"name 1", "Action created", ""},
|
|
202
|
+ {"name 2", "Action created", ""},
|
|
203
|
+ {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
|
|
204
|
+ {"name 4", "Action created", "Response line 1, Response line 2, Response line 3"},
|
|
205
|
+ }));
|
|
206
|
+
|
|
207
|
+ when(group.getActions()).thenReturn(new ArrayList<Action>(Arrays.asList(new Action[]{
|
|
208
|
+ action1, action3, action4,
|
|
209
|
+ })));
|
|
210
|
+
|
|
211
|
+ ((ActionsGroupPanel) panel.getAwtComponent()).actionDeleted("name 2");
|
|
212
|
+
|
|
213
|
+ assertTrue(table.contentEquals(new String[][]{
|
|
214
|
+ {"name 1", "Action created", ""},
|
|
215
|
+ {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
|
|
216
|
+ {"name 4", "Action created", "Response line 1, Response line 2, Response line 3"},
|
|
217
|
+ }));
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+}
|