< Summary

Class:SettingsWidgetTests.SettingsWidgetShould_PlayMode
Assembly:SettingsPanelHUDTests_PlayMode
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Tests/PlayMode/SettingsWidgetTests_PlayMode.cs
Covered lines:24
Uncovered lines:0
Coverable lines:24
Total lines:81
Line coverage:100% (24 of 24)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SettingsWidgetShould_PlayMode()0%110100%
SetUp()0%440100%
TearDown()0%330100%
GenerateControlsIntoAWidgetViewCorrectly()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Tests/PlayMode/SettingsWidgetTests_PlayMode.cs

#LineLine coverage
 1using DCL.SettingsControls;
 2using DCL.SettingsPanelHUD.Controls;
 3using DCL.SettingsPanelHUD.Widgets;
 4using NSubstitute;
 5using NUnit.Framework;
 6using System.Collections;
 7using System.Collections.Generic;
 8using UnityEngine;
 9using UnityEngine.TestTools;
 10
 11namespace SettingsWidgetTests
 12{
 13    public class SettingsWidgetShould_PlayMode
 14    {
 15        private const int NUMBER_OF_COLUMNS = 2;
 16        private const string WIDGET_VIEW_PREFAB_PATH = "Widgets/DefaultSettingsWidgetTemplate";
 17        private const string CONTROL_VIEW_PREFAB_PATH = "Controls/{controlType}SettingsControlTemplate";
 18
 19        private SettingsWidgetView widgetView;
 20        private ISettingsWidgetController widgetController;
 121        private List<SettingsControlGroup> controlColumnsToCreate = new List<SettingsControlGroup>();
 22
 23        [UnitySetUp]
 24        private IEnumerator SetUp()
 25        {
 1826            for (int i = 0; i < NUMBER_OF_COLUMNS; i++)
 27            {
 628                controlColumnsToCreate.Add(new SettingsControlGroup()
 29                {
 30                    controls = new SettingsControlList()
 31                });
 32            }
 33
 334            widgetView = Object.Instantiate((GameObject)Resources.Load(WIDGET_VIEW_PREFAB_PATH)).GetComponent<SettingsWi
 335            widgetController = Substitute.For<ISettingsWidgetController>();
 36
 337            yield return null;
 338        }
 39
 40        [UnityTearDown]
 41        private IEnumerator TearDown()
 42        {
 343            Object.Destroy(widgetView.gameObject);
 344            controlColumnsToCreate.Clear();
 45
 346            yield return null;
 347        }
 48
 49        [UnityTest]
 50        [TestCase(0, "Slider", ExpectedResult = null)]
 51        [TestCase(1, "SpinBox", ExpectedResult = null)]
 52        [TestCase(0, "Toggle", ExpectedResult = null)]
 53        public IEnumerator GenerateControlsIntoAWidgetViewCorrectly(int columnIndex, string controlType)
 54        {
 55            // Arrange
 356            SettingsControlView controlViewPrefab = ((GameObject)Resources.Load(CONTROL_VIEW_PREFAB_PATH.Replace("{contr
 57
 358            SettingsControlModel newControlConfig = ScriptableObject.CreateInstance<SettingsControlModel>();
 359            newControlConfig.title = $"TestControl_Col{columnIndex}";
 360            newControlConfig.controlPrefab = controlViewPrefab;
 361            newControlConfig.controlController = ScriptableObject.CreateInstance<SettingsControlController>();
 362            newControlConfig.flagsThatDeactivateMe = new List<BooleanVariable>();
 363            newControlConfig.flagsThatDisableMe = new List<BooleanVariable>();
 364            newControlConfig.isBeta = false;
 65
 66
 367            controlColumnsToCreate[columnIndex].controls.Add(newControlConfig);
 68
 69            // Act
 370            widgetView.Initialize("TestWidget", widgetController, controlColumnsToCreate);
 371            yield return null;
 72
 73            // Assert
 374            widgetController.Received(1)
 75                            .AddControl(
 76                                Arg.Any<ISettingsControlView>(),
 77                                Arg.Any<SettingsControlController>(),
 78                                Arg.Any<SettingsControlModel>());
 379        }
 80    }
 81}