| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using NSubstitute; |
| | 6 | | using NUnit.Framework; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace 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 | | { |
| 11 | 21 | | controller = new BuilderProjectsPanelController(); |
| | 22 | |
|
| 11 | 23 | | sectionsController = Substitute.For<ISectionsController>(); |
| 11 | 24 | | scenesViewController = Substitute.For<IScenesViewController>(); |
| 11 | 25 | | landsController = Substitute.For<ILandController>(); |
| | 26 | |
|
| 11 | 27 | | ITheGraph theGraph = Substitute.For<ITheGraph>(); |
| 11 | 28 | | theGraph.Query(Arg.Any<string>(), Arg.Any<string>()).Returns(new Promise<string>()); |
| 11 | 29 | | theGraph.Query(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<QueryVariablesBase>()).Returns(new Promise<stri |
| 11 | 30 | | theGraph.QueryLands(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<float>()).Returns(new Promise<List<Land>>( |
| | 31 | |
|
| 11 | 32 | | ICatalyst catalyst = Substitute.For<ICatalyst>(); |
| 11 | 33 | | catalyst.contentUrl.Returns(string.Empty); |
| 11 | 34 | | catalyst.Get(Arg.Any<string>()).Returns(new Promise<string>()); |
| 11 | 35 | | catalyst.GetEntities(Arg.Any<string>(), Arg.Any<string[]>()).Returns(new Promise<string>()); |
| 11 | 36 | | catalyst.GetDeployedScenes(Arg.Any<string[]>()).Returns(new Promise<CatalystSceneEntityPayload[]>()); |
| | 37 | |
|
| 11 | 38 | | controller.Initialize(sectionsController, scenesViewController, |
| | 39 | | landsController, theGraph, catalyst); |
| 11 | 40 | | } |
| | 41 | |
|
| | 42 | | [TearDown] |
| 22 | 43 | | public void TearDown() { controller.Dispose(); } |
| | 44 | |
|
| | 45 | | [Test] |
| 2 | 46 | | public void ViewCreatedCorrectly() { Assert.IsNotNull(controller.view); } |
| | 47 | |
|
| | 48 | | [Test] |
| | 49 | | public void ViewVisibleCorrectly() |
| | 50 | | { |
| 1 | 51 | | BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view; |
| 1 | 52 | | Assert.IsFalse(view.gameObject.activeSelf); |
| | 53 | |
|
| 1 | 54 | | controller.SetVisibility(true); |
| 1 | 55 | | Assert.IsTrue(view.gameObject.activeSelf); |
| 1 | 56 | | } |
| | 57 | |
|
| | 58 | | [Test] |
| | 59 | | public void ViewHideCorrectly() |
| | 60 | | { |
| 1 | 61 | | BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view; |
| | 62 | |
|
| 1 | 63 | | controller.SetVisibility(true); |
| 1 | 64 | | Assert.IsTrue(view.gameObject.activeSelf); |
| | 65 | |
|
| 1 | 66 | | controller.SetVisibility(false); |
| 1 | 67 | | Assert.IsFalse(view.showHideAnimator.isVisible); |
| 1 | 68 | | } |
| | 69 | |
|
| | 70 | | [Test] |
| | 71 | | public void ViewHideCorrectlyOnClosePressed() |
| | 72 | | { |
| 1 | 73 | | BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view; |
| | 74 | |
|
| 1 | 75 | | controller.SetVisibility(true); |
| 1 | 76 | | Assert.IsTrue(view.gameObject.activeSelf); |
| | 77 | |
|
| 1 | 78 | | view.closeButton.onClick.Invoke(); |
| 1 | 79 | | Assert.IsFalse(view.showHideAnimator.isVisible); |
| 1 | 80 | | } |
| | 81 | |
|
| | 82 | | [Test] |
| | 83 | | public void ViewHideAndShowCorrectlyOnEvent() |
| | 84 | | { |
| 1 | 85 | | BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view; |
| | 86 | |
|
| 1 | 87 | | DataStore.i.HUDs.builderProjectsPanelVisible.Set(true); |
| 1 | 88 | | Assert.IsTrue(view.showHideAnimator.isVisible); |
| | 89 | |
|
| 1 | 90 | | DataStore.i.HUDs.builderProjectsPanelVisible.Set(false); |
| 1 | 91 | | Assert.IsFalse(view.showHideAnimator.isVisible); |
| 1 | 92 | | } |
| | 93 | |
|
| | 94 | | [Test] |
| | 95 | | public void AddScenesListenerOnSectionShow() |
| | 96 | | { |
| 1 | 97 | | var section = Substitute.For<SectionDeployedScenesController>(); |
| 1 | 98 | | sectionsController.OnSectionShow += Raise.Event<Action<SectionBase>>(section); |
| 1 | 99 | | scenesViewController.Received(1).AddListener(section); |
| 1 | 100 | | } |
| | 101 | |
|
| | 102 | | [Test] |
| | 103 | | public void RemoveScenesListenerOnSectionHide() |
| | 104 | | { |
| 1 | 105 | | var section = Substitute.For<SectionDeployedScenesController>(); |
| 1 | 106 | | sectionsController.OnSectionHide += Raise.Event<Action<SectionBase>>(section); |
| 1 | 107 | | scenesViewController.Received(1).RemoveListener(section); |
| 1 | 108 | | } |
| | 109 | |
|
| | 110 | | [Test] |
| | 111 | | public void CallOpenSectionWhenSceneSelected() |
| | 112 | | { |
| 1 | 113 | | var cardView = UnityEngine.Object.Instantiate(controller.view.GetCardViewPrefab()); |
| 1 | 114 | | ((ISceneCardView)cardView).Setup(new SceneData()); |
| 1 | 115 | | scenesViewController.OnSceneSelected += Raise.Event<Action<ISceneCardView>>(cardView); |
| 1 | 116 | | sectionsController.Received(1).OpenSection(Arg.Any<SectionId>()); |
| 1 | 117 | | UnityEngine.Object.DestroyImmediate(cardView.gameObject); |
| 1 | 118 | | } |
| | 119 | |
|
| | 120 | | [Test] |
| | 121 | | public void HandleLeftMenuCorrectly() |
| | 122 | | { |
| 1 | 123 | | BuilderProjectsPanelView view = (BuilderProjectsPanelView)controller.view; |
| | 124 | |
|
| 1 | 125 | | sectionsController.OnOpenSectionId += Raise.Event<Action<SectionId>>(SectionId.SCENES_DEPLOYED); |
| 1 | 126 | | Assert.IsTrue(view.leftPanelMain.activeSelf); |
| 1 | 127 | | Assert.IsFalse(view.leftPanelProjectSettings.activeSelf); |
| | 128 | |
|
| 1 | 129 | | sectionsController.OnOpenSectionId += Raise.Event<Action<SectionId>>(SectionId.SETTINGS_PROJECT_GENERAL); |
| 1 | 130 | | Assert.IsTrue(view.leftPanelProjectSettings.activeSelf); |
| 1 | 131 | | Assert.IsFalse(view.leftPanelMain.activeSelf); |
| | 132 | |
|
| 1 | 133 | | view.backToMainPanelButton.onClick.Invoke(); |
| 1 | 134 | | sectionsController.Received(1).OpenSection(SectionId.SCENES_DEPLOYED); |
| 1 | 135 | | } |
| | 136 | |
|
| | 137 | | [Test] |
| | 138 | | public void SetSettingsLeftMenuCorrectly() |
| | 139 | | { |
| 1 | 140 | | Vector2Int coords = new Vector2Int(0, 1); |
| | 141 | | const string author = "Temptation Creator"; |
| | 142 | |
|
| 1 | 143 | | var cardView = UnityEngine.Object.Instantiate(controller.view.GetCardViewPrefab()); |
| 1 | 144 | | ((ISceneCardView)cardView).Setup(new SceneData() |
| | 145 | | { |
| | 146 | | isDeployed = true, |
| | 147 | | coords = coords, |
| | 148 | | authorName = author |
| | 149 | | }); |
| 1 | 150 | | scenesViewController.OnSceneSelected += Raise.Event<Action<ISceneCardView>>(cardView); |
| | 151 | |
|
| 1 | 152 | | LeftMenuSettingsViewReferences viewReferences = controller.view.GetSettingsViewReferences(); |
| | 153 | |
|
| 1 | 154 | | Assert.AreEqual(LeftMenuSettingsViewHandler.SCENE_TITLE, viewReferences.titleLabel.text); |
| 1 | 155 | | Assert.IsTrue(viewReferences.coordsContainer.activeSelf); |
| 1 | 156 | | Assert.IsFalse(viewReferences.sizeContainer.activeSelf); |
| 1 | 157 | | Assert.AreEqual($"{coords.x},{coords.y}", viewReferences.coordsText.text); |
| 1 | 158 | | Assert.AreEqual(author, viewReferences.authorNameText.text); |
| 1 | 159 | | Assert.IsTrue(viewReferences.adminsMenuToggle.gameObject.activeSelf); |
| | 160 | |
|
| 1 | 161 | | UnityEngine.Object.DestroyImmediate(cardView.gameObject); |
| 1 | 162 | | } |
| | 163 | |
|
| | 164 | | [Test] |
| | 165 | | public void SceneContextMenuHidesCorrectly() |
| | 166 | | { |
| 1 | 167 | | var contextMenu = controller.view.GetSceneCardViewContextMenu(); |
| 1 | 168 | | contextMenu.gameObject.SetActive(true); |
| | 169 | |
|
| 1 | 170 | | sectionsController.OnRequestContextMenuHide += Raise.Event<Action>(); |
| 1 | 171 | | Assert.IsFalse(contextMenu.gameObject.activeSelf); |
| 1 | 172 | | } |
| | 173 | | } |
| | 174 | | } |