Skip to content

Commit

Permalink
WIP changes for MDA and Simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant-Archibald-MS committed Dec 10, 2024
1 parent 506f455 commit d18981f
Show file tree
Hide file tree
Showing 27 changed files with 383 additions and 52 deletions.
7 changes: 6 additions & 1 deletion samples/weather/testPlan.fx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ testSuite:
{
'te_categoryname': "Test Category",
'createdon': "2024-12-02T17:52:45Z",
'te_weathercategoryid': "f58de6c-905d-457d-846b-3e0b2aa4c5fd"
'te_weathercategoryid': "8cd3faaa-97ac-4e78-8b71-16c82cabb856"
}
)
});
Expand Down Expand Up @@ -59,6 +59,11 @@ testSuite:
Assert(CountRows(WeatherCategory.Items)=1);
Assert(CountRows(Gallery1.Items)=1);
Assert(Summary.Text="Match: Test Location, Temp: 30^F, Feels: 20^F, Sunny");
- testCaseName: Select category
testCaseDescription: Select a category from the dropdown
testSteps: |
= SetProperty(WeatherCategory.SelectedItems,Table(First(WeatherCategory.Items)));
Experimental.Pause();
testSettings:
headless: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<!-- Nuget Properties -->
<PropertyGroup>
<Authors>Microsoft</Authors>
Expand Down Expand Up @@ -54,4 +59,12 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<MySourceFiles Include="..\..\bin\$(configuration)\Microsoft.PowerApps.TestEngine\Microsoft.PowerApps.TestEngine.pdb" />
</ItemGroup>

