< Summary

Class:Tests.BuilderProjectsPanelControllerShould
Assembly:BuilderProjectsPanelTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Tests/BuilderProjectsPanelControllerShould.cs
Covered lines:82
Uncovered lines:0
Coverable lines:82
Total lines:174
Line coverage:100% (82 of 82)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
TearDown()0%110100%
ViewCreatedCorrectly()0%110100%
ViewVisibleCorrectly()0%110100%
ViewHideCorrectly()0%110100%
ViewHideCorrectlyOnClosePressed()0%110100%
ViewHideAndShowCorrectlyOnEvent()0%110100%
AddScenesListenerOnSectionShow()0%110100%
RemoveScenesListenerOnSectionHide()0%110100%
CallOpenSectionWhenSceneSelected()0%110100%
HandleLeftMenuCorrectly()0%110100%
SetSettingsLeftMenuCorrectly()0%110100%
SceneContextMenuHidesCorrectly()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Tests/BuilderProjectsPanelControllerShould.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL;
 4using DCL.Helpers;
 5using NSubstitute;
 6using NUnit.Framework;
 7using UnityEngine;
 8
 9namespace Tests
 10{
 11    public class BuilderProjectsPanelControllerShould
 12    {
 13        private BuilderProjectsPanelController controller;
 14        private ISectionsController sectionsController;
 15        private IScenesViewController scenesViewController;
 16        private ILandController landsController;
 17
 18        [SetUp]
 19        public void SetUp()
 20        {
 1121            controller = new BuilderProjectsPanelController();
 22
 1123            sectionsController = Substitute.For<ISectionsController>();
 1124            scenesViewController = Substitute.For<IScenesViewController>();
 1125            landsController = Substitute.For<ILandController>();
 26
 1127            ITheGraph theGraph = Substitute.For<ITheGraph>();
 1128            theGraph.Query(Arg.Any<string>(), Arg.Any<string>()).Returns(new Promise<string>());
 1129            theGraph.Query(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<QueryVariablesBase>()).Returns(new Promise<stri
 1130            theGraph.QueryLands(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<float>()).Returns(new Promise<List<Land>>(
 31
 1132            ICatalyst catalyst = Substitute.For<ICatalyst>();
 1133            catalyst.contentUrl.Returns(string.Empty);
 1134            catalyst.Get(Arg.Any<string>()).Returns(new Promise<string>());
 1135            catalyst.GetEntities(Arg.Any<string>(), Arg.Any<string[]>()).Returns(new Promise<string>());
 1136            catalyst.GetDeployedScenes(Arg.Any<string[]>()).Returns(new Promise<CatalystSceneEntityPayload[]>());
 37
 1138            controller.Initialize(sectionsController, scenesViewController,
 39                landsController, theGraph, catalyst);
 1140        }
 41
 42        [TearDown]
 2243        public void TearDown() { controller.Dispose(); }
 44
 45        [Test]
 246        public void ViewCreatedCorrectly() { Assert.IsNotNull(controller.view); }
 47
 48        [Test]
 49        public void ViewVisibleCorrectly()
 50        {
 151            BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view;
 152            Assert.IsFalse(view.gameObject.activeSelf);
 53
 154            controller.SetVisibility(true);
 155            Assert.IsTrue(view.gameObject.activeSelf);
 156        }
 57
 58        [Test]
 59        public void ViewHideCorrectly()
 60        {
 161            BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view;
 62
 163            controller.SetVisibility(true);
 164            Assert.IsTrue(view.gameObject.activeSelf);
 65
 166            controller.SetVisibility(false);
 167            Assert.IsFalse(view.showHideAnimator.isVisible);
 168        }
 69
 70        [Test]
 71        public void ViewHideCorrectlyOnClosePressed()
 72        {
 173            BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view;
 74
 175            controller.SetVisibility(true);
 176            Assert.IsTrue(view.gameObject.activeSelf);
 77
 178            view.closeButton.onClick.Invoke();
 179            Assert.IsFalse(view.showHideAnimator.isVisible);
 180        }
 81
 82        [Test]
 83        public void ViewHideAndShowCorrectlyOnEvent()
 84        {
 185            BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view;
 86
 187            DataStore.i.HUDs.builderProjectsPanelVisible.Set(true);
 188            Assert.IsTrue(view.showHideAnimator.isVisible);
 89
 190            DataStore.i.HUDs.builderProjectsPanelVisible.Set(false);
 191            Assert.IsFalse(view.showHideAnimator.isVisible);
 192        }
 93
 94        [Test]
 95        public void AddScenesListenerOnSectionShow()
 96        {
 197            var section = Substitute.For<SectionDeployedScenesController>();
 198            sectionsController.OnSectionShow += Raise.Event<Action<SectionBase>>(section);
 199            scenesViewController.Received(1).AddListener(section);
 1100        }
 101
 102        [Test]
 103        public void RemoveScenesListenerOnSectionHide()
 104        {
 1105            var section = Substitute.For<SectionDeployedScenesController>();
 1106            sectionsController.OnSectionHide += Raise.Event<Action<SectionBase>>(section);
 1107            scenesViewController.Received(1).RemoveListener(section);
 1108        }
 109
 110        [Test]
 111        public void CallOpenSectionWhenSceneSelected()
 112        {
 1113            var cardView = UnityEngine.Object.Instantiate(controller.view.GetCardViewPrefab());
 1114            ((ISceneCardView)cardView).Setup(new SceneData());
 1115            scenesViewController.OnSceneSelected += Raise.Event<Action<ISceneCardView>>(cardView);
 1116            sectionsController.Received(1).OpenSection(Arg.Any<SectionId>());
 1117            UnityEngine.Object.DestroyImmediate(cardView.gameObject);
 1118        }
 119
 120        [Test]
 121        public void HandleLeftMenuCorrectly()
 122        {
 1123            BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view;
 124
 1125            sectionsController.OnOpenSectionId += Raise.Event<Action<SectionId>>(SectionId.SCENES_DEPLOYED);
 1126            Assert.IsTrue(view.leftPanelMain.activeSelf);
 1127            Assert.IsFalse(view.leftPanelProjectSettings.activeSelf);
 128
 1129            sectionsController.OnOpenSectionId += Raise.Event<Action<SectionId>>(SectionId.SETTINGS_PROJECT_GENERAL);
 1130            Assert.IsTrue(view.leftPanelProjectSettings.activeSelf);
 1131            Assert.IsFalse(view.leftPanelMain.activeSelf);
 132
 1133            view.backToMainPanelButton.onClick.Invoke();
 1134            sectionsController.Received(1).OpenSection(SectionId.SCENES_DEPLOYED);
 1135        }
 136
 137        [Test]
 138        public void SetSettingsLeftMenuCorrectly()
 139        {
 1140            Vector2Int coords = new Vector2Int(0, 1);
 141            const string author = "Temptation Creator";
 142
 1143            var cardView = UnityEngine.Object.Instantiate(controller.view.GetCardViewPrefab());
 1144            ((ISceneCardView)cardView).Setup(new SceneData()
 145            {
 146                isDeployed = true,
 147                coords = coords,
 148                authorName = author
 149            });
 1150            scenesViewController.OnSceneSelected += Raise.Event<Action<ISceneCardView>>(cardView);
 151
 1152            LeftMenuSettingsViewReferences viewReferences = controller.view.GetSettingsViewReferences();
 153
 1154            Assert.AreEqual(LeftMenuSettingsViewHandler.SCENE_TITLE, viewReferences.titleLabel.text);
 1155            Assert.IsTrue(viewReferences.coordsContainer.activeSelf);
 1156            Assert.IsFalse(viewReferences.sizeContainer.activeSelf);
 1157            Assert.AreEqual($"{coords.x},{coords.y}", viewReferences.coordsText.text);
 1158            Assert.AreEqual(author, viewReferences.authorNameText.text);
 1159            Assert.IsTrue(viewReferences.adminsMenuToggle.gameObject.activeSelf);
 160
 1161            UnityEngine.Object.DestroyImmediate(cardView.gameObject);
 1162        }
 163
 164        [Test]
 165        public void SceneContextMenuHidesCorrectly()
 166        {
 1167            var contextMenu = controller.view.GetSceneCardViewContextMenu();
 1168            contextMenu.gameObject.SetActive(true);
 169
 1170            sectionsController.OnRequestContextMenuHide += Raise.Event<Action>();
 1171            Assert.IsFalse(contextMenu.gameObject.activeSelf);
 1172        }
 173    }
 174}