| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCL.Models; |
| | 5 | | using NUnit.Framework; |
| | 6 | | using System.Collections; |
| | 7 | | using DCL.Controllers; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.TestTools; |
| | 10 | | using TMPro; |
| | 11 | |
|
| | 12 | | namespace Tests |
| | 13 | | { |
| | 14 | | public class FontTests : IntegrationTestSuite |
| | 15 | | { |
| | 16 | | const string TEST_BUILTIN_FONT_NAME = "builtin:SF-UI-Text-Regular SDF"; |
| | 17 | |
|
| | 18 | | private ParcelScene scene; |
| | 19 | |
|
| | 20 | | protected override WorldRuntimeContext CreateRuntimeContext() |
| | 21 | | { |
| 3 | 22 | | return DCL.Tests.WorldRuntimeContextFactory.CreateWithCustomMocks |
| | 23 | | ( |
| | 24 | | sceneController: new SceneController(), |
| | 25 | | state: new WorldState(), |
| | 26 | | componentFactory: new RuntimeComponentFactory() |
| | 27 | | ); |
| | 28 | | } |
| | 29 | |
|
| | 30 | | [UnitySetUp] |
| | 31 | | protected override IEnumerator SetUp() |
| | 32 | | { |
| 3 | 33 | | yield return base.SetUp(); |
| 3 | 34 | | scene = Environment.i.world.sceneController.CreateTestScene() as ParcelScene; |
| 3 | 35 | | } |
| | 36 | |
|
| | 37 | | [UnityTest] |
| | 38 | | public IEnumerator BuiltInFontCreateAndLoadTest() |
| | 39 | | { |
| 1 | 40 | | DCLFont font = |
| | 41 | | TestHelpers.SharedComponentCreate<DCLFont, DCLFont.Model>(scene, CLASS_ID.FONT, new DCLFont.Model() { sr |
| 1 | 42 | | yield return font.routine; |
| | 43 | |
|
| 1 | 44 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 45 | |
|
| 1 | 46 | | TextShape textShape = |
| | 47 | | TestHelpers.EntityComponentCreate<TextShape, TextShape.Model>(scene, entity, new TextShape.Model() { fon |
| 1 | 48 | | yield return textShape.routine; |
| | 49 | |
|
| 1 | 50 | | Assert.IsTrue(font.loaded, "Built-in font didn't load"); |
| 1 | 51 | | Assert.IsFalse(font.error, "Built-in font has error"); |
| | 52 | |
|
| 1 | 53 | | TextMeshPro tmpro = textShape.GetComponentInChildren<TextMeshPro>(); |
| 1 | 54 | | Assert.IsTrue(font.fontAsset == tmpro.font, "Built-in font didn't apply correctly"); |
| 1 | 55 | | } |
| | 56 | |
|
| | 57 | | [UnityTest] |
| | 58 | | public IEnumerator BuiltInFontHandleErrorProperly() |
| | 59 | | { |
| 1 | 60 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 61 | |
|
| 1 | 62 | | TextShape textShape = |
| | 63 | | TestHelpers.EntityComponentCreate<TextShape, TextShape.Model>(scene, entity, new TextShape.Model()); |
| 1 | 64 | | yield return textShape.routine; |
| | 65 | |
|
| 1 | 66 | | TMP_FontAsset defaultFont = textShape.GetComponentInChildren<TextMeshPro>().font; |
| | 67 | |
|
| 1 | 68 | | DCLFont font = |
| | 69 | | TestHelpers.SharedComponentCreate<DCLFont, DCLFont.Model>(scene, CLASS_ID.FONT, new DCLFont.Model() { sr |
| 1 | 70 | | yield return font.routine; |
| | 71 | |
|
| 1 | 72 | | scene.EntityComponentUpdate(entity, CLASS_ID_COMPONENT.TEXT_SHAPE, |
| | 73 | | JsonUtility.ToJson(new TextShape.Model { font = font.id })); |
| 1 | 74 | | yield return textShape.routine; |
| | 75 | |
|
| 1 | 76 | | Assert.IsTrue(font.error, "Built-in font error has not araise properly"); |
| 1 | 77 | | Assert.IsTrue(textShape.GetComponentInChildren<TextMeshPro>().font == defaultFont, "Built-in font didn't app |
| 1 | 78 | | } |
| | 79 | |
|
| | 80 | | [UnityTest] |
| | 81 | | public IEnumerator BuiltInFontAttachCorrectlyOnTextComponentUpdate() |
| | 82 | | { |
| 1 | 83 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 84 | |
|
| 1 | 85 | | TextShape textShape = |
| | 86 | | TestHelpers.EntityComponentCreate<TextShape, TextShape.Model>(scene, entity, new TextShape.Model()); |
| 1 | 87 | | yield return textShape.routine; |
| | 88 | |
|
| 1 | 89 | | DCLFont font = |
| | 90 | | TestHelpers.SharedComponentCreate<DCLFont, DCLFont.Model>(scene, CLASS_ID.FONT, new DCLFont.Model() { sr |
| 1 | 91 | | yield return font.routine; |
| | 92 | |
|
| 1 | 93 | | scene.EntityComponentUpdate(entity, CLASS_ID_COMPONENT.TEXT_SHAPE, |
| | 94 | | JsonUtility.ToJson(new TextShape.Model { font = font.id })); |
| 1 | 95 | | yield return textShape.routine; |
| | 96 | |
|
| 1 | 97 | | Assert.IsTrue(font.loaded, "Built-in font didn't load"); |
| 1 | 98 | | Assert.IsFalse(font.error, "Built-in font has error"); |
| | 99 | |
|
| 1 | 100 | | TextMeshPro tmpro = textShape.GetComponentInChildren<TextMeshPro>(); |
| 1 | 101 | | Assert.IsTrue(font.fontAsset == tmpro.font, "Built-in font didn't apply correctly"); |
| 1 | 102 | | } |
| | 103 | | } |
| | 104 | | } |