| | 1 | | using NUnit.Framework; |
| | 2 | | using System.Collections; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.TestTools; |
| | 5 | |
|
| | 6 | | namespace Tests.BuildModeHUDViews |
| | 7 | | { |
| | 8 | | public class SceneCatalogViewShould |
| | 9 | | { |
| | 10 | | private SceneCatalogView sceneCatalogView; |
| | 11 | |
|
| | 12 | | [SetUp] |
| 28 | 13 | | public void SetUp() { sceneCatalogView = SceneCatalogView.Create(); } |
| | 14 | |
|
| | 15 | | [TearDown] |
| 28 | 16 | | public void TearDown() { Object.Destroy(sceneCatalogView.gameObject); } |
| | 17 | |
|
| | 18 | | [Test] |
| | 19 | | public void HideCatalogClickCorrectly() |
| | 20 | | { |
| | 21 | | // Arrange |
| 1 | 22 | | bool hideCatalogClicked = false; |
| 2 | 23 | | sceneCatalogView.OnHideCatalogClicked += () => hideCatalogClicked = true; |
| | 24 | |
|
| | 25 | | // Act |
| 1 | 26 | | sceneCatalogView.OnHideCatalogClick(); |
| | 27 | |
|
| | 28 | | // Assert |
| 1 | 29 | | Assert.IsTrue(hideCatalogClicked, "The hide catalog event has not been called!"); |
| 1 | 30 | | } |
| | 31 | |
|
| | 32 | | [Test] |
| | 33 | | public void GoBackCorrectly() |
| | 34 | | { |
| | 35 | | // Arrange |
| 1 | 36 | | bool backClicked = false; |
| 2 | 37 | | sceneCatalogView.OnSceneCatalogBack += () => backClicked = true; |
| | 38 | |
|
| | 39 | | // Act |
| 1 | 40 | | sceneCatalogView.Back(); |
| | 41 | |
|
| | 42 | | // Assert |
| 1 | 43 | | Assert.IsTrue(backClicked, "The back event has not been called!"); |
| 1 | 44 | | } |
| | 45 | |
|
| | 46 | | [Test] |
| | 47 | | public void SetCatalogTitleCorrectly() |
| | 48 | | { |
| | 49 | | // Arrange |
| 1 | 50 | | string oldText = "Old text"; |
| 1 | 51 | | string newText = "New text"; |
| 1 | 52 | | sceneCatalogView.catalogTitleTxt.text = oldText; |
| | 53 | |
|
| | 54 | | // Act |
| 1 | 55 | | sceneCatalogView.SetCatalogTitle(newText); |
| | 56 | |
|
| | 57 | | // Assert |
| 1 | 58 | | Assert.AreEqual(newText, sceneCatalogView.catalogTitleTxt.text, "The catalog title does not match!"); |
| 1 | 59 | | } |
| | 60 | |
|
| | 61 | | [Test] |
| | 62 | | [TestCase(true)] |
| | 63 | | [TestCase(false)] |
| | 64 | | public void CheckIfCatalogIsOpenCorrectly(bool isOpen) |
| | 65 | | { |
| | 66 | | // Arrange |
| 2 | 67 | | sceneCatalogView.gameObject.SetActive(isOpen); |
| | 68 | |
|
| | 69 | | // Act |
| 2 | 70 | | bool isCatalogOpen = sceneCatalogView.IsCatalogOpen(); |
| | 71 | |
|
| | 72 | | // Assert |
| 2 | 73 | | Assert.AreEqual(sceneCatalogView.gameObject.activeSelf, isCatalogOpen, "The catalog activation property does |
| 2 | 74 | | } |
| | 75 | |
|
| | 76 | | [Test] |
| | 77 | | [TestCase(true)] |
| | 78 | | [TestCase(false)] |
| | 79 | | public void CheckIfCatalogIsExpandedCorrectly(bool isExpanded) |
| | 80 | | { |
| | 81 | | // Arrange |
| 2 | 82 | | sceneCatalogView.isCatalogExpanded = isExpanded; |
| | 83 | |
|
| | 84 | | // Act |
| 2 | 85 | | bool isCatalogExpanded = sceneCatalogView.IsCatalogExpanded(); |
| | 86 | |
|
| | 87 | | // Assert |
| 2 | 88 | | Assert.AreEqual(sceneCatalogView.isCatalogExpanded, isCatalogExpanded, "The catalog expanded property does n |
| 2 | 89 | | } |
| | 90 | |
|
| | 91 | | [UnityTest] |
| | 92 | | public IEnumerator CloseCatalogCorrectly() |
| | 93 | | { |
| | 94 | | // Arrange |
| 1 | 95 | | sceneCatalogView.gameObject.SetActive(true); |
| | 96 | |
|
| | 97 | | // Act |
| 1 | 98 | | sceneCatalogView.CloseCatalog(); |
| | 99 | |
|
| | 100 | | // Assert |
| 1 | 101 | | Assert.IsTrue(sceneCatalogView.isClosing, "The isClosing flag should be activated!"); |
| 1 | 102 | | yield return null; |
| 1 | 103 | | Assert.IsFalse(sceneCatalogView.gameObject.activeSelf, "The catalog is not deactivated!"); |
| 1 | 104 | | Assert.IsFalse(sceneCatalogView.isClosing, "The isClosing flag should be deactivated!"); |
| 1 | 105 | | } |
| | 106 | |
|
| | 107 | | [UnityTest] |
| | 108 | | [TestCase(true, true, ExpectedResult = null)] |
| | 109 | | [TestCase(true, false, ExpectedResult = null)] |
| | 110 | | [TestCase(false, true, ExpectedResult = null)] |
| | 111 | | [TestCase(false, false, ExpectedResult = null)] |
| | 112 | | public IEnumerator SetActiveCorrectly(bool isActive, bool isClosing) |
| | 113 | | { |
| | 114 | | // Arrange |
| 4 | 115 | | sceneCatalogView.isClosing = isClosing; |
| 4 | 116 | | sceneCatalogView.gameObject.SetActive(!isActive); |
| | 117 | |
|
| | 118 | | // Act |
| 4 | 119 | | sceneCatalogView.SetActive(isActive); |
| | 120 | |
|
| | 121 | | // Assert |
| 4 | 122 | | if (isActive && isClosing) |
| | 123 | | { |
| 1 | 124 | | Assert.AreEqual(!isActive, sceneCatalogView.gameObject.activeSelf); |
| 1 | 125 | | sceneCatalogView.isClosing = false; |
| 1 | 126 | | yield return null; |
| | 127 | | } |
| | 128 | |
|
| 4 | 129 | | Assert.AreEqual(isActive, sceneCatalogView.gameObject.activeSelf, "The catalog has not been activated proper |
| | 130 | |
|
| 4 | 131 | | yield return null; |
| 4 | 132 | | Assert.IsTrue(true); |
| 4 | 133 | | } |
| | 134 | |
|
| | 135 | | [Test] |
| | 136 | | [TestCase(true)] |
| | 137 | | [TestCase(false)] |
| | 138 | | public void ShowBackButton(bool isActive) |
| | 139 | | { |
| | 140 | | // Arrange |
| 2 | 141 | | sceneCatalogView.backgBtn.gameObject.SetActive(!isActive); |
| | 142 | |
|
| | 143 | | // Act |
| 2 | 144 | | sceneCatalogView.ShowBackButton(isActive); |
| | 145 | |
|
| | 146 | | // Assert |
| 2 | 147 | | Assert.AreEqual(isActive, sceneCatalogView.backgBtn.gameObject.activeSelf, "The back button has not been act |
| 2 | 148 | | } |
| | 149 | | } |
| | 150 | | } |