| | 1 | | using System.Linq; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace Tests |
| | 6 | | { |
| | 7 | | public class SectionSceneContributorsSettingsShould |
| | 8 | | { |
| | 9 | | private SectionSceneContributorsSettingsView view; |
| | 10 | | private SectionSceneContributorsSettingsController controller; |
| | 11 | |
|
| | 12 | | [SetUp] |
| | 13 | | public void SetUp() |
| | 14 | | { |
| 4 | 15 | | var prefab = Resources.Load<SectionSceneContributorsSettingsView>(SectionSceneContributorsSettingsController |
| 4 | 16 | | view = Object.Instantiate(prefab); |
| 4 | 17 | | controller = new SectionSceneContributorsSettingsController(view, new FriendsController_Mock()); |
| 4 | 18 | | } |
| | 19 | |
|
| | 20 | | [TearDown] |
| 8 | 21 | | public void TearDown() { controller.Dispose(); } |
| | 22 | |
|
| | 23 | | [Test] |
| 2 | 24 | | public void HavePrefabSetupCorrectly() { Assert.AreEqual(1, view.usersContainer.childCount); } |
| | 25 | |
|
| | 26 | | [Test] |
| | 27 | | public void ShowEmptyListCorrectly() |
| | 28 | | { |
| 1 | 29 | | view.SetEmptyList(true); |
| | 30 | |
|
| 1 | 31 | | Assert.IsTrue(view.emptyListContainer.activeSelf); |
| 1 | 32 | | Assert.IsFalse(view.usersContainer.gameObject.activeSelf); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | [Test] |
| | 36 | | public void UpdateContributorsCorrectly() |
| | 37 | | { |
| 1 | 38 | | controller.UpdateContributors(new [] { "1", "2", "3" }); |
| | 39 | |
|
| 1 | 40 | | Assert.AreEqual(3, view.userElementViews.Count); |
| 1 | 41 | | Assert.AreEqual(3, GetVisibleChildrenAmount(view.usersContainer)); |
| | 42 | |
|
| 1 | 43 | | controller.UpdateContributors(new [] { "1", "2" }); |
| | 44 | |
|
| 1 | 45 | | Assert.AreEqual(2, view.userElementViews.Count); |
| 1 | 46 | | Assert.AreEqual(2, GetVisibleChildrenAmount(view.usersContainer)); |
| 1 | 47 | | } |
| | 48 | |
|
| | 49 | | [Test] |
| | 50 | | public void TriggerUpdateContributorsCorrectly() |
| | 51 | | { |
| 1 | 52 | | controller.UpdateContributors(new [] { "1" }); |
| | 53 | |
|
| 1 | 54 | | bool triggered = false; |
| 2 | 55 | | void UpdateContributors(string sceneId, SceneContributorsUpdatePayload payload) { triggered = true; } |
| | 56 | |
|
| 1 | 57 | | controller.OnRequestUpdateSceneContributors += UpdateContributors; |
| 1 | 58 | | view.userElementViews["1"].removeButton.onClick.Invoke(); |
| 1 | 59 | | Assert.IsTrue(triggered); |
| 1 | 60 | | } |
| | 61 | |
|
| 8 | 62 | | public int GetVisibleChildrenAmount(Transform parent) { return parent.Cast<Transform>().Count(child => child.gam |
| | 63 | | } |
| | 64 | | } |