[FZ Editor]Add tests to editor #197 + feedback (#29051)

* here are the tests for the fancy zones

* Wrote tests for GridLayoutModel

* Move FancyZonesEditor tests to right place, tests for default layout model

* fixed SettingTheVerticalLayoutShouldBeTheDefault test

* removed coverlet in the test project

* Fixes for comments on pr

* squashed and updated for comments

* Added the test to the pipeline

---------

Co-authored-by: Drew Gordon <andrewbengordon@gmail.com>
Co-authored-by: Caleb Wightman <agentcboy@gmail.com>
This commit is contained in:
Garrett Vernon
2023-10-18 01:07:48 -06:00
committed by GitHub
parent ec47805634
commit cd99a2e848
6 changed files with 204 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using FancyZonesEditor.Models;
namespace UnitTestsFancyZonesEditor;
[TestClass]
public class DefaultLayoutsModelTests
{
[TestMethod]
public void LayoutCapacityShouldBeNumberOfMonitorConfigurations()
{
var defaultLayoutsModel = new DefaultLayoutsModel();
var expectedOptionCount = Enum.GetValues(typeof(MonitorConfigurationType)).Length;
var actualCapacity = defaultLayoutsModel.Layouts.Capacity;
Assert.AreEqual(expectedOptionCount, actualCapacity);
}
[TestMethod]
public void OverridingLayoutClearsOldDefault()
{
var defaultLayoutsModel = new DefaultLayoutsModel();
GridLayoutModel firstLayout = new GridLayoutModel();
CanvasLayoutModel secondLayout = new CanvasLayoutModel("steve");
defaultLayoutsModel.Set(firstLayout, MonitorConfigurationType.Horizontal);
Assert.AreEqual(defaultLayoutsModel.Layouts[(int)MonitorConfigurationType.Horizontal], firstLayout);
defaultLayoutsModel.Set(secondLayout, MonitorConfigurationType.Horizontal);
Assert.AreNotEqual(defaultLayoutsModel.Layouts[(int)MonitorConfigurationType.Horizontal], firstLayout);
Assert.AreEqual(defaultLayoutsModel.Layouts[(int)MonitorConfigurationType.Horizontal], secondLayout);
}
[TestMethod]
public void SettingTheVerticalLayoutShouldBeTheDefault()
{
var defaultLayoutsModel = new DefaultLayoutsModel();
GridLayoutModel firstLayout = new GridLayoutModel();
defaultLayoutsModel.Set(firstLayout, MonitorConfigurationType.Horizontal);
defaultLayoutsModel.Set(firstLayout, MonitorConfigurationType.Vertical);
Assert.AreEqual(defaultLayoutsModel.Layouts[(int)MonitorConfigurationType.Vertical], firstLayout);
}
[TestMethod]
public void RestoringLayoutShouldSetLayouts()
{
var defaultLayoutsModel = new DefaultLayoutsModel();
GridLayoutModel firstLayout = new GridLayoutModel();
CanvasLayoutModel secondLayout = new CanvasLayoutModel("steve");
var restoredLayouts = new List<LayoutModel> { firstLayout, secondLayout };
defaultLayoutsModel.Restore(restoredLayouts);
CollectionAssert.AreEqual(defaultLayoutsModel.Layouts, restoredLayouts);
}
}

View File

@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using FancyZonesEditor.Models;
namespace UnitTestsFancyZonesEditor;
[TestClass]
public class GridLayoutModelTests
{
[TestMethod]
public void EmptyGridLayoutModelIsNotValid()
{
GridLayoutModel gridLayoutModel = new GridLayoutModel();
Assert.IsFalse(gridLayoutModel.IsModelValid());
}
[TestMethod]
public void GridLayoutModelWithInvalidRowAndColumnCountsIsNotValid()
{
GridLayoutModel gridLayoutModel = new GridLayoutModel();
gridLayoutModel.Rows = 0;
gridLayoutModel.Columns = 0;
Assert.IsFalse(gridLayoutModel.IsModelValid());
}
[TestMethod]
public void GridLayoutModelWithInvalidRowPercentsIsNotValid()
{
GridLayoutModel gridLayoutModel = new GridLayoutModel();
gridLayoutModel.Rows = 1;
gridLayoutModel.Columns = 1;
gridLayoutModel.RowPercents = new List<int> { 0 }; // Invalid percentage
Assert.IsFalse(gridLayoutModel.IsModelValid());
}
[TestMethod]
public void GridLayoutModelWithInvalidColumnPercentsIsNotValid()
{
GridLayoutModel gridLayoutModel = new GridLayoutModel();
gridLayoutModel.Rows = 1;
gridLayoutModel.Columns = 1;
gridLayoutModel.ColumnPercents = new List<int> { 0 }; // Invalid percentage
Assert.IsFalse(gridLayoutModel.IsModelValid());
}
[TestMethod]
public void GridLayoutModelWithInvalidCellChildMapLengthIsNotValid()
{
GridLayoutModel gridLayoutModel = new GridLayoutModel();
gridLayoutModel.Rows = 2;
gridLayoutModel.Columns = 2;
gridLayoutModel.CellChildMap = new int[2, 1]; // Invalid length
Assert.IsFalse(gridLayoutModel.IsModelValid());
}
[TestMethod]
public void GridLayoutModelWithInvalidZoneCountIsNotValid()
{
GridLayoutModel gridLayoutModel = new GridLayoutModel();
gridLayoutModel.Rows = 2;
gridLayoutModel.Columns = 2;
gridLayoutModel.CellChildMap = new int[,]
{
{ 1, 2 },
{ 3, 4 },
}; // Invalid zone count
Assert.IsFalse(gridLayoutModel.IsModelValid());
}
[TestMethod]
public void GridLayoutModelWithValidPropertiesIsValid()
{
GridLayoutModel gridLayoutModel = new GridLayoutModel();
// Set valid row and column counts
gridLayoutModel.Rows = 2;
gridLayoutModel.Columns = 2;
// Set valid percentages for rows and columns
// Should add up to 10000
gridLayoutModel.RowPercents = new List<int> { 5000, 5000 };
gridLayoutModel.ColumnPercents = new List<int> { 5000, 5000 };
// Set a valid CellChildMap
gridLayoutModel.CellChildMap = new int[,]
{
{ 0, 1 },
{ 2, 3 },
}; // corresponds to 4 zones
Assert.IsTrue(gridLayoutModel.IsModelValid(), "GridLayoutModel with valid properties should be valid.");
}
}

View File

@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows10.0.20348.0</TargetFramework>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\tests\UnitTest-FancyZonesEditor\</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="System.IO.Abstractions" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\editor\FancyZonesEditor\FancyZonesEditor.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
global using Microsoft.VisualStudio.TestTools.UnitTesting;