| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using System.Collections; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.TestTools; |
| | 7 | | using DCL; |
| | 8 | | using System.Linq; |
| | 9 | | using NSubstitute; |
| | 10 | | using NUnit.Framework; |
| | 11 | |
|
| | 12 | | public class BlockerHandlerCan |
| | 13 | | { |
| | 14 | | private IBlockerInstanceHandler blockerInstanceHandler; |
| | 15 | | private IBlockerAnimationHandler blockerAnimationHandler; |
| | 16 | | private ISceneHandler sceneHandler; |
| | 17 | | private GameObject blockersParent; |
| | 18 | |
|
| | 19 | | [SetUp] |
| | 20 | | protected void SetUp() |
| | 21 | | { |
| 6 | 22 | | RenderProfileManifest.i.Initialize(); |
| | 23 | |
|
| 6 | 24 | | sceneHandler = Substitute.For<ISceneHandler>(); |
| | 25 | |
|
| 6 | 26 | | var allLoadedParcelCoords = new HashSet<Vector2Int>(); |
| 6 | 27 | | allLoadedParcelCoords.Add(new Vector2Int(0, 0)); |
| 6 | 28 | | allLoadedParcelCoords.Add(new Vector2Int(-1, 0)); |
| 6 | 29 | | allLoadedParcelCoords.Add(new Vector2Int(-1, 1)); |
| | 30 | |
|
| 6 | 31 | | sceneHandler.GetAllLoadedScenesCoords().Returns(allLoadedParcelCoords); |
| | 32 | |
|
| 6 | 33 | | blockerAnimationHandler = Substitute.For<IBlockerAnimationHandler>(); |
| | 34 | |
|
| | 35 | | //NOTE(Brian): Call OnFinish() when blockerAnimationHandler.FadeOut is called. |
| 6 | 36 | | blockerAnimationHandler.FadeOut(Arg.Any<GameObject>(), Arg.Invoke()); |
| | 37 | |
|
| 6 | 38 | | var newBlockerInstanceHandler = new BlockerInstanceHandler(); |
| 6 | 39 | | newBlockerInstanceHandler.Initialize(blockerAnimationHandler, null); |
| | 40 | |
|
| 6 | 41 | | blockerInstanceHandler = newBlockerInstanceHandler; |
| 6 | 42 | | blockersParent = new GameObject(); |
| | 43 | |
|
| 6 | 44 | | blockerInstanceHandler.SetParent(blockersParent.transform); |
| 6 | 45 | | } |
| | 46 | |
|
| | 47 | | [TearDown] |
| 12 | 48 | | protected void TearDown() { Object.Destroy(blockersParent); } |
| | 49 | |
|
| | 50 | | [Test] |
| | 51 | | public void ShowBlocker() |
| | 52 | | { |
| 1 | 53 | | blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0)); |
| 1 | 54 | | blockerAnimationHandler.ReceivedWithAnyArgs(1).FadeIn(default); |
| 1 | 55 | | Assert.AreEqual(1, blockerInstanceHandler.GetBlockers().Count); |
| 1 | 56 | | } |
| | 57 | |
|
| | 58 | | [Test] |
| | 59 | | public void HideBlocker() |
| | 60 | | { |
| 1 | 61 | | blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true); |
| 1 | 62 | | blockerInstanceHandler.HideBlocker(new Vector2Int(0, 0), false); |
| 1 | 63 | | blockerAnimationHandler.ReceivedWithAnyArgs(1).FadeOut(default, default); |
| 1 | 64 | | Assert.AreEqual(0, blockerInstanceHandler.GetBlockers().Count); |
| 1 | 65 | | } |
| | 66 | |
|
| | 67 | | [Test] |
| | 68 | | public void ShowBlockerInstantly() |
| | 69 | | { |
| 1 | 70 | | blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true); |
| 1 | 71 | | blockerAnimationHandler.DidNotReceiveWithAnyArgs().FadeIn(default); |
| 1 | 72 | | Assert.AreEqual(1, blockerInstanceHandler.GetBlockers().Count); |
| 1 | 73 | | } |
| | 74 | |
|
| | 75 | | [Test] |
| | 76 | | public void HideBlockerInstantly() |
| | 77 | | { |
| 1 | 78 | | blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true); |
| 1 | 79 | | blockerInstanceHandler.HideBlocker(new Vector2Int(0, 0), true); |
| 1 | 80 | | blockerAnimationHandler.DidNotReceiveWithAnyArgs().FadeOut(default, default); |
| 1 | 81 | | Assert.AreEqual(0, blockerInstanceHandler.GetBlockers().Count); |
| 1 | 82 | | } |
| | 83 | |
|
| | 84 | | [Test] |
| | 85 | | public void SetParent() |
| | 86 | | { |
| | 87 | | // Arrange |
| 1 | 88 | | GameObject testParent = new GameObject(); |
| 1 | 89 | | blockerInstanceHandler.SetParent(testParent.transform); |
| 1 | 90 | | blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true); |
| | 91 | |
|
| | 92 | | // Act |
| 1 | 93 | | var blocker = blockerInstanceHandler.GetBlockers().First().Value.gameObject; |
| | 94 | |
|
| | 95 | | // Assert |
| 1 | 96 | | Assert.IsTrue(blocker.transform.parent == testParent.transform); |
| | 97 | |
|
| | 98 | | // Dispose |
| 1 | 99 | | Object.Destroy(testParent); |
| 1 | 100 | | } |
| | 101 | |
|
| | 102 | | [Test] |
| | 103 | | public void DestroyAllBlockers() |
| | 104 | | { |
| | 105 | | // Arrange |
| 1 | 106 | | blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 0), true); |
| 1 | 107 | | blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 1), true); |
| 1 | 108 | | blockerInstanceHandler.ShowBlocker(new Vector2Int(0, 2), true); |
| | 109 | |
|
| 1 | 110 | | Assert.AreEqual(3, blockerInstanceHandler.GetBlockers().Count); |
| | 111 | |
|
| | 112 | | // Act |
| 1 | 113 | | blockerInstanceHandler.DestroyAllBlockers(); |
| | 114 | |
|
| | 115 | | // Assert |
| 1 | 116 | | blockerAnimationHandler.DidNotReceiveWithAnyArgs().FadeOut(default, default); |
| 1 | 117 | | Assert.AreEqual(0, blockerInstanceHandler.GetBlockers().Count); |
| 1 | 118 | | } |
| | 119 | | } |