|
| 1 | +package com.interlinedlist.android.feature.lists.ui.detail |
| 2 | + |
| 3 | +import androidx.compose.ui.test.assertIsDisplayed |
| 4 | +import androidx.compose.ui.test.junit4.createComposeRule |
| 5 | +import androidx.compose.ui.test.onNodeWithTag |
| 6 | +import androidx.compose.ui.test.onNodeWithText |
| 7 | +import androidx.compose.ui.test.performClick |
| 8 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 9 | +import com.google.common.truth.Truth.assertThat |
| 10 | +import com.interlinedlist.android.core.designsystem.theme.InterlinedListTheme |
| 11 | +import com.interlinedlist.android.feature.lists.domain.GithubRepoLink |
| 12 | +import com.interlinedlist.android.feature.lists.domain.ListSchema |
| 13 | +import com.interlinedlist.android.feature.lists.domain.ListSource |
| 14 | +import com.interlinedlist.android.feature.lists.domain.ListSummary |
| 15 | +import org.junit.Rule |
| 16 | +import org.junit.Test |
| 17 | +import org.junit.runner.RunWith |
| 18 | + |
| 19 | +/** |
| 20 | + * The repository link under a GitHub-backed list's title, and its **Private repo** |
| 21 | + * tag — which describes the repository's visibility on GitHub, never the list's. |
| 22 | + */ |
| 23 | +@RunWith(AndroidJUnit4::class) |
| 24 | +class GithubRepoLinkRowTest { |
| 25 | + |
| 26 | + @get:Rule |
| 27 | + val composeRule = createComposeRule() |
| 28 | + |
| 29 | + private fun setRow(isPrivate: Boolean?, onOpenRepo: (String) -> Unit = {}) { |
| 30 | + composeRule.setContent { |
| 31 | + InterlinedListTheme { |
| 32 | + GithubRepoLinkRow( |
| 33 | + repo = "octocat/Hello-World", |
| 34 | + githubRepoPrivate = isPrivate, |
| 35 | + onOpenRepo = onOpenRepo, |
| 36 | + ) |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + fun linksTheRepositoryIssuesPage() { |
| 43 | + var opened: String? = null |
| 44 | + setRow(isPrivate = false) { opened = it } |
| 45 | + |
| 46 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.LINK).assertIsDisplayed() |
| 47 | + composeRule.onNodeWithText("octocat/Hello-World issues").assertIsDisplayed() |
| 48 | + |
| 49 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.LINK).performClick() |
| 50 | + assertThat(opened).isEqualTo("https://github.com/octocat/Hello-World/issues") |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + fun showsThePrivateRepoTag_whenTheRepositoryIsPrivate() { |
| 55 | + setRow(isPrivate = true) |
| 56 | + |
| 57 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).assertIsDisplayed() |
| 58 | + composeRule.onNodeWithText(GithubRepoLink.PRIVATE_TAG).assertIsDisplayed() |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + fun theTagExplainsTheRepositoryIsPrivate_notTheList() { |
| 63 | + setRow(isPrivate = true) |
| 64 | + |
| 65 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).performClick() |
| 66 | + |
| 67 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_EXPLANATION).assertIsDisplayed() |
| 68 | + // The copy names the repository, and says the list's visibility is separate. |
| 69 | + val explanation = GithubRepoLink.PRIVATE_TAG_EXPLANATION |
| 70 | + assertThat(explanation).contains("This repository is private on GitHub") |
| 71 | + assertThat(explanation).contains("separate from who can see this list") |
| 72 | + composeRule.onNodeWithText(explanation).assertIsDisplayed() |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + fun showsNoTag_whenTheRepositoryIsPublic() { |
| 77 | + setRow(isPrivate = false) |
| 78 | + |
| 79 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).assertDoesNotExist() |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + fun showsNoTag_whenTheRepositoryVisibilityIsNotYetKnown() { |
| 84 | + // A list that has not synced since the tag existed: unknown is never |
| 85 | + // presented as public, and it is never presented as private either. |
| 86 | + setRow(isPrivate = null) |
| 87 | + |
| 88 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.LINK).assertIsDisplayed() |
| 89 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).assertDoesNotExist() |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + fun rendersUnderTheTitleOfAGithubBackedListOnly() { |
| 94 | + val githubList = ListSummary( |
| 95 | + id = "L1", |
| 96 | + title = "Repo issues", |
| 97 | + description = null, |
| 98 | + itemCount = 0, |
| 99 | + folderId = null, |
| 100 | + isPublic = false, |
| 101 | + updatedAt = null, |
| 102 | + parentId = null, |
| 103 | + source = ListSource.GITHUB, |
| 104 | + githubRepo = "octocat/Hello-World", |
| 105 | + githubRepoPrivate = true, |
| 106 | + ) |
| 107 | + composeRule.setContent { |
| 108 | + InterlinedListTheme { |
| 109 | + ListDetailScreen( |
| 110 | + state = ListDetailUiState( |
| 111 | + summary = githubList, |
| 112 | + schema = ListSchema.EMPTY, |
| 113 | + isLoading = false, |
| 114 | + ), |
| 115 | + onBack = {}, |
| 116 | + onAddRow = {}, |
| 117 | + onEditRow = {}, |
| 118 | + onDeleteRow = {}, |
| 119 | + onDeleteList = {}, |
| 120 | + ) |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.ROW).assertIsDisplayed() |
| 125 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).assertIsDisplayed() |
| 126 | + // Refresh from GitHub is offered here and nowhere else. |
| 127 | + composeRule.onNodeWithTag(ListDetailTestTags.REFRESH).assertIsDisplayed() |
| 128 | + } |
| 129 | + |
| 130 | + @Test |
| 131 | + fun aLocalListShowsNoRepoLinkAndNoRefresh() { |
| 132 | + composeRule.setContent { |
| 133 | + InterlinedListTheme { |
| 134 | + ListDetailScreen( |
| 135 | + state = ListDetailUiState( |
| 136 | + summary = ListSummary("L1", "Reading", null, 0, null, false, null), |
| 137 | + schema = ListSchema.EMPTY, |
| 138 | + isLoading = false, |
| 139 | + ), |
| 140 | + onBack = {}, |
| 141 | + onAddRow = {}, |
| 142 | + onEditRow = {}, |
| 143 | + onDeleteRow = {}, |
| 144 | + onDeleteList = {}, |
| 145 | + ) |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + composeRule.onNodeWithTag(GithubRepoLinkTestTags.ROW).assertDoesNotExist() |
| 150 | + composeRule.onNodeWithTag(ListDetailTestTags.REFRESH).assertDoesNotExist() |
| 151 | + } |
| 152 | +} |
0 commit comments