Search in sources :

Example 16 with NlProperty

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

the class IdInspectorProviderTest method testUpdateProperties.

public void testUpdateProperties() {
    List<NlComponent> components = ImmutableList.of(myTextView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    IdInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    inspector.updateProperties(ImmutableList.of(), properties, myPropertiesManager);
    components = ImmutableList.of(myButtonInConstraintLayout);
    properties = getPropertyMap(components);
    inspector.updateProperties(components, properties, myPropertiesManager);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString) IdInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent)

Example 17 with NlProperty

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

the class ViewInspectorProviderTest method testUpdateProperties.

public void testUpdateProperties() {
    List<NlComponent> components = ImmutableList.of(myImageView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    InspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    inspector.updateProperties(components, properties, myPropertiesManager);
    NlComponentEditor srcEditor = inspector.getEditors().get(0);
    assertThat(srcEditor.getProperty()).isNotNull();
    assertThat(srcEditor.getProperty().getName()).isEqualTo(ATTR_SRC);
    // Simulate the addition of appcompat library:
    AttributeDefinition srcCompatDefinition = new AttributeDefinition(ATTR_SRC_COMPAT);
    properties.put(ATTR_SRC_COMPAT, new NlPropertyItem(components, ANDROID_URI, srcCompatDefinition));
    // Check that an update will replace the ATTR_SRC with ATTR_SRC_COMPAT
    inspector.updateProperties(components, properties, myPropertiesManager);
    srcEditor = inspector.getEditors().get(0);
    assertThat(srcEditor.getProperty()).isNotNull();
    assertThat(srcEditor.getProperty().getName()).isEqualTo(ATTR_SRC_COMPAT);
    // Simulate the removal of appcompat library:
    properties.remove(ATTR_SRC_COMPAT);
    // Check that an update will replace the ATTR_SRC with ATTR_SRC_COMPAT
    inspector.updateProperties(components, properties, myPropertiesManager);
    srcEditor = inspector.getEditors().get(0);
    assertThat(srcEditor.getProperty()).isNotNull();
    assertThat(srcEditor.getProperty().getName()).isEqualTo(ATTR_SRC);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) Matchers.anyString(org.mockito.Matchers.anyString) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 18 with NlProperty

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

the class ViewInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    List<NlComponent> components = ImmutableList.of(mySwitch);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    InspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    List<NlComponentEditor> editors = inspector.getEditors();
    assertThat(editors.size()).isEqualTo(14);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(editors.size() + 1);
    Set<String> inspectorProperties = new HashSet<>(new SwitchHandler().getInspectorProperties());
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    verify(panel).addTitle(SWITCH);
    for (NlComponentEditor editor : editors) {
        NlProperty property = editor.getProperty();
        assertThat(property).isNotNull();
        verify(panel).addComponent(eq(property.getName()), eq(property.getTooltipText()), eq(editor.getComponent()));
        assertThat(editor.getLabel()).isNotNull();
        if (TOOLS_URI.equals(property.getNamespace())) {
            assertThat(editor.getLabel().getIcon()).isEqualTo(AndroidIcons.NeleIcons.DesignProperty);
            if (!inspectorProperties.remove(TOOLS_NS_NAME_PREFIX + property.getName())) {
                assertThat(inspectorProperties.remove(TOOLS_NS_NAME_PREFIX + property.getName())).named(property.getName()).isTrue();
            }
        } else {
            assertThat(editor.getLabel().getIcon()).isNull();
            assertThat(inspectorProperties.remove(property.getName())).named(property.getName()).isTrue();
        }
    }
    assertThat(inspectorProperties).isEmpty();
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor) SwitchHandler(com.android.tools.idea.uibuilder.handlers.SwitchHandler) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty)

Example 19 with NlProperty

use of com.android.tools.idea.uibuilder.property.NlProperty 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)

Example 20 with NlProperty

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

the class IdInspectorProviderTest method testIsNotApplicableForPreferenceAndMenuComponents.

public void testIsNotApplicableForPreferenceAndMenuComponents() {
    Map<String, NlProperty> properties = getPropertyMap(ImmutableList.of(myTextView));
    for (String tagName : PreferenceUtils.VALUES) {
        assertThat(myProvider.isApplicable(ImmutableList.of(mockComponentWithTag(tagName)), properties, myPropertiesManager)).isFalse();
    }
    assertThat(myProvider.isApplicable(ImmutableList.of(mockComponentWithTag(TAG_GROUP)), properties, myPropertiesManager)).isFalse();
    assertThat(myProvider.isApplicable(ImmutableList.of(mockComponentWithTag(TAG_ITEM)), properties, myPropertiesManager)).isFalse();
    assertThat(myProvider.isApplicable(ImmutableList.of(mockComponentWithTag(TAG_MENU)), properties, myPropertiesManager)).isFalse();
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)25 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)17 Matchers.anyString (org.mockito.Matchers.anyString)12 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)7 NlComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)6 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)5 TextInspectorComponent (com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent)3 IdInspectorComponent (com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent)2 HashMap (java.util.HashMap)2 SdkConstants (com.android.SdkConstants)1 ChooseResourceDialog (com.android.tools.idea.ui.resourcechooser.ChooseResourceDialog)1 SwitchHandler (com.android.tools.idea.uibuilder.handlers.SwitchHandler)1 PreferenceUtils (com.android.tools.idea.uibuilder.model.PreferenceUtils)1 PropertyTestCase (com.android.tools.idea.uibuilder.property.PropertyTestCase)1 com.android.tools.idea.uibuilder.property.editors (com.android.tools.idea.uibuilder.property.editors)1 NlBaseComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlBaseComponentEditor)1 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1