Skip to main content
summaryrefslogtreecommitdiffstats
blob: ed6ac394913a65f6eed294a842a69946459eb814 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.tasklist.tests;

import java.util.List;

import junit.framework.TestCase;

import org.eclipse.mylar.core.MylarPlugin;
import org.eclipse.mylar.internal.tasklist.Task;
import org.eclipse.mylar.internal.tasklist.TaskListManager;
import org.eclipse.mylar.internal.tasklist.ui.actions.NextTaskDropDownAction;
import org.eclipse.mylar.internal.tasklist.ui.actions.PreviousTaskDropDownAction;
import org.eclipse.mylar.internal.tasklist.ui.actions.TaskActivateAction;
import org.eclipse.mylar.internal.tasklist.ui.actions.TaskDeactivateAction;
import org.eclipse.mylar.internal.tasklist.ui.actions.TaskNavigateDropDownAction.TaskNavigateAction;
import org.eclipse.mylar.internal.tasklist.ui.views.TaskActivationHistory;
import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView;
import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.mylar.tasklist.MylarTaskListPlugin;
import org.eclipse.ui.PartInitException;

/**
 * @author Wes Coelho
 */
public class TaskHistoryTest extends TestCase {

	protected TaskListManager manager = MylarTaskListPlugin.getTaskListManager();

	protected TaskListView taskView = null;

	protected Task task1 = null;

	protected Task task2 = null;

	protected Task task3 = null;

	protected Task task4 = null;

	protected Task task5 = null;

	protected void setUp() throws Exception {
		super.setUp();

		try {
			MylarTaskListPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(
					"org.eclipse.mylar.tasks.ui.views.TaskListView");
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail("View not initialized");
		}

		assertNotNull(TaskListView.getDefault());
		taskView = TaskListView.getDefault();

		resetHistory();

		task1 = new Task(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(), "task 1", true);
		task2 = new Task(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(), "task 2", true);
		task3 = new Task(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(), "task 3", true);
		task4 = new Task(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(), "task 4", true);
		task5 = new Task(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(), "task 5", true);

		manager.moveToRoot(task1);
		manager.moveToRoot(task2);
		manager.moveToRoot(task3);
		manager.moveToRoot(task4);
		manager.moveToRoot(task5);

	}

	private void resetHistory() {
		taskView.clearTaskHistory();
		MylarPlugin.getContextManager().resetActivityHistory();
	}

	/**
	 * Tests the next task and previous task navigation.
	 */
	public void testBasicHistoryNavigation() {
		(new TaskActivateAction()).run(task1);
		taskView.addTaskToHistory(task1);
		(new TaskActivateAction()).run(task2);
		taskView.addTaskToHistory(task2);
		(new TaskActivateAction()).run(task3);
		taskView.addTaskToHistory(task3);

		assertTrue(task3.isActive());
		assertFalse(task2.isActive());

		taskView.getPreviousTaskAction().run();
		assertTrue(task2.isActive());

		taskView.getPreviousTaskAction().run();
		assertTrue(task1.isActive());

		taskView.getPreviousTaskAction().run();
		assertTrue(task1.isActive());

		taskView.getNextTaskAction().run();
		assertTrue(task2.isActive());

		taskView.getNextTaskAction().run();
		assertTrue(task3.isActive());

		taskView.getNextTaskAction().run();
		assertTrue(task3.isActive());

		taskView.getPreviousTaskAction().run();
		assertTrue(task2.isActive());

		taskView.getNextTaskAction().run();
		assertTrue(task3.isActive());

		(new TaskActivateAction()).run(task4);
		taskView.addTaskToHistory(task4); // Simulate clicking on it rather
											// than navigating next or previous
		assertTrue(task4.isActive());

		taskView.getNextTaskAction().run();
		assertTrue(task4.isActive());

		taskView.getPreviousTaskAction().run();
		assertTrue(task3.isActive());

		taskView.getNextTaskAction().run();
		assertTrue(task4.isActive());

	}

	/**
	 * Tests navigation to previous/next tasks that are chosen from a list
	 * rather than being sequentially navigated
	 */
	public void testArbitraryHistoryNavigation() {

		resetHistory();

		// Simulate activating the tasks by clicking rather than
		// navigating previous/next
		(new TaskActivateAction()).run(task1);
		taskView.addTaskToHistory(task1);
		(new TaskActivateAction()).run(task2);
		taskView.addTaskToHistory(task2);
		(new TaskActivateAction()).run(task3);
		taskView.addTaskToHistory(task3);
		(new TaskActivateAction()).run(task4);
		taskView.addTaskToHistory(task4);

		assertTrue(task4.isActive());
		TaskActivationHistory taskHistory = taskView.getTaskActivationHistory();
		List<ITask> prevHistoryList = taskHistory.getPreviousTasks();

		// Check that the previous history list looks right
		assertTrue(prevHistoryList.size() >= 3);
		assertTrue(prevHistoryList.get(prevHistoryList.size() - 1) == task3);
		assertTrue(prevHistoryList.get(prevHistoryList.size() - 2) == task2);
		assertTrue(prevHistoryList.get(prevHistoryList.size() - 3) == task1);

		// Get a task from the list and activate it
		PreviousTaskDropDownAction prevAction = new PreviousTaskDropDownAction(taskView, taskHistory);
		TaskNavigateAction navigateAction = prevAction.new TaskNavigateAction(task2);
		navigateAction.run();
		taskHistory.navigatedToTask(task2);

		assertTrue(task2.isActive());

		// Now check that the next and prev lists look right
		prevHistoryList = taskHistory.getPreviousTasks();
		assertTrue(prevHistoryList.get(prevHistoryList.size() - 1) == task1);
		List<ITask> nextHistoryList = taskHistory.getNextTasks();
		assertTrue(nextHistoryList.get(0) == task3);
		assertTrue(nextHistoryList.get(1) == task4);

		// Navigate to a next item
		NextTaskDropDownAction nextAction = new NextTaskDropDownAction(taskView, taskHistory);
		navigateAction = nextAction.new TaskNavigateAction(task4);
		navigateAction.run();
		taskHistory.navigatedToTask(task4);

		assertTrue(task4.isActive());

		// Check that the prev and next lists look right
		nextHistoryList = taskHistory.getNextTasks();
		prevHistoryList = taskHistory.getPreviousTasks();
		assertTrue(nextHistoryList.size() == 0);
		assertTrue(prevHistoryList.get(prevHistoryList.size() - 1) == task3);
		assertTrue(prevHistoryList.get(prevHistoryList.size() - 2) == task2);
		assertTrue(prevHistoryList.get(prevHistoryList.size() - 3) == task1);

		// Check that a deactivated task appears first on the history list
		(new TaskActivateAction()).run(task5);
		(new TaskDeactivateAction()).run(task5);
		taskView.addTaskToHistory(task5);
		prevHistoryList = taskHistory.getPreviousTasks();
		assertTrue(prevHistoryList.get(prevHistoryList.size() - 1) == task5);

	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

}

Back to the top