diff --git a/src/Microsoft.PowerApps.TestEngine.Tests/PowerApps/PowerAppFunctionsTest.cs b/src/Microsoft.PowerApps.TestEngine.Tests/PowerApps/PowerAppFunctionsTest.cs index 911b6ebb5..1af288741 100644 --- a/src/Microsoft.PowerApps.TestEngine.Tests/PowerApps/PowerAppFunctionsTest.cs +++ b/src/Microsoft.PowerApps.TestEngine.Tests/PowerApps/PowerAppFunctionsTest.cs @@ -158,7 +158,8 @@ public async Task SetPropertyDateAsyncTest() var result = await powerAppFunctions.SetPropertyAsync(itemPath, DateValue.NewDateOnly(dt.Date)); Assert.True(result); - MockTestInfraFunctions.Verify(x => x.RunJavascriptAsync($"PowerAppsTestEngine.setPropertyValue({itemPathString},{{\"SelectedDate\":Date.parse(\"{((DateValue)DateValue.NewDateOnly(dt.Date)).GetConvertedValue(null)}\")}})"), Times.Once()); + var dateTimeValue = convertDateToDateTimeUTC(dt); + MockTestInfraFunctions.Verify(x => x.RunJavascriptAsync($"PowerAppsTestEngine.setPropertyValue({itemPathString},{{\"SelectedDate\":Date.parse(\"{dateTimeValue}\")}})"), Times.Once()); } [Fact] @@ -823,7 +824,8 @@ public async Task SetPropertyDateAsyncNoPublishedAppFunction() var powerAppFunctions = new PowerAppFunctions(MockTestInfraFunctions.Object, MockSingleTestInstanceState.Object, MockTestState.Object); await Assert.ThrowsAsync(async () => { await powerAppFunctions.SetPropertyDateAsync(itemPath, DateValue.NewDateOnly(dt.Date)); }); - MockTestInfraFunctions.Verify(x => x.RunJavascriptAsync($"PowerAppsTestEngine.setPropertyValue({itemPathString},{{\"SelectedDate\":Date.parse(\"{((DateValue)DateValue.NewDateOnly(dt.Date)).GetConvertedValue(null)}\")}})"), Times.Once()); + var dateTimeValue = convertDateToDateTimeUTC(dt); + MockTestInfraFunctions.Verify(x => x.RunJavascriptAsync($"PowerAppsTestEngine.setPropertyValue({itemPathString},{{\"SelectedDate\":Date.parse(\"{dateTimeValue}\")}})"), Times.Once()); LoggingTestHelper.VerifyLogging(MockLogger, ExceptionHandlingHelper.PublishedAppWithoutJSSDKMessage, LogLevel.Error, Times.Once()); } @@ -864,5 +866,9 @@ public async Task GetPropertyAsyncNoPublishedAppFunction() } // End Published App JSSDK not found tests + private string convertDateToDateTimeUTC(DateTime dt) + { + return $"{DateValue.NewDateOnly(dt.Date).GetConvertedValue(null).ToString("yyyy-MM-dd")}{PowerAppFunctions.UTCTimeValue}"; + } } } diff --git a/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs b/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs index 572a126e5..3721bb177 100644 --- a/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs +++ b/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs @@ -25,6 +25,7 @@ public class PowerAppFunctions : IPowerAppFunctions public static string PublishedAppIframeName = "fullscreen-app-host"; public static string CheckPowerAppsTestEngineObject = "typeof PowerAppsTestEngine"; public static string CheckPowerAppsTestEngineReadyFunction = "typeof PowerAppsTestEngine.testEngineReady"; + public static string UTCTimeValue = "T00:00:00.000Z"; private string GetItemCountErrorMessage = "Something went wrong when Test Engine tried to get item count."; private string GetPropertyValueErrorMessage = "Something went wrong when Test Engine tried to get property value."; @@ -275,8 +276,11 @@ public async Task SetPropertyDateAsync(ItemPath itemPath, DateValue value) var propertyNameString = JsonConvert.SerializeObject(itemPath.PropertyName); var recordValue = value.GetConvertedValue(null); - // Date.parse() parses the date to unix timestamp - var expression = $"PowerAppsTestEngine.setPropertyValue({itemPathString},{{{propertyNameString}:Date.parse(\"{recordValue}\")}})"; + // Date.parse() parses the date to unix timestamp. + // SetProperty value expected from user is in format Date(yyyy, MM, dd), setting the time value to T00:00.000Z to maintain uniformity across timezones. + // This value explicitly specifies the UTC timezone. This helps in fetching the date value as it is in any timezone locally without considering off by one in day value. + var dt = $"Date.parse(\"{recordValue.Date.ToString("yyyy-MM-dd")}{UTCTimeValue}\")"; + var expression = $"PowerAppsTestEngine.setPropertyValue({itemPathString},{{{propertyNameString}:{dt}}})"; return await _testInfraFunctions.RunJavascriptAsync(expression); }