-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Experimental.SelectControl() for MDA custom pages
- Loading branch information
1 parent
be09349
commit 07270dc
Showing
6 changed files
with
150 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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,54 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Playwright; | ||
using Microsoft.PowerApps.TestEngine.Config; | ||
using Microsoft.PowerApps.TestEngine.Providers; | ||
using Microsoft.PowerApps.TestEngine.Providers.PowerFxModel; | ||
using Microsoft.PowerApps.TestEngine.TestInfra; | ||
using Microsoft.PowerFx.Types; | ||
using Moq; | ||
|
||
namespace testengine.module | ||
{ | ||
public class SelectControlFunctionTests | ||
{ | ||
private Mock<ITestInfraFunctions> MockTestInfraFunctions; | ||
private Mock<ITestState> MockTestState; | ||
private Mock<IPage> MockPage; | ||
private Mock<ITestWebProvider> MockTestWebProvider; | ||
private Mock<ILogger> MockLogger; | ||
private Mock<ILocator> MockLocator; | ||
|
||
public SelectControlFunctionTests() | ||
{ | ||
MockTestInfraFunctions = new Mock<ITestInfraFunctions>(MockBehavior.Strict); | ||
MockTestState = new Mock<ITestState>(MockBehavior.Strict); | ||
MockPage = new Mock<IPage>(MockBehavior.Strict); | ||
MockTestWebProvider = new Mock<ITestWebProvider>(MockBehavior.Strict); | ||
MockLogger = new Mock<ILogger>(); | ||
MockLocator = new Mock<ILocator>(); | ||
} | ||
|
||
[Fact] | ||
public async Task HappyPathMatchIsFound() | ||
{ | ||
// Arrange | ||
var function = new SelectControlFunction(MockTestInfraFunctions.Object, MockTestState.Object, MockLogger.Object); | ||
|
||
MockTestInfraFunctions.SetupGet(x => x.Page).Returns(MockPage.Object); | ||
MockPage.Setup(x => x.Locator("[data-control-name='Button1']", null)).Returns(MockLocator.Object); | ||
|
||
MockLocator.Setup(x => x.Nth(0)).Returns(MockLocator.Object); | ||
|
||
MockLocator.Setup(x => x.ClickAsync(null)).Returns(Task.CompletedTask); | ||
|
||
var recordType = RecordType.Empty().Add("Text", FormulaType.String); | ||
var recordValue = new ControlRecordValue(recordType, MockTestWebProvider.Object, "Button1"); | ||
|
||
// Act & Assert | ||
function.Execute(recordValue, NumberValue.New((float)1.0)); | ||
} | ||
} | ||
} |
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
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,72 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Playwright; | ||
using Microsoft.PowerApps.TestEngine.Config; | ||
using Microsoft.PowerApps.TestEngine.Providers; | ||
using Microsoft.PowerApps.TestEngine.Providers.PowerFxModel; | ||
using Microsoft.PowerApps.TestEngine.TestInfra; | ||
using Microsoft.PowerFx; | ||
using Microsoft.PowerFx.Core.Utils; | ||
using Microsoft.PowerFx.Types; | ||
|
||
namespace testengine.module | ||
{ | ||
/// <summary> | ||
/// This will check the custom pages of a model driven app looking for a consent dialog | ||
/// </summary> | ||
public class SelectControlFunction : ReflectionFunction | ||
{ | ||
private readonly ITestInfraFunctions _testInfraFunctions; | ||
private readonly ITestState _testState; | ||
private readonly ILogger _logger; | ||
|
||
private static TableType SearchType = TableType.Empty() | ||
.Add(new NamedFormulaType("Text", FormulaType.String, displayName: "Text")); | ||
|
||
public SelectControlFunction(ITestInfraFunctions testInfraFunctions, ITestState testState, ILogger logger) | ||
: base(DPath.Root.Append(new DName("Experimental")), "SelectControl", FormulaType.Blank, RecordType.Empty(), FormulaType.Number) | ||
{ | ||
_testInfraFunctions = testInfraFunctions; | ||
_testState = testState; | ||
_logger = logger; | ||
} | ||
|
||
public BlankValue Execute(RecordValue control, NumberValue index) | ||
{ | ||
_logger.LogInformation("------------------------------\n\n" + | ||
"Executing Experimental.SelectControl() function."); | ||
|
||
ExecuteAsync(control, index).Wait(); | ||
|
||
return FormulaValue.NewBlank(); | ||
} | ||
|
||
private async Task ExecuteAsync(RecordValue obj, NumberValue index) | ||
{ | ||
_logger.LogInformation("------------------------------\n\n" + | ||
"Executing Select function."); | ||
|
||
if (obj == null) | ||
{ | ||
_logger.LogError($"Object cannot be null."); | ||
throw new ArgumentException(); | ||
} | ||
|
||
var powerAppControlModel = (ControlRecordValue)obj; | ||
|
||
var itemPath = powerAppControlModel.GetItemPath(); | ||
itemPath.Index = (int)index.Value; | ||
|
||
// Experimental support allow selection control using data-control-name DOM element | ||
var match = _testInfraFunctions.Page.Locator($"[data-control-name='{powerAppControlModel.Name}']").Nth((int)index.Value - 1); | ||
|
||
await match.ClickAsync(); | ||
|
||
_logger.LogInformation("Successfully finished executing SelectControl function."); | ||
} | ||
} | ||
} | ||
|