Search in sources :

Example 6 with NlComponentEditor

use of com.android.tools.idea.uibuilder.property.editors.NlComponentEditor in project android by JetBrains.

the class FavoritesInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    NlPropertyItem elevation = createFrom(myTextView, ATTR_ELEVATION);
    NlPropertyItem visibility = createFrom(myTextView, ATTR_VISIBILITY);
    NlPropertyItem text = createFrom(myTextView, ATTR_TEXT);
    myPropertiesComponent.setValue(STARRED_PROP, TOOLS_NS_NAME_PREFIX + ATTR_ELEVATION + ";" + ATTR_VISIBILITY);
    List<NlComponent> components = Collections.singletonList(myTextView);
    Map<String, NlProperty> properties = ImmutableMap.of(ATTR_TEXT, text, ATTR_ELEVATION, elevation, ATTR_VISIBILITY, visibility);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    InspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    List<NlComponentEditor> editors = inspector.getEditors();
    assertThat(editors.size()).isEqualTo(2);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(3);
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    verify(panel).addTitle(eq("Favorite Attributes"));
    NlComponentEditor visibilityEditor = editors.get(1);
    assertThat(visibilityEditor.getProperty()).isSameAs(visibility);
    verify(panel).addComponent(eq(visibility.getName()), eq(visibility.getTooltipText()), eq(visibilityEditor.getComponent()));
    JLabel visibilityLabel = visibilityEditor.getLabel();
    assertThat(visibilityLabel).isNotNull();
    assertThat(visibilityLabel.getIcon()).isNull();
    NlComponentEditor elevationEditor = editors.get(0);
    NlProperty elevationDesignProperty = elevationEditor.getProperty();
    assertThat(elevationDesignProperty.getName()).isEqualTo(elevation.getName());
    assertThat(elevationDesignProperty.getDefinition()).isSameAs(elevation.getDefinition());
    assertThat(elevationDesignProperty.getNamespace()).isEqualTo(TOOLS_URI);
    verify(panel).addComponent(eq(elevationDesignProperty.getName()), eq(elevationDesignProperty.getTooltipText()), eq(elevationEditor.getComponent()));
    JLabel elevationLabel = elevationEditor.getLabel();
    assertThat(elevationLabel).isNotNull();
    assertThat(elevationLabel.getIcon()).isSameAs(AndroidIcons.NeleIcons.DesignProperty);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Aggregations

NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)6 NlComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)6 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)5 Matchers.anyString (org.mockito.Matchers.anyString)5 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)2 SwitchHandler (com.android.tools.idea.uibuilder.handlers.SwitchHandler)1 IdInspectorComponent (com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent)1 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)1