|
| 1 | +package org.iiab.controller.kolibri.presentation; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertFalse; |
| 4 | +import static org.junit.Assert.assertTrue; |
| 5 | + |
| 6 | +import org.iiab.controller.kolibri.domain.TopicNode; |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +import java.util.Collections; |
| 10 | + |
| 11 | +/** |
| 12 | + * Unit tests for {@link KolibriTopicsUiState#isEmpty()} — the call that decides whether a |
| 13 | + * level renders content or the "empty" status. The offline bundle folds a folder's loose |
| 14 | + * leaves into an aggregate, so "no child folders" no longer means "nothing here" (ADFA-5094). |
| 15 | + * Pure JVM, no Android. |
| 16 | + */ |
| 17 | +public class KolibriTopicsUiStateTest { |
| 18 | + |
| 19 | + private static final String ROOT = "c150ea1d69495d37b5b0ac6f017e9bfb"; |
| 20 | + private static final String CHILD = "23a7dc9c73635cd2abbd3e8aab13c3ca"; |
| 21 | + |
| 22 | + private static KolibriTopicsUiState levelOf(TopicNode node) { |
| 23 | + return KolibriTopicsUiState.level(node, "Folder", |
| 24 | + Collections.<String>emptyList(), Collections.singletonList("Folder")); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void aLevelWithOnlyLooseResourcesIsNotEmpty() { |
| 29 | + // No sub-folders, but loose resources: must render the aggregate line, not "empty". |
| 30 | + TopicNode loose = TopicNode.fromBundle(ROOT, "Folder", "topic", 100L, 3, 3, 100L, null); |
| 31 | + assertFalse(levelOf(loose).isEmpty()); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void aLevelWithNeitherChildrenNorLooseIsEmpty() { |
| 36 | + TopicNode bare = TopicNode.fromBundle(ROOT, "Folder", "topic", 0L, 0, 0, 0L, null); |
| 37 | + assertTrue(levelOf(bare).isEmpty()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void aLevelWithChildFoldersIsNotEmpty() { |
| 42 | + TopicNode child = TopicNode.fromBundle(CHILD, "Sub", "topic", 0L, 0, 0, 0L, null); |
| 43 | + TopicNode parent = TopicNode.fromBundle(ROOT, "Folder", "topic", 0L, 1, 0, 0L, |
| 44 | + Collections.singletonList(child)); |
| 45 | + assertFalse(levelOf(parent).isEmpty()); |
| 46 | + } |
| 47 | +} |
0 commit comments