Skip to content

Commit

Permalink
[Android] Fix fallback again in master (#3280)
Browse files Browse the repository at this point in the history
* Fix issue introduced by column fallback

* Add test for feature registration
  • Loading branch information
almedina-ms authored Aug 26, 2019
1 parent da79c45 commit 95bfaec
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.adaptivecards.objectmodel;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.test.mock.MockContext;
import android.widget.LinearLayout;

import junit.framework.Assert;

import org.junit.Test;

import io.adaptivecards.renderer.AdaptiveCardRenderer;
import io.adaptivecards.renderer.RenderedAdaptiveCard;
import io.adaptivecards.renderer.registration.CardRendererRegistration;

public class FeatureRegistrationRenderTest
{

static {
System.loadLibrary("adaptivecards-native-lib");
}

@Test
public void TestDefaultRendering() throws Exception
{
final String cardJson =
"{\"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\"," +
"\"type\": \"AdaptiveCard\"," +
"\"version\": \"1.0\"," +
"\"body\": [{\"type\": \"TextBlock\",\"text\": \"This is some text\"}]" +
"}";

HostConfig hostConfig = new HostConfig();

ParseContext parseContext = new ParseContext();
ParseResult parseResult = AdaptiveCard.DeserializeFromString(cardJson, AdaptiveCardRenderer.VERSION, parseContext);
Context context = InstrumentationRegistry.getTargetContext();
AdaptiveCardRenderer.getInstance().render(context, null, parseResult.GetAdaptiveCard(), null, hostConfig);
}

@Test
public void TestFeatureRegistrationRendering() throws Exception
{
final String cardJson =
"{\"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\"," +
"\"type\": \"AdaptiveCard\"," +
"\"version\": \"1.0\"," +
"\"body\": [{\"type\": \"TextBlock\",\"text\": \"This is some text\"}]" +
"}";

HostConfig hostConfig = new HostConfig();

ParseContext parseContext = new ParseContext();
ParseResult parseResult = AdaptiveCard.DeserializeFromString(cardJson, AdaptiveCardRenderer.VERSION, parseContext);
Context context = InstrumentationRegistry.getTargetContext();

FeatureRegistration featureRegistration = new FeatureRegistration();
featureRegistration.AddFeature("featureName", "1.0");
CardRendererRegistration.getInstance().registerFeatureRegistration(featureRegistration);

AdaptiveCardRenderer.getInstance().render(context, null, parseResult.GetAdaptiveCard(), null, hostConfig);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ else if ((fallbackActionElement = BaseActionElement.dynamic_cast(fallbackElement
throw new AdaptiveFallbackException(fallbackElement);
}

if (!fallbackElement.MeetsRequirements(featureRegistration))
if ((featureRegistration != null) && (!fallbackElement.MeetsRequirements(featureRegistration)))
{
throw new AdaptiveFallbackException(fallbackElement, featureRegistration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ else if ((fallbackCardElement = BaseCardElement.dynamic_cast(fallbackElement)) =
throw new AdaptiveFallbackException(fallbackCardElement);
}

if (!fallbackElement.MeetsRequirements(featureRegistration))
if ((featureRegistration != null) && (!fallbackElement.MeetsRequirements(featureRegistration)))
{
throw new AdaptiveFallbackException(fallbackCardElement, featureRegistration);
}
Expand Down

0 comments on commit 95bfaec

Please sign in to comment.