Search in sources :

Example 1 with SwitchHandler

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

Aggregations

SwitchHandler (com.android.tools.idea.uibuilder.handlers.SwitchHandler)1 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)1 NlComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)1 Matchers.anyString (org.mockito.Matchers.anyString)1