| | 1 | | using DCL; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using UnityEditor; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace Tests |
| | 7 | | { |
| | 8 | | public class UnpublishPopupShould |
| | 9 | | { |
| | 10 | | private UnpublishPopupView view; |
| | 11 | | private UnpublishPopupController controller; |
| | 12 | |
|
| | 13 | | [SetUp] |
| | 14 | | public void SetUp() |
| | 15 | | { |
| | 16 | | const string prefabAssetPath = |
| | 17 | | "Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Prefabs/UnpublishPopup/UnpublishPop |
| 6 | 18 | | var prefab = AssetDatabase.LoadAssetAtPath<UnpublishPopupView>(prefabAssetPath); |
| 6 | 19 | | view = UnityEngine.Object.Instantiate(prefab); |
| 6 | 20 | | controller = new UnpublishPopupController(view); |
| 6 | 21 | | } |
| | 22 | |
|
| | 23 | | [TearDown] |
| 12 | 24 | | public void TearDown() { controller.Dispose(); } |
| | 25 | |
|
| | 26 | | [Test] |
| | 27 | | public void ShowConfirmationPopupCorrectly() |
| | 28 | | { |
| 1 | 29 | | controller.Show(Vector2Int.zero); |
| 1 | 30 | | Assert.IsTrue(view.gameObject.activeSelf); |
| | 31 | |
|
| 1 | 32 | | Assert.IsTrue(view.cancelButton.gameObject.activeSelf); |
| 1 | 33 | | Assert.IsTrue(view.unpublishButton.gameObject.activeSelf); |
| 1 | 34 | | Assert.IsTrue(view.infoText.gameObject.activeSelf); |
| 1 | 35 | | Assert.IsTrue(view.closeButton.gameObject.activeSelf); |
| 1 | 36 | | Assert.IsFalse(view.doneButton.gameObject.activeSelf); |
| 1 | 37 | | Assert.IsFalse(view.errorText.gameObject.activeSelf); |
| 1 | 38 | | Assert.IsFalse(view.loadingBarContainer.gameObject.activeSelf); |
| 1 | 39 | | } |
| | 40 | |
|
| | 41 | | [Test] |
| | 42 | | public void ShowProgressCorrectly() |
| | 43 | | { |
| 1 | 44 | | IUnpublishPopupView iview = view; |
| 1 | 45 | | iview.SetProgress("", 0); |
| 1 | 46 | | Assert.AreEqual("0%", view.loadingText.text); |
| 1 | 47 | | iview.SetProgress("", 0.5f); |
| 1 | 48 | | Assert.AreEqual("50%", view.loadingText.text); |
| | 49 | |
|
| 1 | 50 | | Assert.IsTrue(view.loadingBarContainer.gameObject.activeSelf); |
| 1 | 51 | | Assert.IsFalse(view.cancelButton.gameObject.activeSelf); |
| 1 | 52 | | Assert.IsFalse(view.unpublishButton.gameObject.activeSelf); |
| 1 | 53 | | Assert.IsFalse(view.infoText.gameObject.activeSelf); |
| 1 | 54 | | Assert.IsFalse(view.doneButton.gameObject.activeSelf); |
| 1 | 55 | | Assert.IsFalse(view.errorText.gameObject.activeSelf); |
| 1 | 56 | | Assert.IsFalse(view.closeButton.gameObject.activeSelf); |
| 1 | 57 | | } |
| | 58 | |
|
| | 59 | | [Test] |
| | 60 | | public void ShowErrorCorrectly() |
| | 61 | | { |
| | 62 | | const string error = "Some Error"; |
| | 63 | |
|
| 1 | 64 | | IUnpublishPopupView iview = view; |
| 1 | 65 | | iview.SetError("", error); |
| 1 | 66 | | Assert.AreEqual(error, view.errorText.text); |
| | 67 | |
|
| 1 | 68 | | Assert.IsFalse(view.loadingBarContainer.gameObject.activeSelf); |
| 1 | 69 | | Assert.IsFalse(view.cancelButton.gameObject.activeSelf); |
| 1 | 70 | | Assert.IsFalse(view.unpublishButton.gameObject.activeSelf); |
| 1 | 71 | | Assert.IsFalse(view.infoText.gameObject.activeSelf); |
| 1 | 72 | | Assert.IsTrue(view.doneButton.gameObject.activeSelf); |
| 1 | 73 | | Assert.IsTrue(view.errorText.gameObject.activeSelf); |
| 1 | 74 | | Assert.IsTrue(view.closeButton.gameObject.activeSelf); |
| 1 | 75 | | } |
| | 76 | |
|
| | 77 | | [Test] |
| | 78 | | public void ShowSuccessCorrectly() |
| | 79 | | { |
| | 80 | | const string success = "Some Success Message"; |
| | 81 | |
|
| 1 | 82 | | IUnpublishPopupView iview = view; |
| 1 | 83 | | iview.SetSuccess("", success); |
| 1 | 84 | | Assert.AreEqual(success, view.infoText.text); |
| | 85 | |
|
| 1 | 86 | | Assert.IsTrue(view.infoText.gameObject.activeSelf); |
| 1 | 87 | | Assert.IsTrue(view.doneButton.gameObject.activeSelf); |
| 1 | 88 | | Assert.IsFalse(view.loadingBarContainer.gameObject.activeSelf); |
| 1 | 89 | | Assert.IsFalse(view.cancelButton.gameObject.activeSelf); |
| 1 | 90 | | Assert.IsFalse(view.unpublishButton.gameObject.activeSelf); |
| 1 | 91 | | Assert.IsFalse(view.errorText.gameObject.activeSelf); |
| 1 | 92 | | Assert.IsTrue(view.closeButton.gameObject.activeSelf); |
| 1 | 93 | | } |
| | 94 | |
|
| | 95 | | [Test] |
| | 96 | | public void ControllerSuccessFlowCorrectly() |
| | 97 | | { |
| 1 | 98 | | controller.Show(Vector2Int.zero); |
| 1 | 99 | | Assert.AreEqual(UnpublishPopupView.State.CONFIRM_UNPUBLISH, view.state); |
| | 100 | |
|
| 1 | 101 | | view.unpublishButton.onClick.Invoke(); |
| 1 | 102 | | Assert.AreEqual(UnpublishPopupView.State.UNPUBLISHING, view.state); |
| | 103 | |
|
| 1 | 104 | | DataStore.i.builderInWorld.unpublishSceneResult.Set(new PublishSceneResultPayload() { ok = true }, true); |
| 1 | 105 | | Assert.AreEqual(UnpublishPopupView.State.DONE_UNPUBLISH, view.state); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | [Test] |
| | 109 | | public void ControllerErrorFlowCorrectly() |
| | 110 | | { |
| 1 | 111 | | controller.Show(Vector2Int.zero); |
| 1 | 112 | | Assert.AreEqual(UnpublishPopupView.State.CONFIRM_UNPUBLISH, view.state); |
| | 113 | |
|
| 1 | 114 | | view.unpublishButton.onClick.Invoke(); |
| 1 | 115 | | Assert.AreEqual(UnpublishPopupView.State.UNPUBLISHING, view.state); |
| | 116 | |
|
| 1 | 117 | | DataStore.i.builderInWorld.unpublishSceneResult.Set(new PublishSceneResultPayload() { ok = false }, true); |
| 1 | 118 | | Assert.AreEqual(UnpublishPopupView.State.ERROR_UNPUBLISH, view.state); |
| 1 | 119 | | } |
| | 120 | | } |
| | 121 | | } |