|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +package com.facebook.react.fabric.internal.interop |
| 9 | + |
| 10 | +import com.facebook.testutils.fakes.FakeUIManager |
| 11 | +import org.junit.Assert.assertEquals |
| 12 | +import org.junit.Test |
| 13 | + |
| 14 | +class InteropUiBlockListenerTest { |
| 15 | + |
| 16 | + @Test |
| 17 | + fun prependUIBlock_addsBlockCorrectly() { |
| 18 | + val underTest = InteropUIBlockListener() |
| 19 | + underTest.prependUIBlock {} |
| 20 | + |
| 21 | + assertEquals(1, underTest.beforeUIBlocks.size) |
| 22 | + assertEquals(0, underTest.afterUIBlocks.size) |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + fun addUIBlock_addsBlockCorrectly() { |
| 27 | + val underTest = InteropUIBlockListener() |
| 28 | + underTest.addUIBlock {} |
| 29 | + |
| 30 | + assertEquals(0, underTest.beforeUIBlocks.size) |
| 31 | + assertEquals(1, underTest.afterUIBlocks.size) |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + fun willMountItems_emptiesBeforeUIBlocks() { |
| 36 | + val underTest = InteropUIBlockListener() |
| 37 | + underTest.prependUIBlock {} |
| 38 | + underTest.addUIBlock {} |
| 39 | + |
| 40 | + underTest.willMountItems(FakeUIManager()) |
| 41 | + |
| 42 | + assertEquals(0, underTest.beforeUIBlocks.size) |
| 43 | + assertEquals(1, underTest.afterUIBlocks.size) |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + fun didMountItems_emptiesAfterUIBlocks() { |
| 48 | + val underTest = InteropUIBlockListener() |
| 49 | + underTest.prependUIBlock {} |
| 50 | + underTest.addUIBlock {} |
| 51 | + |
| 52 | + underTest.didMountItems(FakeUIManager()) |
| 53 | + |
| 54 | + assertEquals(1, underTest.beforeUIBlocks.size) |
| 55 | + assertEquals(0, underTest.afterUIBlocks.size) |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + fun willMountItems_deliversUiManagerCorrectly() { |
| 60 | + val fakeUIManager = FakeUIManager() |
| 61 | + val underTest = InteropUIBlockListener() |
| 62 | + |
| 63 | + underTest.prependUIBlock { uiManager -> uiManager.resolveView(0) } |
| 64 | + |
| 65 | + underTest.willMountItems(fakeUIManager) |
| 66 | + |
| 67 | + assertEquals(1, fakeUIManager.resolvedViewCount) |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + fun didMountItems_deliversUiManagerCorrectly() { |
| 72 | + val fakeUIManager = FakeUIManager() |
| 73 | + val underTest = InteropUIBlockListener() |
| 74 | + |
| 75 | + underTest.addUIBlock { uiManager -> uiManager.resolveView(0) } |
| 76 | + |
| 77 | + underTest.didMountItems(fakeUIManager) |
| 78 | + |
| 79 | + assertEquals(1, fakeUIManager.resolvedViewCount) |
| 80 | + } |
| 81 | +} |
0 commit comments