use of com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent in project android by JetBrains.
the class TextInspectorProviderTest method testInspectorComponent.
public void testInspectorComponent() {
List<NlComponent> components = ImmutableList.of(myTextView);
Map<String, NlProperty> properties = getPropertyMap(components);
assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
TextInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
List<NlComponentEditor> editors = inspector.getEditors();
assertThat(editors.size()).isEqualTo(9);
assertThat(inspector.getMaxNumberOfRows()).isEqualTo(12);
InspectorPanel panel = mock(InspectorPanel.class);
when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
inspector.attachToInspector(panel);
verify(panel).addTitle(eq(TEXT_VIEW));
for (NlComponentEditor editor : editors) {
NlProperty property = editor.getProperty();
assertThat(property).isNotNull();
if (property.getName().equals(ATTR_TEXT_APPEARANCE)) {
assertThat(editor).isInstanceOf(NlEnumEditor.class);
NlEnumEditor enumEditor = (NlEnumEditor) editor;
verify(panel).addExpandableComponent(eq(property.getName()), eq(property.getTooltipText()), eq(editor.getComponent()), eq(enumEditor.getKeySource()));
} else {
verify(panel).addComponent(eq(property.getName()), eq(property.getTooltipText()), eq(editor.getComponent()));
}
}
propertyPanelHasAllComponents(panel, ATTR_TEXT_STYLE, properties, inspector.getTextStyleEditors());
propertyPanelHasAllComponents(panel, ATTR_TEXT_ALIGNMENT, properties, inspector.getTextAlignmentEditors());
}
use of com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent in project android by JetBrains.
the class TextInspectorProviderTest method testTextAppearanceResetsOtherStyles.
public void testTextAppearanceResetsOtherStyles() {
List<NlComponent> components = ImmutableList.of(myTextView);
Map<String, NlProperty> properties = getPropertyMap(components);
properties.get(ATTR_FONT_FAMILY).setValue("serif");
properties.get(ATTR_TYPEFACE).setValue("sans");
properties.get(ATTR_TEXT_SIZE).setValue("24sp");
properties.get(ATTR_LINE_SPACING_EXTRA).setValue("24sp");
properties.get(ATTR_TEXT_COLOR).setValue("@android:color/holo_blue_dark");
properties.get(ATTR_TEXT_STYLE).setValue("bold|italic");
properties.get(ATTR_TEXT_ALL_CAPS).setValue("true");
properties.get(ATTR_TEXT_ALIGNMENT).setValue("textStart");
assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
TextInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
inspector.refresh();
Optional<NlComponentEditor> textAppearanceEditor = inspector.getEditors().stream().filter(editor -> editor.getProperty() != null && editor.getProperty().getName().equals(ATTR_TEXT_APPEARANCE)).findFirst();
assertThat(textAppearanceEditor.isPresent()).isTrue();
assert textAppearanceEditor.isPresent();
assertThat(textAppearanceEditor.get()).isInstanceOf(NlBaseComponentEditor.class);
NlBaseComponentEditor editor = (NlBaseComponentEditor) textAppearanceEditor.get();
editor.stopEditing("Material.Display1");
assertThat(properties.get(ATTR_TEXT_APPEARANCE).getValue()).isEqualTo("Material.Display1");
assertThat(properties.get(ATTR_FONT_FAMILY).getValue()).isNull();
assertThat(properties.get(ATTR_TYPEFACE).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_SIZE).getValue()).isNull();
assertThat(properties.get(ATTR_LINE_SPACING_EXTRA).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_COLOR).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_STYLE).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_ALL_CAPS).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_ALIGNMENT).getValue()).isNull();
}
Aggregations