| | 1 | | using NUnit.Framework; |
| | 2 | | using System.Collections; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.TestTools; |
| | 5 | |
|
| | 6 | | public class FriendRequestEntryShould : IntegrationTestSuite_Legacy |
| | 7 | | { |
| 1 | 8 | | static string FRIEND_REQUEST_ENTRY_RESOURCE_NAME = "FriendRequestEntry"; |
| | 9 | |
|
| | 10 | | FriendRequestEntry entry; |
| | 11 | |
|
| | 12 | | [UnitySetUp] |
| | 13 | | protected override IEnumerator SetUp() |
| | 14 | | { |
| 5 | 15 | | GameObject go = Object.Instantiate((GameObject)Resources.Load(FRIEND_REQUEST_ENTRY_RESOURCE_NAME)); |
| 5 | 16 | | entry = go.GetComponent<FriendRequestEntry>(); |
| 5 | 17 | | yield break; |
| | 18 | | } |
| | 19 | |
|
| | 20 | | protected override IEnumerator TearDown() |
| | 21 | | { |
| 5 | 22 | | Object.Destroy(entry.gameObject); |
| 5 | 23 | | yield break; |
| | 24 | | } |
| | 25 | |
|
| | 26 | | [Test] |
| | 27 | | public void BePopulatedCorrectly() |
| | 28 | | { |
| 1 | 29 | | var model1 = new FriendEntry.Model() { userName = "test1", avatarImage = Texture2D.whiteTexture }; |
| 1 | 30 | | var model2 = new FriendEntry.Model() { userName = "test2", avatarImage = Texture2D.blackTexture }; |
| | 31 | |
|
| 1 | 32 | | entry.userId = "userId1"; |
| 1 | 33 | | entry.Populate(model1); |
| 1 | 34 | | entry.SetReceived(true); |
| | 35 | |
|
| 1 | 36 | | Assert.AreEqual(model1.userName, entry.playerNameText.text); |
| 1 | 37 | | Assert.AreEqual(model1.avatarImage, entry.playerImage.texture); |
| | 38 | |
|
| 1 | 39 | | Assert.IsFalse(entry.cancelButton.gameObject.activeSelf); |
| 1 | 40 | | Assert.IsTrue(entry.acceptButton.gameObject.activeSelf); |
| 1 | 41 | | Assert.IsTrue(entry.rejectButton.gameObject.activeSelf); |
| | 42 | |
|
| 1 | 43 | | entry.userId = "userId2"; |
| 1 | 44 | | entry.Populate(model2); |
| 1 | 45 | | entry.SetReceived(false); |
| | 46 | |
|
| 1 | 47 | | Assert.AreEqual(model2.userName, entry.playerNameText.text); |
| 1 | 48 | | Assert.AreEqual(model2.avatarImage, entry.playerImage.texture); |
| | 49 | |
|
| 1 | 50 | | Assert.IsTrue(entry.cancelButton.gameObject.activeSelf); |
| 1 | 51 | | Assert.IsFalse(entry.acceptButton.gameObject.activeSelf); |
| 1 | 52 | | Assert.IsFalse(entry.rejectButton.gameObject.activeSelf); |
| 1 | 53 | | } |
| | 54 | |
|
| | 55 | | [Test] |
| | 56 | | public void SendProperEventWhenOnAcceptedIsPressed() |
| | 57 | | { |
| 1 | 58 | | var model = new FriendEntry.Model() { }; |
| 1 | 59 | | entry.userId = "userId-1"; |
| 1 | 60 | | entry.Populate(model); |
| | 61 | |
|
| 1 | 62 | | bool buttonPressed = false; |
| 1 | 63 | | entry.OnAccepted += (x) => |
| | 64 | | { |
| 1 | 65 | | if (x == entry) |
| 1 | 66 | | buttonPressed = true; |
| 1 | 67 | | }; |
| 1 | 68 | | entry.acceptButton.onClick.Invoke(); |
| 1 | 69 | | Assert.IsTrue(buttonPressed); |
| 1 | 70 | | } |
| | 71 | |
|
| | 72 | | [Test] |
| | 73 | | public void SendProperEventWhenOnCancelledIsPressed() |
| | 74 | | { |
| 1 | 75 | | var model = new FriendEntry.Model() { }; |
| 1 | 76 | | entry.userId = "userId-1"; |
| 1 | 77 | | entry.Populate(model); |
| 1 | 78 | | bool buttonPressed = false; |
| 1 | 79 | | entry.OnCancelled += (x) => |
| | 80 | | { |
| 1 | 81 | | if (x == entry) |
| 1 | 82 | | buttonPressed = true; |
| 1 | 83 | | }; |
| 1 | 84 | | entry.cancelButton.onClick.Invoke(); |
| 1 | 85 | | Assert.IsTrue(buttonPressed); |
| 1 | 86 | | } |
| | 87 | |
|
| | 88 | | [Test] |
| | 89 | | public void SendProperEventWhenOnMenuToggleIsPressed() |
| | 90 | | { |
| 1 | 91 | | var model = new FriendEntry.Model() { }; |
| 1 | 92 | | entry.userId = "userId-1"; |
| 1 | 93 | | entry.Populate(model); |
| 1 | 94 | | bool buttonPressed = false; |
| 1 | 95 | | entry.OnMenuToggle += (x) => |
| | 96 | | { |
| 1 | 97 | | if (x == entry) |
| 1 | 98 | | buttonPressed = true; |
| 1 | 99 | | }; |
| 1 | 100 | | entry.menuButton.onClick.Invoke(); |
| 1 | 101 | | Assert.IsTrue(buttonPressed); |
| 1 | 102 | | } |
| | 103 | |
|
| | 104 | | [Test] |
| | 105 | | public void SendProperEventWhenOnRejectedIsPressed() |
| | 106 | | { |
| 1 | 107 | | var model = new FriendEntry.Model() { }; |
| 1 | 108 | | entry.userId = "userId-1"; |
| 1 | 109 | | entry.Populate(model); |
| 1 | 110 | | bool buttonPressed = false; |
| 1 | 111 | | entry.OnRejected += (x) => |
| | 112 | | { |
| 1 | 113 | | if (x == entry) |
| 1 | 114 | | buttonPressed = true; |
| 1 | 115 | | }; |
| 1 | 116 | | entry.rejectButton.onClick.Invoke(); |
| 1 | 117 | | Assert.IsTrue(buttonPressed); |
| 1 | 118 | | } |
| | 119 | |
|
| | 120 | | } |