| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using NSubstitute; |
| | 4 | | using NSubstitute.Extensions; |
| | 5 | | using NUnit.Framework; |
| | 6 | | using SignupHUD; |
| | 7 | |
|
| | 8 | | namespace Tests.SignupHUD |
| | 9 | | { |
| | 10 | | public class SignupHUDControllerShould |
| | 11 | | { |
| | 12 | | private SignupHUDController hudController; |
| | 13 | | private ISignupHUDView hudView; |
| | 14 | | private IHUD avatarEditorHUD; |
| 0 | 15 | | private BaseVariable<bool> signupVisible => DataStore.i.HUDs.signupVisible; |
| | 16 | |
|
| | 17 | | [SetUp] |
| | 18 | | public void SetUp() |
| | 19 | | { |
| 8 | 20 | | hudView = Substitute.For<ISignupHUDView>(); |
| 8 | 21 | | avatarEditorHUD = Substitute.For<IHUD>(); |
| 8 | 22 | | hudController = Substitute.ForPartsOf<SignupHUDController>(); |
| 16 | 23 | | hudController.Configure().CreateView().Returns(info => hudView); |
| 8 | 24 | | hudController.Initialize(avatarEditorHUD); |
| 8 | 25 | | } |
| | 26 | |
|
| | 27 | | [Test] |
| | 28 | | public void InitializeProperly() |
| | 29 | | { |
| 1 | 30 | | Assert.AreEqual(hudView, hudController.view); |
| 1 | 31 | | Assert.AreEqual(avatarEditorHUD, hudController.avatarEditorHUD); |
| 1 | 32 | | Assert.IsFalse(signupVisible.Get()); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | [Test] |
| | 36 | | public void ReactToSignupVisibleTrue() |
| | 37 | | { |
| 1 | 38 | | hudController.name = "this_will_be_null"; |
| 1 | 39 | | hudController.email = "this_will_be_null"; |
| | 40 | |
|
| 1 | 41 | | signupVisible.Set(true, true); //Force event notification |
| | 42 | |
|
| 1 | 43 | | hudView.Received().SetVisibility(true); |
| 1 | 44 | | Assert.IsNull(hudController.name); |
| 1 | 45 | | Assert.IsNull(hudController.email); |
| 1 | 46 | | hudView.Received().ShowNameScreen(); |
| 1 | 47 | | } |
| | 48 | |
|
| | 49 | | [Test] |
| | 50 | | public void ReactToSignupVisibleFalse() |
| | 51 | | { |
| 1 | 52 | | signupVisible.Set(false, true); //Force event notification |
| 1 | 53 | | hudView.Received().SetVisibility(false); |
| 1 | 54 | | } |
| | 55 | |
|
| | 56 | | [Test] |
| | 57 | | public void StartSignupProcessProperly() |
| | 58 | | { |
| 1 | 59 | | hudController.name = "this_will_be_null"; |
| 1 | 60 | | hudController.email = "this_will_be_null"; |
| | 61 | |
|
| 1 | 62 | | hudController.StartSignupProcess(); |
| | 63 | |
|
| 1 | 64 | | Assert.IsNull(hudController.name); |
| 1 | 65 | | Assert.IsNull(hudController.email); |
| 1 | 66 | | hudView.Received().ShowNameScreen(); |
| 1 | 67 | | } |
| | 68 | |
|
| | 69 | | [Test] |
| | 70 | | public void ReactsToNameScreenNextProperly() |
| | 71 | | { |
| 1 | 72 | | hudView.OnNameScreenNext += Raise.Event<ISignupHUDView.NameScreenDone>("new_name", "new_email"); |
| 1 | 73 | | Assert.AreEqual(hudController.name, "new_name"); |
| 1 | 74 | | Assert.AreEqual(hudController.email, "new_email"); |
| 1 | 75 | | hudView.Received().ShowTermsOfServiceScreen(); |
| 1 | 76 | | } |
| | 77 | |
|
| | 78 | | [Test] |
| | 79 | | public void ReactsToEditAvatarProperly() |
| | 80 | | { |
| 1 | 81 | | hudView.OnEditAvatar += Raise.Event<Action>(); |
| 1 | 82 | | Assert.IsFalse(signupVisible.Get()); |
| 1 | 83 | | avatarEditorHUD.Received().SetVisibility(true); |
| 1 | 84 | | } |
| | 85 | |
|
| | 86 | | [Test] |
| | 87 | | public void ReactsToTermsOfServiceAgreed() |
| | 88 | | { |
| 1 | 89 | | hudView.OnTermsOfServiceAgreed += Raise.Event<Action>(); |
| | 90 | | //TODO assert webinterface interaction |
| 1 | 91 | | Assert.IsFalse(signupVisible.Get()); |
| 1 | 92 | | Assert.IsFalse(DataStore.i.isSignUpFlow.Get()); |
| 1 | 93 | | } |
| | 94 | |
|
| | 95 | | [Test] |
| | 96 | | public void ReactsToTermsOfServiceBack() |
| | 97 | | { |
| 1 | 98 | | hudController.name = "this_will_be_null"; |
| 1 | 99 | | hudController.email = "this_will_be_null"; |
| | 100 | |
|
| 1 | 101 | | hudView.OnTermsOfServiceBack += Raise.Event<Action>(); |
| | 102 | |
|
| 1 | 103 | | Assert.IsNull(hudController.name); |
| 1 | 104 | | Assert.IsNull(hudController.email); |
| 1 | 105 | | hudView.Received().ShowNameScreen(); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | [TearDown] |
| 16 | 109 | | public void TearDown() { DataStore.Clear(); } |
| | 110 | | } |
| | 111 | | } |