Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant-Archibald-MS committed Oct 21, 2024
1 parent 6cab5c1 commit 0b4fedf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Text.Json;
using Microsoft.Extensions.Logging;
using Microsoft.Playwright;
using Microsoft.PowerApps.TestEngine.Config;
using Microsoft.PowerApps.TestEngine.Providers;
using Microsoft.PowerApps.TestEngine.System;
using Microsoft.PowerApps.TestEngine.TestInfra;
using Microsoft.PowerFx;
using Microsoft.PowerFx.Types;
using Moq;
using testengine.module.powerapps.portal;

namespace testengine.module.powerappsportal.tests
{
public class SelectSectionFunctionTests
{
private Mock<ITestInfraFunctions> MockTestInfraFunctions;
private Mock<ITestState> MockTestState;
private Mock<ISingleTestInstanceState> MockSingleTestInstanceState;
private Mock<IPage> MockPage;
private Mock<ILogger> MockLogger;
private Mock<IBrowserContext> MockBrowserContext;

public SelectSectionFunctionTests()
{
MockTestInfraFunctions = new Mock<ITestInfraFunctions>(MockBehavior.Strict);
MockTestState = new Mock<ITestState>(MockBehavior.Strict);
MockSingleTestInstanceState = new Mock<ISingleTestInstanceState>(MockBehavior.Strict);
MockPage = new Mock<IPage>(MockBehavior.Strict);
MockLogger = new Mock<ILogger>();
MockBrowserContext = new Mock<IBrowserContext>(MockBehavior.Strict);
}

[Fact]
public void SectionFound()
{
// Arrange
MockTestInfraFunctions.Setup(x => x.GetContext()).Returns(MockBrowserContext.Object);
MockBrowserContext.SetupGet(x => x.Pages).Returns(new List<IPage>() { MockPage.Object });
MockPage.Setup(x => x.Url).Returns("https://make.powerapps.com/environments/a1234567-1111-2222-4444-555566667777/home");
MockPage.Setup(x => x.WaitForSelectorAsync("[data-test-id='solutions']:visible", It.IsAny<PageWaitForSelectorOptions>())).ReturnsAsync(new Mock<IElementHandle>().Object);
MockPage.Setup(x => x.ClickAsync("[data-test-id='solutions']", null)).Returns(Task.CompletedTask);

var function = new SelectSectionFunction(MockTestInfraFunctions.Object, MockTestState.Object, MockLogger.Object);

// Act
function.Execute(FormulaValue.New("solutions"));

// Assert
}

}
}
11 changes: 6 additions & 5 deletions src/testengine.module.powerapps.portal/SelectSection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Linq;
Expand Down Expand Up @@ -45,13 +45,14 @@ private async Task ExecuteAsync(StringValue section)
{
foreach (var page in _testInfraFunctions.GetContext().Pages) {
var url = page.Url;
var name = section.Value.ToString();
var sectionName = section.Value.ToString();

// TODO: Handle case section is not visible. If not visible then add steps to add item
// TODO: Handle case section is not visible in the left navigation. If not consider adding steps to make visible from extra options in the portal
if (url.Contains("powerapps.com") && url.Contains("/environments") && url.Contains("/home")) {
await page.WaitForSelectorAsync($"[data-test-id='{name}']:visible");
var selector = $"[data-test-id='{sectionName}']";
await page.WaitForSelectorAsync($"{selector}:visible");

await page.Locator(selector).ClickAsync();
await page.ClickAsync(selector);
}
}
}
Expand Down

0 comments on commit 0b4fedf

Please sign in to comment.