-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add base for unit tests * Add unit tests for TextBlock, Image, Media, Container and CollectionTypeElement * Add more tests * Adds all actions to tests * Add tests for base element properties * Add tests for almost all elements * Add missing readonly elements tests * Add warning for test that fails * [Android] Add unit tests for inpu elements (#3094) * Add text input tests * Add numberInputTests * Add Date and Time input tests * Add toggle visibility and choiceset input tests * Fix togggle input tests * fixing layout constraint issue * dev complete * ready
- Loading branch information
1 parent
24c9ba9
commit d4c5950
Showing
31 changed files
with
5,252 additions
and
115 deletions.
There are no files selected for viewing
26 changes: 0 additions & 26 deletions
26
.../android/adaptivecards/src/androidTest/java/io/adaptivecards/ExampleInstrumentedTest.java
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
...ptivecards/src/androidTest/java/io/adaptivecards/objectmodel/ActionSetPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package io.adaptivecards.objectmodel; | ||
|
||
import android.drm.DrmStore; | ||
import android.util.Pair; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ActionSetPropertiesTest | ||
{ | ||
|
||
static { | ||
System.loadLibrary("adaptivecards-native-lib"); | ||
} | ||
|
||
@Test | ||
public void AllPropertiesWithInheritedTest() | ||
{ | ||
final String actionSetWithActions = | ||
"{\"actions\":[" + | ||
"{\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}," + | ||
"{\"card\":{" + | ||
"\"actions\":[" + | ||
"{\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}]," + | ||
"\"body\":[" + | ||
"{\"text\":\"Test\",\"type\":\"TextBlock\"}]," + | ||
"\"type\":\"AdaptiveCard\",\"version\":\"1.0\"" + | ||
"},\"type\":\"Action.ShowCard\"}," + | ||
"{\"data\":{\"data\":\"Some data\"},\"type\":\"Action.Submit\"}," + | ||
"{\"targetElements\":[" + | ||
"\"id1\"," + | ||
"{\"elementId\":\"id2\",\"isVisible\":true}," + | ||
"{\"elementId\":\"id3\",\"isVisible\":false}]," + | ||
"\"type\":\"Action.ToggleVisibility\"}]," + | ||
"\"fallback\":{\"type\":\"Image\",\"url\":\"http://\"}," + | ||
"\"height\":\"Stretch\"," + | ||
"\"id\":\"Sample id\"," + | ||
"\"isVisible\":false," + | ||
"\"separator\":true," + | ||
"\"spacing\":\"medium\"," + | ||
"\"type\":\"ActionSet\"}\n"; | ||
|
||
ActionSet actionSet = TestUtil.createSampleActionSet(); | ||
actionSet.SetFallbackType(FallbackType.Content); | ||
actionSet.SetFallbackContent(TestUtil.createMockImage()); | ||
actionSet.SetHeight(HeightType.Stretch); | ||
actionSet.SetId("Sample id"); | ||
actionSet.SetIsVisible(false); | ||
actionSet.SetSeparator(true); | ||
actionSet.SetSpacing(Spacing.Medium); | ||
|
||
Assert.assertEquals(actionSetWithActions, actionSet.Serialize()); | ||
} | ||
|
||
@Test | ||
public void ActionsTest() throws Exception | ||
{ | ||
{ | ||
final String actionSetEmptyActions = "{\"actions\":[],\"type\":\"ActionSet\"}\n"; | ||
ActionSet actionSet = TestUtil.createMockActionSet(); | ||
Assert.assertEquals(actionSetEmptyActions, actionSet.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseElementJsonInCard(actionSetEmptyActions), "1.0"); | ||
ActionSet parsedActionSet = TestUtil.castToActionSet(result.GetAdaptiveCard().GetBody().get(0)); | ||
Assert.assertEquals(0, parsedActionSet.GetActions().size()); | ||
} | ||
|
||
{ | ||
final String actionSetWithActions = | ||
"{\"actions\":[" + | ||
"{\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}," + | ||
"{\"card\":{" + | ||
"\"actions\":[" + | ||
"{\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}]," + | ||
"\"body\":[" + | ||
"{\"text\":\"Test\",\"type\":\"TextBlock\"}]," + | ||
"\"type\":\"AdaptiveCard\",\"version\":\"1.0\"" + | ||
"},\"type\":\"Action.ShowCard\"}," + | ||
"{\"data\":{\"data\":\"Some data\"},\"type\":\"Action.Submit\"}," + | ||
"{\"targetElements\":[" + | ||
"\"id1\"," + | ||
"{\"elementId\":\"id2\",\"isVisible\":true}," + | ||
"{\"elementId\":\"id3\",\"isVisible\":false}]," + | ||
"\"type\":\"Action.ToggleVisibility\"}]," + | ||
"\"type\":\"ActionSet\"}\n"; | ||
|
||
ActionSet actionSet = TestUtil.createSampleActionSet(); | ||
Assert.assertEquals(actionSetWithActions, actionSet.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseElementJsonInCard(actionSetWithActions), "1.0"); | ||
ActionSet parsedActionSet = TestUtil.castToActionSet(result.GetAdaptiveCard().GetBody().get(0)); | ||
Assert.assertEquals(4, parsedActionSet.GetActions().size()); | ||
} | ||
} | ||
|
||
} |
229 changes: 229 additions & 0 deletions
229
...ds/src/androidTest/java/io/adaptivecards/objectmodel/BaseActionElementPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
package io.adaptivecards.objectmodel; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class BaseActionElementPropertiesTest | ||
{ | ||
|
||
static { | ||
System.loadLibrary("adaptivecards-native-lib"); | ||
} | ||
|
||
@Test | ||
public void AllPropertiesTest() throws Exception | ||
{ | ||
final String openUrlActionNoDefaultValues = | ||
"{\"fallback\":{\"data\":{\"data\":\"Some data\"},\"type\":\"Action.Submit\"}," + | ||
"\"iconUrl\":\"http://\"," + | ||
"\"id\":\"Sample id\"," + | ||
"\"style\":\"positive\"," + | ||
"\"title\":\"Sample Title\"," + | ||
"\"type\":\"Action.OpenUrl\"," + | ||
"\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetFallbackType(FallbackType.Content); | ||
openUrlAction.SetFallbackContent(TestUtil.createSampleSubmitAction()); | ||
openUrlAction.SetIconUrl("http://"); | ||
openUrlAction.SetId("Sample id"); | ||
openUrlAction.SetStyle("positive"); | ||
openUrlAction.SetTitle("Sample Title"); | ||
|
||
Assert.assertEquals(openUrlActionNoDefaultValues, openUrlAction.Serialize()); | ||
} | ||
|
||
@Test | ||
public void FallbackContentTest() throws Exception | ||
{ | ||
{ | ||
final String openUrlJson = "{\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetFallbackContent(null); | ||
Assert.assertEquals(openUrlJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals(null, parsedOpenUrlAction.GetFallbackContent()); | ||
} | ||
|
||
{ | ||
final String openUrlActionDropFallbackJson = "{\"fallback\":\"drop\",\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetFallbackType(FallbackType.Drop); | ||
Assert.assertEquals(openUrlActionDropFallbackJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionDropFallbackJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals(FallbackType.Drop, parsedOpenUrlAction.GetFallbackType()); | ||
} | ||
|
||
{ | ||
final String openUrlActionSubmitActionFallbackJson = | ||
"{\"fallback\":{\"data\":{\"data\":\"Some data\"},\"type\":\"Action.Submit\"}," + | ||
"\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetFallbackType(FallbackType.Content); | ||
openUrlAction.SetFallbackContent(TestUtil.createSampleSubmitAction()); | ||
Assert.assertEquals(openUrlActionSubmitActionFallbackJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionSubmitActionFallbackJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals(FallbackType.Content, parsedOpenUrlAction.GetFallbackType()); | ||
|
||
BaseActionElement fallbackBaseActionElement = TestUtil.castToBaseActionElement(parsedOpenUrlAction.GetFallbackContent()); | ||
Assert.assertEquals(ActionType.Submit, fallbackBaseActionElement.GetElementType()); | ||
|
||
SubmitAction fallbackSubmitAction = TestUtil.castToSubmitAction(fallbackBaseActionElement); | ||
Assert.assertEquals("{\"data\":\"Some data\"}\n", fallbackSubmitAction.GetDataJson()); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void IdTest() throws Exception | ||
{ | ||
{ | ||
final String openUrlActionJson = "{\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("", parsedOpenUrlAction.GetId()); | ||
|
||
openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetId(""); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("", parsedOpenUrlAction.GetId()); | ||
} | ||
|
||
{ | ||
final String openUrlActionJson = "{\"id\":\"Sample Id\",\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetId("Sample Id"); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("Sample Id", parsedOpenUrlAction.GetId()); | ||
} | ||
} | ||
|
||
@Test | ||
public void IconUrlTest() throws Exception | ||
{ | ||
{ | ||
final String openUrlActionJson = "{\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("", parsedOpenUrlAction.GetIconUrl()); | ||
|
||
openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetIconUrl(""); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("", parsedOpenUrlAction.GetIconUrl()); | ||
} | ||
|
||
{ | ||
final String openUrlActionJson = "{\"iconUrl\":\"http://\",\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetIconUrl("http://"); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("http://", parsedOpenUrlAction.GetIconUrl()); | ||
} | ||
} | ||
|
||
@Test | ||
public void StyleTest() throws Exception | ||
{ | ||
{ | ||
final String openUrlActionJson = "{\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("default", parsedOpenUrlAction.GetStyle()); | ||
|
||
openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetStyle(""); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("default", parsedOpenUrlAction.GetStyle()); | ||
} | ||
|
||
{ | ||
final String openUrlActionJson = "{\"style\":\"positive\",\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetStyle("positive"); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("positive", parsedOpenUrlAction.GetStyle()); | ||
} | ||
} | ||
|
||
@Test | ||
public void TitleTest() throws Exception | ||
{ | ||
{ | ||
final String openUrlActionJson = "{\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("default", parsedOpenUrlAction.GetStyle()); | ||
|
||
openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetTitle(""); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("", parsedOpenUrlAction.GetTitle()); | ||
} | ||
|
||
{ | ||
final String openUrlActionJson = "{\"title\":\"Sample Title\",\"type\":\"Action.OpenUrl\",\"url\":\"http://\"}\n"; | ||
|
||
OpenUrlAction openUrlAction = TestUtil.createSampleOpenUrlAction(); | ||
openUrlAction.SetTitle("Sample Title"); | ||
Assert.assertEquals(openUrlActionJson, openUrlAction.Serialize()); | ||
|
||
ParseResult result = AdaptiveCard.DeserializeFromString(TestUtil.encloseActionJsonInCard(openUrlActionJson), "1.0"); | ||
OpenUrlAction parsedOpenUrlAction = TestUtil.castToOpenUrlAction(result.GetAdaptiveCard().GetActions().get(0)); | ||
Assert.assertEquals("Sample Title", parsedOpenUrlAction.GetTitle()); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.