diff --git a/samples/mdaformtablecontrol/MDA_FormControl_1_0_0_1_managed.zip b/samples/mdaformtablecontrol/MDA_FormControl_1_0_0_1_managed.zip new file mode 100644 index 00000000..4fcbb1f1 Binary files /dev/null and b/samples/mdaformtablecontrol/MDA_FormControl_1_0_0_1_managed.zip differ diff --git a/samples/mdaformtablecontrol/README.md b/samples/mdaformtablecontrol/README.md new file mode 100644 index 00000000..5be61f90 --- /dev/null +++ b/samples/mdaformtablecontrol/README.md @@ -0,0 +1,43 @@ +# Overview + +This Power Apps Test Engine sample demonstrates how to assert and interact with the values of Table, Form, and Classic Forms—EditForm and ViewForm controls—in a model-driven application form. + +## Usage + +1. **Build the Test Engine Solution** + Ensure the Power Apps Test Engine solution is built and ready to be executed. + +2. **Get the URL of the Model-Driven Application Form** + Acquire the URL of the specific model-driven application form that you want to test. + +3. **Modify the testPlan.fx.yaml** + Update the YAML file to assert expected values of the Table, Form, and Classic Forms—EditForm and ViewForm controls. + + > **Note:** The controls are referenced using the [logical name](https://learn.microsoft.com/power-apps/developer/data-platform/entity-metadata#table-names). + +4. **Update the Domain URL for Your Model-Driven Application** + + | URL Part | Description | + | ---------------------------------------------- | ------------------------------------------------------- | + | `appid=a1234567-cccc-44444-9999-a123456789123` | The unique identifier of your model-driven application. | + | `etn=` | The name of the entity being validated. | + | `id=26bafa27-ca7d-ee11-8179-0022482a91f4` | The unique identifier of the record being edited. | + | `pagetype=custom` | The type of page to open. | + | `UserAuth=storagestate` | The type of user authentication to use. | + | `UseStaticContext=True` | A flag indicating the use of a static context. | + +5. **Execute the Test for Custom Page** + Please replace the example URLs with your organization's URL. Validate the number of records in the Employee table before executing the test plan. If needed, update the number in the test plan. + + **Command for Form and Table Controls:** + ```pwsh + cd bin\Debug\PowerAppsEngine + dotnet PowerAppsTestEngine.dll -i ..\..\..\samples\mdaformtablecontrol\formtablecontroltestplan.fx.yaml -e 00000000-0000-0000-0000-11112223333 -t 11112222-3333-4444-5555-666677778888 -u browser -p mda -d "https://orgfc708206.crm.dynamics.com/main.aspx?appid=706281e3-b1ed-ef11-be20-7c1e526718b6&pagetype=custom&name=cr693_employeedetails_7f620" + ``` + + **Command for Classic Form and Table Controls:** + ```pwsh + cd bin\Debug\PowerAppsEngine + dotnet PowerAppsTestEngine.dll -i ..\..\..\samples\mdaformtablecontrol\classicformtablecontroltestplan.fx.yaml -e 00000000-0000-0000-0000-11112223333 -t 11112222-3333-4444-5555-666677778888 -u browser -p mda -d "https://orgfc708206.crm.dynamics.com/main.aspx?appid=706281e3-b1ed-ef11-be20-7c1e526718b6&pagetype=custom&name=cr7d6_classicforms_e08a2" + ``` + diff --git a/samples/mdaformtablecontrol/RunTests.ps1 b/samples/mdaformtablecontrol/RunTests.ps1 new file mode 100644 index 00000000..5b10ef75 --- /dev/null +++ b/samples/mdaformtablecontrol/RunTests.ps1 @@ -0,0 +1,33 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +# Get current directory so we can reset back to it after running the tests +$currentDirectory = Get-Location + +$config = Get-Content -Path .\config.json -Raw | ConvertFrom-Json +$tenantId = $config.tenantId +$environmentId = $config.environmentId +$user1Email = $config.user1Email + +if ([string]::IsNullOrEmpty($environmentId)) { + Write-Error "Environment not configured. Please update config.json" + return +} + +# Build the latest debug version of Test Engine from source +Set-Location ..\..\src +dotnet build + +if ($config.installPlaywright) { + Start-Process -FilePath "pwsh" -ArgumentList "-Command `"..\bin\Debug\PowerAppsTestEngine\playwright.ps1 install`"" -Wait +} else { + Write-Host "Skipped playwright install" +} + +Set-Location ..\bin\Debug\PowerAppsTestEngine +$env:user1Email = $user1Email +# Run the tests for each user in the configuration file. +dotnet PowerAppsTestEngine.dll -u "storagestate" -p "mda" -a "none" -i "$currentDirectory\formtablecontroltestplan.fx.yaml" -t $tenantId -e $environmentId + +# Reset the location back to the original directory. +Set-Location $currentDirectory \ No newline at end of file diff --git a/samples/mdaformtablecontrol/classicformtablecontroltestplan.fx.yaml b/samples/mdaformtablecontrol/classicformtablecontroltestplan.fx.yaml new file mode 100644 index 00000000..90554b3e --- /dev/null +++ b/samples/mdaformtablecontrol/classicformtablecontroltestplan.fx.yaml @@ -0,0 +1,158 @@ +testSuite: + testSuiteName: MDA Custom Page tests - Table and Classic Edit and View form Control + testSuiteDescription: Verify test cases for Table and Classic Edit and View form Control in Custom Page + persona: User1 + appLogicalName: NotNeeded + + testCases: + - testCaseName: Test Table Control - Selected Property + testCaseDescription: Verify that selecting a row updates the Selected property correctly. + testSteps: | + SetProperty(Table1.SelectedItems, Table(Index(Table1.Items, 5))); + Select(Table1, 5); + Wait(FormViewer1, "Visible", true); + Assert(Form1.Visible = false && FormViewer1.Visible = true, "Checking if the View form is displayed and Edit form is hidden correctly"); + Assert(Employee_Name_DataCard2.Default = "Diana Prince", "Checking if the selected record in the table display correctly in view form"); + + - testCaseName: Test Table Control - Validate the Selected Record in Form + testCaseDescription: Verify that selected record in the table display correctly in view form. + testSteps: | + SetProperty(Table1.SelectedItems, Table(First(Table1.Items))); + Assert(Employee_Name_DataCard2.Default = "George Clooney", "Checking if the selected record in the table display correctly in view form"); + + - testCaseName: Test Edit Form through Edit Button + testCaseDescription: Verify that Edit form is visible on click of Edit button. + testSteps: | + Select(btnEdit); + Assert(Form1.Visible = true && FormViewer1.Visible = false, "Checking if the Edit form is displayed and View form is hidden correctly"); + + - testCaseName: Test Form Control in Edit Mode - Validate Mode + testCaseDescription: Verify that Form control is in Edit mode. + testSteps: | + Assert(Form1.DefaultMode = 0, "Checking if the form control is in edit mode during edit operation"); + + - testCaseName: Test Edit Form through updating field value + testCaseDescription: Verify that Edit form through updating field value. + testSteps: | + SetProperty(Department_DataCard1.Default, {Id:681470003,Value:"Sales"}); + SetProperty(DOB_DataCard1.Default, DateTime(1983,01,09,10,0,0)); + SetProperty(Email_DataCard1.Default, "xyz123@abc.com"); + Select(btnUpdate); + SetProperty(Table1.SelectedItems, Table(First(Table1.Items))); + Select(Table1, 1); + Wait(FormViewer1, "Visible", true); + Assert(DOB_DataCard2.Default = "1/9/1983 10:00 AM", "Check if the DOB displays '01/09/1983 10:00 AM'."); + Assert(Email_DataCard2.Default = "xyz123@abc.com", "Checking if the email value updated to new value"); + Assert(CountRows('DataCardValue12'.SelectedItems) = 1, "Check if only one item is selected in Department Field."); + Assert(Form1.Visible = false && FormViewer1.Visible = true, "Checking if the Edit form is displayed and View form is hidden correctly"); + + + # + # + # - testCaseName: Test Form Control in Edit Mode - Validate Mode + # testCaseDescription: Verify that Form control is in edit mode during edit operation. + # testSteps: | + # SetProperty(Form2.DefaultMode, 0); + # Assert(Form2.DefaultMode = 0, "Checking if the form control is in edit mode during edit operation"); + + # - testCaseName: Test Form Control in Edit Mode - Edit Value of Form Controls + # testCaseDescription: Verify that Form control is in edit mode during edit operation. + # testSteps: | + # SetProperty(Department_DataCard2.Default, {Id:681470003,Value:"Sales"}); + # SetProperty(Address_DataCard2.Default, "152 South Cross Street"); + # SetProperty(Email_DataCard2.Default, "xyz@abc.com"); + # SetProperty(Phone_Number_DataCard2.Default, "0987654321"); + # SetProperty(DOB_DataCard3.Default, DateTime(1983,01,09,09,0,0)); + # Select(btnEdit); + # SetProperty(Table1.SelectedItems, Table(First(Table1.Items))); + # Assert(Email_DataCard2.Default = "xyz@abc.com", "Checking if the email value updated to new value"); + # Assert(Phone_Number_DataCard2.Default = "0987654321", "Checking if the phone value updated to new value"); + # Assert(DOB_DataCard3.Default = DateTime(1983,01,09,09,0,0), "Check if the DOB displays '01/09/1983 09:00 AM'."); + + + # # Form control test cases + + # - testCaseName: Navigate to New Employee Form Control + # testCaseDescription: Verify that the Form Navigate to the new Employee form. + # testSteps: | + # Select(btnNew); + + # - testCaseName: Test Employee_Name_DataCard2 - Default Value + # testCaseDescription: Verify that the Employee Name field displays the default value correctly. + # testSteps: | + # SetProperty(Employee_Name_DataCard2.Default, "David Benjamin12"); + # Assert(Employee_Name_DataCard2.Default = "David Benjamin12", "Check if the Employee Name displays 'James Clear'."); + + # - testCaseName: Test Gender_DataCard2 - Default Value + # testCaseDescription: Verify that updating the Gender field reflects correctly. + # testSteps: | + # SetProperty(Gender_DataCard2.Default, {Id:681470001,Value:"Female"}); + # Assert(CountRows('DataCardValue7'.SelectedItems) = 1, "Check if only one item is selected in Gender Field."); + + # - testCaseName: Test DOB_DataCard3 - DateTime Value + # testCaseDescription: Verify that setting DateTime in the DOB field reflects correctly. + # testSteps: | + # SetProperty(DOB_DataCard3.Default, DateTime(1975,01,01,05,0,0)); + # Assert(DOB_DataCard3.Default = DateTime(1975,01,01,05,0,0), "Check if the DOB displays '01/01/1975 05:00 AM'."); + + # - testCaseName: Test Department_DataCard2 - Default Value + # testCaseDescription: Verify that the Department field displays the default value correctly. + # testSteps: | + # SetProperty(Department_DataCard2.Default, {Id:681470003,Value:"Sales"}); + # Assert(CountRows('DataCardValue8'.SelectedItems) = 1, "Check if only one item is selected in Department Field."); + + # - testCaseName: Test Address_DataCard3 - Default Value + # testCaseDescription: Verify that the Address field displays the default value correctly. + # testSteps: | + # SetProperty(Address_DataCard3.Default, "100 North Cross Street"); + # Assert(Address_DataCard3.Default = "100 North Cross Street", "Check if the Address displays '152 South Cross Street'."); + + # - testCaseName: Test Email_DataCard2 - Default Value + # testCaseDescription: Verify that the Email field displays the default value correctly. + # testSteps: | + # SetProperty(Email_DataCard2.Default, "DavidBenjamin@abc.com"); + # Assert(Email_DataCard2.Default = "DavidBenjamin@abc.com", "Check if the Email displays 'DavidBenjamin@abc.com'."); + + # - testCaseName: Test Phone_Number_DataCard2 - Default Value + # testCaseDescription: Verify that the Phone Number field displays the default value correctly. + # testSteps: | + # SetProperty(Phone_Number_DataCard2.Default, "1112223344"); + # Assert(Phone_Number_DataCard2.Default = "1112223344", "Check if the Phone Number displays '1112223344'."); + + # - testCaseName: Test Save Functionality of the New Employee Form Control + # testCaseDescription: Verify that the Employee data in the form saved correctly. + # testSteps: | + # Select(btnSubmit); + # Assert(CountRows(Table1.Items) = 14, "Checking if Table displays correct number of items"); + + # - testCaseName: Test Reset Functionality of the New Employee Form Control + # testCaseDescription: Verify that the Employee data in the form is reset to default value. + # testSteps: | + # SetProperty(Employee_Name_DataCard2.Default, "John Benjamin"); + # SetProperty(Gender_DataCard2.Default, {Id:681470001,Value:"Female"}); + # SetProperty(DOB_DataCard3.Default, DateTime(1975,01,01,05,0,0)); + # SetProperty(Department_DataCard2.Default, {Id:681470003,Value:"Sales"}); + # SetProperty(Address_DataCard3.Default, "152 South Cross Street"); + # SetProperty(Email_DataCard2.Default, "JohnBenjamin@abc.com"); + # SetProperty(Phone_Number_DataCard2.Default, "1112223344"); + # Select(btnReset); + # Wait(Employee_Name_DataCard2, "Default",""); + # Assert(Employee_Name_DataCard2.Default = "", "Check if the Employee Name displays default value."); + # Assert(DOB_DataCard3.Default = DateTime(1980,01,01,03,0,0), "Check if the DOB displays '01/01/1980 03:00 AM'."); + # Assert(CountRows('DataCardValue8'.SelectedItems) = 1, "Check if only one item is selected in Department Field."); + +testSettings: + headless: false + locale: "en-US" + recordVideo: true + extensionModules: + enable: true + browserConfigurations: + - browser: Chromium + channel: msedge + +environmentVariables: + users: + - personaName: User1 + emailKey: user1Email + passwordKey: NotNeeded diff --git a/samples/mdaformtablecontrol/formtablecontroltestplan.fx.yaml b/samples/mdaformtablecontrol/formtablecontroltestplan.fx.yaml new file mode 100644 index 00000000..5397826f --- /dev/null +++ b/samples/mdaformtablecontrol/formtablecontroltestplan.fx.yaml @@ -0,0 +1,154 @@ +testSuite: + testSuiteName: MDA Custom Page tests - Form Control + testSuiteDescription: Verify test cases for Form Control in Custom Page + persona: User1 + appLogicalName: NotNeeded + + testCases: + + # Table control test cases + - testCaseName: Test Table Control - Items Property + testCaseDescription: Verify that the Table Control correctly loads and displays items. + testSteps: | + Assert(CountRows(Table1.Items) = 15, "Checking if Table displays correct number of items"); + + - testCaseName: Test Table Control - ReflowBehavior Property + testCaseDescription: Verify that the Table Control refresh behavior works as expected. + testSteps: | + SetProperty(Table1.ReflowBehavior, "Reflow"); + Assert(Table1.ReflowBehavior = "Reflow", "Checking the refresh behavior setting"); + + - testCaseName: Test Table Control - Selected Property + testCaseDescription: Verify that selecting a row updates the Selected property correctly. + testSteps: | + SetProperty(Table1.SelectedItems, Table(First(Table1.Items))); + Assert(CountRows(Table1.SelectedItems) = 1, "Checking if the selected row updates correctly"); + + - testCaseName: Test Table Control - Multiple Select Property + testCaseDescription: Verify that selecting a row updates the Selected property correctly. + testSteps: | + SetProperty(Table1.SelectedItems, Table(First(Table1.Items), Last(Table1.Items))); + Assert(CountRows(Table1.SelectedItems) = 2, "Checking if the table control allow to select multiple values"); + + - testCaseName: Test Table Control - EnableMultipleSelection Property + testCaseDescription: Verify that the Table Control EnableMultipleSelection works as expected. + testSteps: | + SetProperty(Table1.EnableMultipleSelection, "no"); + Assert(Table1.EnableMultipleSelection = "no", "Checking the EnableMultipleSelection setting"); + SetProperty(Table1.EnableMultipleSelection, "yes"); + Assert(Table1.EnableMultipleSelection = "yes", "Checking the EnableMultipleSelection setting"); + + - testCaseName: Test Table Control - EnableRangeSelection Property + testCaseDescription: Verify that the Table Control EnableRangeSelection works as expected. + testSteps: | + SetProperty(Table1.EnableRangeSelection, "no"); + Assert(Table1.EnableRangeSelection = "no", "Checking the EnableRangeSelection setting"); + SetProperty(Table1.EnableRangeSelection, "yes"); + Assert(Table1.EnableRangeSelection = "yes", "Checking the EnableRangeSelection setting"); + + - testCaseName: Test Table Control - EnableSorting Property + testCaseDescription: Verify that the Table Control EnableSorting works as expected. + testSteps: | + SetProperty(Table1.EnableSorting, "no"); + Assert(Table1.EnableSorting = "no", "Checking the EnableSorting setting"); + SetProperty(Table1.EnableSorting, "yes"); + Assert(Table1.EnableSorting = "yes", "Checking the EnableSorting setting"); + + - testCaseName: Test Form Control in View Mode - Validate Mode + testCaseDescription: Verify that Form control is in read only mode before edit. + testSteps: | + Assert(Form2.DefaultMode = 2, "Checking if the form control is in readonly mode before edit operation"); + + - testCaseName: Test Form Control in Edit Mode - Validate Mode + testCaseDescription: Verify that Form control is in edit mode during edit operation. + testSteps: | + SetProperty(Form2.DefaultMode, 0); + Assert(Form2.DefaultMode = 0, "Checking if the form control is in edit mode during edit operation"); + + - testCaseName: Test Form Control in Edit Mode - Edit Value of Form Controls + testCaseDescription: Verify that Form control is in edit mode during edit operation. + testSteps: | + SetProperty(Table1.SelectedItems, Table(First(Table1.Items))); + SetProperty(Department_DataCard2.Default, {Id:681470003,Value:"Sales"}); + SetProperty(Address_DataCard2.Default, "152 North East Cross Street"); + SetProperty(Email_DataCard2.Default, "xyz@abc.com"); + SetProperty(Phone_Number_DataCard2.Default, "0987654321"); + SetProperty(DOB_DataCard3.Default, DateTime(1983,01,09,09,0,0)); + Select(btnEdit); + SetProperty(Table1.SelectedItems, Table(First(Table1.Items))); + Assert(Email_DataCard2.Default = "xyz@abc.com", "Checking if the email value updated to new value"); + Assert(Phone_Number_DataCard2.Default = "0987654321", "Checking if the phone value updated to new value"); + Assert(DOB_DataCard3.Default = DateTime(1983,01,09,09,0,0), "Check if the DOB displays '01/09/1983 09:00 AM'."); + + + # Form control test cases + + - testCaseName: Navigate to New Employee Form Control + testCaseDescription: Verify that the Form Navigate to the new Employee form. + testSteps: | + Select(btnNew); + + - testCaseName: Test Employee_Name_DataCard2 - Default Value + testCaseDescription: Verify that the Employee Name field displays the default value correctly. + testSteps: | + SetProperty(Employee_Name_DataCard2.Default, "David Benjamin12"); + Assert(Employee_Name_DataCard2.Default = "David Benjamin12", "Check if the Employee Name displays 'James Clear'."); + + - testCaseName: Test Gender_DataCard2 - Default Value + testCaseDescription: Verify that updating the Gender field reflects correctly. + testSteps: | + SetProperty(Gender_DataCard2.Default, {Id:681470001,Value:"Female"}); + Assert(CountRows('DataCardValue7'.SelectedItems) = 1, "Check if only one item is selected in Gender Field."); + + - testCaseName: Test DOB_DataCard3 - DateTime Value + testCaseDescription: Verify that setting DateTime in the DOB field reflects correctly. + testSteps: | + SetProperty(DOB_DataCard3.Default, DateTime(1975,01,01,05,0,0)); + Assert(DOB_DataCard3.Default = DateTime(1975,01,01,05,0,0), "Check if the DOB displays '01/01/1975 05:00 AM'."); + + - testCaseName: Test Department_DataCard2 - Default Value + testCaseDescription: Verify that the Department field displays the default value correctly. + testSteps: | + SetProperty(Department_DataCard2.Default, {Id:681470003,Value:"Sales"}); + Assert(CountRows('DataCardValue8'.SelectedItems) = 1, "Check if only one item is selected in Department Field."); + + - testCaseName: Test Address_DataCard3 - Default Value + testCaseDescription: Verify that the Address field displays the default value correctly. + testSteps: | + SetProperty(Address_DataCard3.Default, "100 North Cross Street"); + Assert(Address_DataCard3.Default = "100 North Cross Street", "Check if the Address displays '152 South Cross Street'."); + + - testCaseName: Test Email_DataCard2 - Default Value + testCaseDescription: Verify that the Email field displays the default value correctly. + testSteps: | + SetProperty(Email_DataCard2.Default, "DavidBenjamin@abc.com"); + Assert(Email_DataCard2.Default = "DavidBenjamin@abc.com", "Check if the Email displays 'DavidBenjamin@abc.com'."); + + - testCaseName: Test Phone_Number_DataCard2 - Default Value + testCaseDescription: Verify that the Phone Number field displays the default value correctly. + testSteps: | + SetProperty(Phone_Number_DataCard2.Default, "1112223344"); + Assert(Phone_Number_DataCard2.Default = "1112223344", "Check if the Phone Number displays '1112223344'."); + + - testCaseName: Test Save Functionality of the New Employee Form Control + testCaseDescription: Verify that the Employee data in the form saved correctly. + testSteps: | + Select(btnSubmit); + Assert(CountRows(Table1.Items) = 15, "Checking if Table displays correct number of items"); + + +testSettings: + headless: false + locale: "en-US" + recordVideo: true + extensionModules: + enable: true + browserConfigurations: + - browser: Chromium + channel: msedge + +environmentVariables: + users: + - personaName: User1 + emailKey: user1Email + passwordKey: NotNeeded diff --git a/src/Microsoft.PowerApps.TestEngine/Providers/PowerFxModel/MDATypeMapping.cs b/src/Microsoft.PowerApps.TestEngine/Providers/PowerFxModel/MDATypeMapping.cs index 27418f27..73ff6b8c 100644 --- a/src/Microsoft.PowerApps.TestEngine/Providers/PowerFxModel/MDATypeMapping.cs +++ b/src/Microsoft.PowerApps.TestEngine/Providers/PowerFxModel/MDATypeMapping.cs @@ -72,7 +72,7 @@ private bool IsTable(string typeString) private bool IsRecord(string typeString) { - return typeString.StartsWith("!"); + return typeString.StartsWith("!") || typeString.StartsWith("l"); } /// diff --git a/src/testengine.provider.mda/ModelDrivenApplicationProvider.cs b/src/testengine.provider.mda/ModelDrivenApplicationProvider.cs index d4dee61a..7c0d6a50 100644 --- a/src/testengine.provider.mda/ModelDrivenApplicationProvider.cs +++ b/src/testengine.provider.mda/ModelDrivenApplicationProvider.cs @@ -469,6 +469,8 @@ public async Task SetPropertyAsync(ItemPath itemPath, FormulaValue value) break; case (DateType): return await SetPropertyDateAsync(itemPath, (DateValue)value); + case (DateTimeType): + return await SetPropertyDateTimeAsync(itemPath, (DateTimeValue)value); case (RecordType): return await SetPropertyRecordAsync(itemPath, (RecordValue)value); case (TableType): @@ -514,6 +516,27 @@ public async Task SetPropertyDateAsync(ItemPath itemPath, DateValue value) } } + public async Task SetPropertyDateTimeAsync(ItemPath itemPath, DateTimeValue value) + { + try + { + ValidateItemPath(itemPath, false); + + var itemPathString = JsonConvert.SerializeObject(itemPath); + var propertyNameString = JsonConvert.SerializeObject(itemPath.PropertyName); + var recordValue = value.GetConvertedValue(null); + + var expression = $"PowerAppsTestEngine.setPropertyValue({itemPathString},Date.parse(\"{recordValue}\"))"; + + return await TestInfraFunctions.RunJavascriptAsync(expression); + } + catch (Exception ex) + { + ExceptionHandlingHelper.CheckIfOutDatedPublishedApp(ex, SingleTestInstanceState.GetLogger()); + throw; + } + } + public async Task SetPropertyRecordAsync(ItemPath itemPath, RecordValue value) { try diff --git a/src/testengine.provider.mda/PowerAppsTestEngineMDACustom.js b/src/testengine.provider.mda/PowerAppsTestEngineMDACustom.js index aa07faba..77ba933a 100644 --- a/src/testengine.provider.mda/PowerAppsTestEngineMDACustom.js +++ b/src/testengine.provider.mda/PowerAppsTestEngineMDACustom.js @@ -209,7 +209,13 @@ class PowerAppsModelDrivenCanvas { var control = appMagic.AuthoringTool.Runtime.getGlobalBindingContext().controlContexts[itemPath.controlName]; if (typeof control === "undefined") { - return null; + var childControlContext = PowerAppsModelDrivenCanvas.FindControlContextForChildControl(itemPath.controlName); + if (childControlContext) { + control = childControlContext; + } + else { + return null; + } } var property = control.modelProperties[itemPath.propertyName]; @@ -264,12 +270,28 @@ class PowerAppsModelDrivenCanvas { if (controlContext.modelProperties[itemPath.propertyName]) { propertyValue = controlContext.modelProperties[itemPath.propertyName]?.getValue(); - if ((typeof propertyValue !== "undefined") && (propertyValue !== null) && (typeof propertyValue.dataSource !== "undefined") && (typeof propertyValue.dataSource.data !== "undefined")) { - // TODO: Transform data to display data + if ((typeof propertyValue !== "undefined") && (propertyValue !== null) && (typeof propertyValue.dataSource !== "undefined") && (typeof propertyValue.dataSource.data !== "undefined")) { propertyValue = propertyValue.dataSource.data; } } } + else { + try { + var childControlContext = PowerAppsModelDrivenCanvas.FindControlContextForChildControl(itemPath.controlName); + if (childControlContext) { + if (childControlContext.modelProperties[itemPath.propertyName]) { + propertyValue = childControlContext.modelProperties[itemPath.propertyName]?.getValue(); + + if ((typeof propertyValue !== "undefined") && (propertyValue !== null) && (typeof propertyValue.dataSource !== "undefined") && (typeof propertyValue.dataSource.data !== "undefined")) { + propertyValue = propertyValue.dataSource.data; + } + } + } + } + catch (error) { + return console.log(error); + } + } return { propertyValue: propertyValue @@ -338,10 +360,58 @@ class PowerAppsModelDrivenCanvas { return true; } } + else { + try { + var childControlContext = PowerAppsModelDrivenCanvas.FindControlContextForChildControl(itemPath.controlName); + if (childControlContext) { + if (childControlContext.modelProperties[itemPath.propertyName]) { + propertyValue = childControlContext.modelProperties[itemPath.propertyName]?.setValue(value); + return true; + } + } + } + catch (error) { + return console.log(error); + } + } return false; } + static FindControlContextForChildControl(controlToFind) { + var appMagic = PowerAppsModelDrivenCanvas.getAppMagic(); + + var controlContext = appMagic.Controls.GlobalContextManager.bindingContext.controlContexts; + var controlNames = Object.keys(controlContext); + for (let controlName of controlNames) { + var control = controlContext[controlName]; + var bindingContext = PowerAppsModelDrivenCanvas.findControl(controlName, control, controlToFind); + if (bindingContext) { + return bindingContext; + } + } + return null; + } + + static findControl(controlName, controlObject, controlToFind) { + if (controlName === controlToFind) { + return controlObject; + } + + if (controlObject.controlWidget.replicatedContextManager) { + var childrenControlContext = controlObject.controlWidget.replicatedContextManager.authoringAreaBindingContext.controlContexts; + var childControlNames = Object.keys(childrenControlContext); + for (let childControlName of childControlNames) { + var childControlObject = childrenControlContext[childControlName]; + var foundControl = PowerAppsModelDrivenCanvas.findControl(childControlName, childControlObject, controlToFind); + if (foundControl) { + return foundControl; + } + } + } + return null; + } + static interactWithControl(itemPath, value) { var appMagic = PowerAppsModelDrivenCanvas.getAppMagic() @@ -402,7 +472,7 @@ class PowerAppsModelDrivenCanvas { }) } - + }) } return JSON.stringify(data);