From d5153b412f95031b99a6a8ea2b9845f45dac9ef8 Mon Sep 17 00:00:00 2001 From: Navaneeth Thekkumpat Date: Mon, 18 Sep 2023 10:34:26 -0400 Subject: [PATCH 1/2] Updating setproperty for date value to set date to utc time --- .../PowerApps/PowerAppFunctionsTest.cs | 10 ++++++++-- .../PowerApps/PowerAppFunctions.cs | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) 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..c120a4f64 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,13 @@ 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 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 one-off 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); } From fa9163f7759c3d259c6f213698e5a69a234f7897 Mon Sep 17 00:00:00 2001 From: Navaneeth Thekkumpat Date: Mon, 18 Sep 2023 11:06:50 -0400 Subject: [PATCH 2/2] refactoring comments --- .../PowerApps/PowerAppFunctions.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs b/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs index c120a4f64..3721bb177 100644 --- a/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs +++ b/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs @@ -277,10 +277,8 @@ public async Task SetPropertyDateAsync(ItemPath itemPath, DateValue value) var recordValue = value.GetConvertedValue(null); // Date.parse() parses the date to unix timestamp. - // SetProperty value expected from user is 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 one-off in day value. + // 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}}})";