Search in sources :

Example 6 with NlProperty

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

the class ProgressBarInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    List<NlComponent> components = ImmutableList.of(myProgressBar);
    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(10);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(11);
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    verify(panel).addTitle(eq(PROGRESS_BAR));
    for (NlComponentEditor editor : editors) {
        NlProperty property = editor.getProperty();
        assertThat(property).isNotNull();
        verify(panel).addComponent(eq(property.getName()), eq(property.getTooltipText()), eq(editor.getComponent()));
    }
}
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)

Example 7 with NlProperty

use of com.android.tools.idea.uibuilder.property.NlProperty 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());
}
Also used : TextInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString)

Example 8 with NlProperty

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

the class TextInspectorProviderTest method testIsNotApplicableForPreferenceComponents.

public void testIsNotApplicableForPreferenceComponents() {
    Map<String, NlProperty> properties = getPropertyMap(ImmutableList.of(myTextView));
    for (String tagName : PreferenceUtils.VALUES) {
        NlComponent component = mock(NlComponent.class);
        when(component.getTagName()).thenReturn(tagName);
        assertThat(myProvider.isApplicable(ImmutableList.of(component), properties, myPropertiesManager)).isFalse();
    }
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Matchers.anyString(org.mockito.Matchers.anyString)

Example 9 with NlProperty

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

the class TextInspectorProviderTest method testIsApplicableRequiresAllTextAttributesPresent.

public void testIsApplicableRequiresAllTextAttributesPresent() {
    List<NlComponent> components = ImmutableList.of(myTextView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    for (String propertyName : TextInspectorProvider.TEXT_PROPERTIES) {
        Map<String, NlProperty> props = new HashMap<>(properties);
        props.remove(propertyName);
        assertThat(myProvider.isApplicable(components, props, myPropertiesManager)).isFalse();
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString)

Example 10 with NlProperty

use of com.android.tools.idea.uibuilder.property.NlProperty 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();
}
Also used : SdkConstants(com.android.SdkConstants) HashMap(java.util.HashMap) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Matchers.anyString(org.mockito.Matchers.anyString) java.awt(java.awt) Matchers.any(org.mockito.Matchers.any) PropertyTestCase(com.android.tools.idea.uibuilder.property.PropertyTestCase) Mockito(org.mockito.Mockito) List(java.util.List) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) com.android.tools.idea.uibuilder.property.editors(com.android.tools.idea.uibuilder.property.editors) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) Optional(java.util.Optional) TextInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent) PreferenceUtils(com.android.tools.idea.uibuilder.model.PreferenceUtils) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) TextInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) 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