<Target Name="CopyFiles" AfterTargets="AfterBuild">
<Copy SourceFiles="@(MySourceFiles)" DestinationFolder="..\..\bin\$(configuration)\PowerAppsTestEngine" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -73,6 +74,7 @@ public ItemPath GetItemPath(string propertyName = null)
/// <returns>True if able to get the field value</returns>
protected override bool TryGetField(FormulaType fieldType, string fieldName, out FormulaValue result)
{

if (fieldType is TableType)
{
// This would be if we were referencing a property that could be indexed. Eg. Gallery1.AllItems (fieldName = AllItems)
Expand Down Expand Up @@ -106,6 +108,13 @@ protected override bool TryGetField(FormulaType fieldType, string fieldName, out
var itemPath = GetItemPath(fieldName);

var propertyValueJson = _testWebProvider.GetPropertyValueFromControl<string>(itemPath);

if (string.IsNullOrEmpty(propertyValueJson))
{
result = BlankValue.NewBlank(fieldType);
return true;
}

var jsPropertyValueModel = JsonConvert.DeserializeObject<JSPropertyValueModel>(propertyValueJson);

if (jsPropertyValueModel != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<MinVerMinimumMajorMinor>1.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<MinVerMinimumMajorMinor>1.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
5 changes: 5 additions & 0 deletions src/testengine.common.user/testengine.common.user.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
5 changes: 5 additions & 0 deletions src/testengine.module.mda/testengine.module.mda.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<MinVerMinimumMajorMinor>1.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
5 changes: 5 additions & 0 deletions src/testengine.module.pause/testengine.module.pause.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<MinVerMinimumMajorMinor>1.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -18,6 +17,11 @@
<MinVerMinimumMajorMinor>1.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
6 changes: 5 additions & 1 deletion src/testengine.module.sample/testengine.module.sample.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -18,6 +17,11 @@
<MinVerMinimumMajorMinor>1.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -12,6 +11,11 @@
<AssemblyOriginatorKeyFile>../../35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<SignAssembly>false</SignAssembly>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -9,6 +8,11 @@
<MinVerMinimumMajorMinor>1.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SignAssembly>true</SignAssembly>
<PublicSign>true</PublicSign>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,76 @@ public static IEnumerable<object[]> GetSetValueData()
"Hello"
};
}

[Theory]
[MemberData(nameof(GetDataFromParentData))]
public async Task GetValueFromParent(ItemPath path, string parentJson, object? expected)
{
// Arrange
MockTestInfraFunctions.Setup(m => m.RunJavascriptAsync<object>(It.IsAny<string>())).Returns(Task.FromResult((object)parentJson));
MockTestState.Setup(m => m.GetDomain()).Returns("https://www.microsoft.com");
MockTestState.Setup(m => m.GetTimeout()).Returns(1000);
MockSingleTestInstanceState.Setup(m => m.GetLogger()).Returns(MockLogger.Object);

// Act
var provider = new ModelDrivenApplicationProvider(MockTestInfraFunctions.Object, MockSingleTestInstanceState.Object, MockTestState.Object);
var json = provider.GetPropertyValueFromControl<string>(path);

// Assert
dynamic result = JsonConvert.DeserializeObject<ExpandoObject>(json);

Assert.Equal(expected, result.PropertyValue);
}

/// <summary>
/// Test data for <see cref="GetDataFromParentData"/>
/// </summary>
/// <returns>MemberData items</returns>
public static IEnumerable<object[]> GetDataFromParentData()
{
var sampleDateUnix = new DateTimeOffset(new DateTime(2024, 12, 1)).ToUnixTimeSeconds();

// Date Time in unix test
yield return new object[] {
new ItemPath{ ControlName = "TableRow", PropertyName = "when", ParentControl = new ItemPath { ControlName = "Gallery", PropertyName = "Items", Index = 0 } },
$"[{{ \"Key\": \"Items\", \"Value\": [ {{ \"when\":{sampleDateUnix} }} ] }}]",
sampleDateUnix
};

// Numeric test
yield return new object[] {
new ItemPath{ ControlName = "TableRow", PropertyName = "num", ParentControl = new ItemPath { ControlName = "Gallery", PropertyName = "Items", Index = 0 } },
$"[{{ \"Key\": \"Items\", \"Value\":[ {{ \"num\": 1}} ] }}]",
(long)1
};

// Numeric test
yield return new object[] {
new ItemPath{ ControlName = "TableRow", PropertyName = "num", ParentControl = new ItemPath { ControlName = "Gallery", PropertyName = "Items", Index = 0 } },
$"[{{ \"Key\": \"Items\", \"Value\":[ {{ \"num\": 1.1}} ] }}]",
1.1
};

// String test
yield return new object[] {
new ItemPath{ ControlName = "TableRow", PropertyName = "text", ParentControl = new ItemPath { ControlName = "Gallery", PropertyName = "Items", Index = 0 } },
$"[{{ \"Key\": \"Items\", \"Value\": [ {{ \"text\": \"A\"}} ] }}]",
"A"
};

// String test
yield return new object[] {
new ItemPath{ ControlName = "TableRow", PropertyName = "text", ParentControl = new ItemPath { ControlName = "Gallery", PropertyName = "Items", Index = 1 } },
$"[{{ \"Key\": \"Items\", \"Value\": [ {{ \"text\": \"A\"}}, {{ \"text\": \"B\"}} ] }}]",
"B"
};

// Object test
yield return new object[] {
new ItemPath{ ControlName = "TableRow", PropertyName = "object", ParentControl = new ItemPath { ControlName = "Gallery", PropertyName = "Items", Index = 0 } },
$"[{{ \"Key\": \"Items\", \"Value\": [ {{ \"object\": {{ \"id\": 1 }} }} ] }}]",
"{\"id\":1}"
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.PowerApps.TestEngine.Config;
using Microsoft.PowerApps.TestEngine.Providers;
using Microsoft.PowerApps.TestEngine.TestInfra;
using Microsoft.PowerFx;
using Microsoft.PowerFx.Types;
using Moq;
using Newtonsoft.Json;
Expand Down Expand Up @@ -771,5 +772,40 @@ public async Task EmbedMDAJSScripts_EmbedsScriptSuccessfully()
// Verify that AddScriptTagAsync was called with the correct PageAddScriptTagOptions
mockPage.Verify(p => p.AddScriptTagAsync(It.Is<PageAddScriptTagOptions>(opt => opt.Url.Contains(expectedScriptHash))), Times.Once);
}

[Theory]
[MemberData(nameof(RecordTestValues))]
public async Task SetRecordValue(FormulaValue data)
{
// Arrange
MockSingleTestInstanceState.Setup(m => m.GetLogger()).Returns(MockLogger.Object);
MockTestInfraFunctions = new Mock<ITestInfraFunctions>();
MockTestInfraFunctions.Setup(m => m.RunJavascriptAsync<string>(It.IsAny<string>()));

var provider = new ModelDrivenApplicationProvider(MockTestInfraFunctions.Object, MockSingleTestInstanceState.Object, MockTestState.Object);


// Act
var row = RecordValue.NewRecordFromFields(new NamedValue("Selected", data)); // BlankValue.NewBlank(RecordValue.NewRecordFromFields(new NamedValue("Name", StringValue.New("")));
var value = RecordValue.NewRecordFromFields(new NamedValue("PropertyValue", row));
await provider.SetPropertyAsync(new ItemPath() { ControlName = "Dropdown1", PropertyName = "Selected" }, value);

// Assert
}

/// <summary>
/// Test data for <see cref="SetRecordValue"/>
/// </summary>
/// <returns>MemberData items</returns>
public static IEnumerable<object[]> RecordTestValues()
{
yield return new object[] {
BlankValue.NewBlank()
};

yield return new object[] {
RecordValue.NewRecordFromFields(new NamedValue("Name", StringValue.New("Test")))
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task ApplyChanges(ITestInfraFunctions testInfraFunctions, ModelDriv
}
else
{
originalState.VariableState.Add(variable, await originalState.ConvertToVariableState(newPowerFxVariableValue));
originalState.VariableState.TryAdd(variable, await originalState.ConvertToVariableState(newPowerFxVariableValue));
}
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public async Task ApplyChanges(ITestInfraFunctions testInfraFunctions, ModelDriv
{
// Add the new collction and cache a copy of the collection state
originalEngine.UpdateVariable(collection, newPowerFxCollectionValue);
originalState.CollectionState.Add(collection, await originalState.ConvertToVariableState(newPowerFxCollectionValue));
originalState.CollectionState.TryAdd(collection, await originalState.ConvertToVariableState(newPowerFxCollectionValue));
}
}
}
Expand Down
Loading

0 comments on commit d18981f

Please sign in to comment.