Search in sources :

Example 71 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class ProgressBarInspectorProviderTest method testChangingIndeterminateChangesVisibilityOfEditors.

public void testChangingIndeterminateChangesVisibilityOfEditors() {
    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);
    inspector.refresh();
    assertThat(isEditorVisible(inspector, ATTR_STYLE, "")).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_DRAWABLE)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_DRAWABLE)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_TINT)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_TINT)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_MAXIMUM)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY, TOOLS_URI)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE)).isTrue();
    NlBaseComponentEditor indeterminateEditor = (NlBaseComponentEditor) getEditor(inspector, ATTR_INDETERMINATE, ANDROID_URI);
    indeterminateEditor.stopEditing("true");
    assertThat(isEditorVisible(inspector, ATTR_STYLE, "")).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_DRAWABLE)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_DRAWABLE)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_TINT)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_TINT)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_MAXIMUM)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY, TOOLS_URI)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE)).isTrue();
    indeterminateEditor.stopEditing("false");
    assertThat(isEditorVisible(inspector, ATTR_STYLE, "")).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_DRAWABLE)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_DRAWABLE)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_TINT)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_TINT)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_MAXIMUM)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY, TOOLS_URI)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE)).isTrue();
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString) NlBaseComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlBaseComponentEditor)

Example 72 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent 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 73 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent 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 74 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent 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 75 with NlComponent

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

Aggregations

NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)184 NlModel (com.android.tools.idea.uibuilder.model.NlModel)34 NotNull (org.jetbrains.annotations.NotNull)34 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)18 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)17 Nullable (org.jetbrains.annotations.Nullable)14 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)11 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)9 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)9 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)8 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 XmlFile (com.intellij.psi.xml.XmlFile)7 XmlTag (com.intellij.psi.xml.XmlTag)7 ArrayList (java.util.ArrayList)7 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)6 NlGraphics (com.android.tools.idea.uibuilder.graphics.NlGraphics)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Project (com.intellij.openapi.project.Project)6 List (java.util.List)6