Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchris.poon2015-08-31 20:23:54 -0400
committerGerrit Code Review @ Eclipse.org2015-09-02 18:16:54 -0400
commit304393bd6fde6b648d93870a825377a3b7eb6872 (patch)
tree91b1632c7c38edf4e02bcd7e716dd0050c45d8e0 /org.eclipse.mylyn.tasks.ui.tests
parent9f4de2dba03de7b00c4db82f7e14ede218697447 (diff)
downloadorg.eclipse.mylyn.tasks-304393bd6fde6b648d93870a825377a3b7eb6872.tar.gz
org.eclipse.mylyn.tasks-304393bd6fde6b648d93870a825377a3b7eb6872.tar.xz
org.eclipse.mylyn.tasks-304393bd6fde6b648d93870a825377a3b7eb6872.zip
476383: add an attribute editor for label fields
Add a text attribute editor that supports single and multi values and has content assist Change-Id: I9e53666e713abb1affbb7b6376c5af7192174ddb Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=476383 Signed-off-by: chris.poon <chris.poon@tasktop.com>
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui.tests')
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/editors/LabelsAttributeEditorTest.java135
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkitTest.java132
2 files changed, 267 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/editors/LabelsAttributeEditorTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/editors/LabelsAttributeEditorTest.java
new file mode 100644
index 000000000..36c73ac3e
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/editors/LabelsAttributeEditorTest.java
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui.editors;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.eclipse.mylyn.internal.tasks.core.data.TaskDataState;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
+import org.eclipse.mylyn.tasks.tests.TaskTestUtil;
+import org.eclipse.mylyn.tasks.tests.connector.MockTask;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan;
+import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class LabelsAttributeEditorTest {
+
+ private TaskData taskData;
+
+ private TaskDataModel model;
+
+ private LabelsAttributeEditor editor;
+
+ private TaskAttribute singleSelectAttribute;
+
+ private TaskAttribute multiSelectAttribute;
+
+ @Before
+ public void setUp() {
+ TaskRepository repository = TaskTestUtil.createMockRepository();
+ taskData = new TaskData(new TaskAttributeMapper(repository), "kind", "url", "id");
+ MockTask task = new MockTask("taskId");
+ TaskDataState state = new TaskDataState("kind", "url", "taskId");
+ state.setEditsData(taskData);
+ state.setLocalTaskData(taskData);
+ model = new TaskDataModel(repository, task, state);
+ }
+
+ @Test
+ public void testSingleSelectEmpty() {
+ createSingleSelect("");
+ assertSingleSelectValue("");
+ editor.setValue("test");
+ assertSingleSelectValue("test");
+ editor.setValue("");
+ assertSingleSelectValue("");
+ }
+
+ @Test
+ public void testSingleSelect() {
+ createSingleSelect("test option");
+ assertSingleSelectValue("test option");
+ editor.setValue("testing option");
+ assertSingleSelectValue("testing option");
+ }
+
+ @Test
+ public void testSingleSelectWithSeparator() {
+ createSingleSelect("one,two , three, four");
+ assertSingleSelectValue("one,two , three, four");
+ editor.setValue("one,two , three, four ,five ,");
+ assertSingleSelectValue("one,two , three, four ,five ,");
+ }
+
+ @Test
+ public void testMultiSelectEmpty() {
+ createMultiSelect(ImmutableList.<String> of());
+ assertMultiSelectValue("", ImmutableList.<String> of());
+ editor.setValue("one,two");
+ assertMultiSelectValue("one, two", ImmutableList.of("one", "two"));
+ editor.setValue("");
+ assertMultiSelectValue("", ImmutableList.<String> of());
+ }
+
+ @Test
+ public void testMultiSelect() {
+ createMultiSelect(ImmutableList.of("one", "two"));
+ assertMultiSelectValue("one, two", ImmutableList.of("one", "two"));
+ editor.setValue("one,two,three,four");
+ assertMultiSelectValue("one, two, three, four", ImmutableList.of("one", "two", "three", "four"));
+ editor.setValue("one");
+ assertMultiSelectValue("one", ImmutableList.of("one"));
+ editor.setValue("one,two , three, four ,five ,, ,");
+ assertMultiSelectValue("one, two, three, four, five", ImmutableList.of("one", "two", "three", "four", "five"));
+ }
+
+ private void createSingleSelect(String value) {
+ singleSelectAttribute = taskData.getRoot().createAttribute("singleSelect");
+ singleSelectAttribute.getMetaData().setType(TaskAttribute.TYPE_SINGLE_SELECT);
+ singleSelectAttribute.setValue(value);
+ editor = new LabelsAttributeEditor(model, singleSelectAttribute);
+ assertLayoutHint(false);
+ }
+
+ private void createMultiSelect(List<String> values) {
+ multiSelectAttribute = taskData.getRoot().createAttribute("multiSelect");
+ multiSelectAttribute.getMetaData().setType(TaskAttribute.TYPE_MULTI_SELECT);
+ multiSelectAttribute.setValues(ImmutableList.copyOf(values));
+ editor = new LabelsAttributeEditor(model, multiSelectAttribute);
+ assertLayoutHint(true);
+ }
+
+ private void assertSingleSelectValue(String value) {
+ assertEquals(value, editor.getValue());
+ assertEquals(value, singleSelectAttribute.getValue());
+ }
+
+ private void assertLayoutHint(boolean isMultiSelect) {
+ assertEquals(ColumnSpan.SINGLE, editor.getLayoutHint().columnSpan);
+ assertEquals((isMultiSelect ? RowSpan.MULTIPLE : RowSpan.SINGLE), editor.getLayoutHint().rowSpan);
+ }
+
+ private void assertMultiSelectValue(String stringValue, List<String> values) {
+ assertEquals(stringValue, editor.getValue());
+ assertEquals(values, multiSelectAttribute.getValues());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkitTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkitTest.java
new file mode 100644
index 000000000..1ff7ac11b
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkitTest.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.ui.editors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+import org.eclipse.mylyn.commons.workbench.WorkbenchUtil;
+import org.eclipse.mylyn.commons.workbench.editors.CommonTextSupport;
+import org.eclipse.mylyn.internal.tasks.ui.OptionsProposalProvider;
+import org.eclipse.mylyn.internal.tasks.ui.editors.LabelsAttributeEditor;
+import org.eclipse.mylyn.internal.tasks.ui.editors.MultiSelectionAttributeEditor;
+import org.eclipse.mylyn.internal.tasks.ui.editors.SingleSelectionAttributeEditor;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
+import org.eclipse.mylyn.tasks.tests.TaskTestUtil;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+public class AttributeEditorToolkitTest {
+ public class TestAttributeEditorToolkit extends AttributeEditorToolkit {
+
+ private ContentAssistCommandAdapter commandAdapter;
+
+ TestAttributeEditorToolkit(CommonTextSupport textSupport) {
+ super(textSupport);
+ }
+
+ @Override
+ public ContentAssistCommandAdapter createContentAssistCommandAdapter(Control control,
+ IContentProposalProvider proposalProvider) {
+ commandAdapter = super.createContentAssistCommandAdapter(control, proposalProvider);
+ return commandAdapter;
+ }
+
+ @Override
+ public IContentProposalProvider createContentProposalProvider(AbstractAttributeEditor editor) {
+ return super.createContentProposalProvider(editor);
+ }
+ }
+
+ private TestAttributeEditorToolkit toolkit;
+
+ private TaskAttribute taskAttribute;
+
+ private final FormToolkit formToolkit = new FormToolkit(Display.getCurrent());
+
+ private final TaskDataModel taskDataModel = mock(TaskDataModel.class);
+
+ @SuppressWarnings("restriction")
+ @Before
+ public void setUp() {
+ CommonTextSupport textSupport = mock(CommonTextSupport.class);
+ toolkit = spy(new TestAttributeEditorToolkit(textSupport));
+ TaskData taskData = TaskTestUtil.createMockTaskData("1");
+ taskAttribute = taskData.getRoot();
+ when(taskDataModel.getTaskData()).thenReturn(taskData);
+ }
+
+ @After
+ public void tearDown() {
+ formToolkit.dispose();
+ }
+
+ @Test
+ public void testAdaptSingleSelectionAttributeEditor() {
+ SingleSelectionAttributeEditor editor = new SingleSelectionAttributeEditor(taskDataModel, taskAttribute);
+ assertNoOptionsProposalProvider(editor);
+ }
+
+ @Test
+ public void testAdaptMultiSelectionAttributeEditor() {
+ MultiSelectionAttributeEditor editor = new MultiSelectionAttributeEditor(taskDataModel, taskAttribute);
+ assertNoOptionsProposalProvider(editor);
+ }
+
+ private void assertNoOptionsProposalProvider(AbstractAttributeEditor editor) {
+ editor.createControl(WorkbenchUtil.getShell(), formToolkit);
+ toolkit.adapt(editor);
+ verify(toolkit, never()).createContentProposalProvider(any(AbstractAttributeEditor.class));
+ verify(toolkit, never()).createContentAssistCommandAdapter(any(Control.class),
+ any(IContentProposalProvider.class));
+ }
+
+ @Test
+ public void testAdaptLabelsAttributeEditor() {
+ assertOptionsProposalProvider(true);
+ assertOptionsProposalProvider(false);
+ }
+
+ private void assertOptionsProposalProvider(boolean isMultiSelect) {
+ taskAttribute.getMetaData().setType(
+ isMultiSelect ? TaskAttribute.TYPE_MULTI_SELECT : TaskAttribute.TYPE_SINGLE_SELECT);
+ LabelsAttributeEditor editor = new LabelsAttributeEditor(taskDataModel, taskAttribute);
+ editor.createControl(WorkbenchUtil.getShell(), formToolkit);
+ toolkit.adapt(editor);
+
+ verify(toolkit).createContentProposalProvider(editor);
+ ArgumentCaptor<IContentProposalProvider> providerCaptor = ArgumentCaptor.forClass(IContentProposalProvider.class);
+ verify(toolkit).createContentAssistCommandAdapter(eq(editor.getControl()), providerCaptor.capture());
+ IContentProposalProvider proposalProvider = providerCaptor.getValue();
+ assertTrue(proposalProvider instanceof OptionsProposalProvider);
+ assertEquals(isMultiSelect, ((OptionsProposalProvider) proposalProvider).isMultiSelect());
+ assertNull(toolkit.commandAdapter.getAutoActivationCharacters());
+ }
+
+}

Back to the top