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);
}
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);
}
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();
}
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);
}
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();
}
Aggregations