Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.interlinedlist.android.navigation

import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.List
Expand Down Expand Up @@ -344,13 +346,18 @@ private fun MainShell(
onOpenConnections = { tabNav.navigate(Routes.LIST_CONNECTIONS) },
onOpenSharedWithMe = { tabNav.navigate(Routes.LISTS_SHARED_WITH_ME) },
onOpenFolders = { tabNav.navigate(Routes.LIST_FOLDERS) },
// A GitHub-backed list needs GitHub linked with the Issues
// scope; linking is an OAuth flow this app does not drive, so
// the picker routes to the existing connected-accounts screen.
onOpenConnectedAccounts = { tabNav.navigate(Routes.INTEGRATIONS_ACCOUNTS) },
)
}
composable(
Routes.LIST_DETAIL,
arguments = listOf(navArgument("listId") { type = NavType.StringType }),
) { entry ->
val listId = entry.arguments?.getString("listId").orEmpty()
val context = LocalContext.current
ListDetailRoute(
onBack = { tabNav.popBackStack() },
onListDeleted = { tabNav.popBackStack() },
Expand All @@ -359,6 +366,13 @@ private fun MainShell(
onOpenShare = { tabNav.navigate(Routes.listShare(listId)) },
// Breadcrumb hops and newly created child lists open a detail route.
onOpenList = { id -> tabNav.navigate(Routes.listDetail(id)) },
// The repository link under a GitHub-backed list's title opens
// that repo's issues page in the browser, as the web app does.
onOpenRepo = { url ->
runCatching {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}
},
)
}
composable(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.interlinedlist.android.feature.lists.ui.detail

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.interlinedlist.android.core.designsystem.theme.InterlinedListTheme
import com.interlinedlist.android.feature.lists.domain.GithubRepoLink
import com.interlinedlist.android.feature.lists.domain.ListSchema
import com.interlinedlist.android.feature.lists.domain.ListSource
import com.interlinedlist.android.feature.lists.domain.ListSummary
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
* The repository link under a GitHub-backed list's title, and its **Private repo**
* tag — which describes the repository's visibility on GitHub, never the list's.
*/
@RunWith(AndroidJUnit4::class)
class GithubRepoLinkRowTest {

@get:Rule
val composeRule = createComposeRule()

private fun setRow(isPrivate: Boolean?, onOpenRepo: (String) -> Unit = {}) {
composeRule.setContent {
InterlinedListTheme {
GithubRepoLinkRow(
repo = "octocat/Hello-World",
githubRepoPrivate = isPrivate,
onOpenRepo = onOpenRepo,
)
}
}
}

@Test
fun linksTheRepositoryIssuesPage() {
var opened: String? = null
setRow(isPrivate = false) { opened = it }

composeRule.onNodeWithTag(GithubRepoLinkTestTags.LINK).assertIsDisplayed()
composeRule.onNodeWithText("octocat/Hello-World issues").assertIsDisplayed()

composeRule.onNodeWithTag(GithubRepoLinkTestTags.LINK).performClick()
assertThat(opened).isEqualTo("https://github.com/octocat/Hello-World/issues")
}

@Test
fun showsThePrivateRepoTag_whenTheRepositoryIsPrivate() {
setRow(isPrivate = true)

composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).assertIsDisplayed()
composeRule.onNodeWithText(GithubRepoLink.PRIVATE_TAG).assertIsDisplayed()
}

@Test
fun theTagExplainsTheRepositoryIsPrivate_notTheList() {
setRow(isPrivate = true)

composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).performClick()

composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_EXPLANATION).assertIsDisplayed()
// The copy names the repository, and says the list's visibility is separate.
val explanation = GithubRepoLink.PRIVATE_TAG_EXPLANATION
assertThat(explanation).contains("This repository is private on GitHub")
assertThat(explanation).contains("separate from who can see this list")
composeRule.onNodeWithText(explanation).assertIsDisplayed()
}

@Test
fun showsNoTag_whenTheRepositoryIsPublic() {
setRow(isPrivate = false)

composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).assertDoesNotExist()
}

@Test
fun showsNoTag_whenTheRepositoryVisibilityIsNotYetKnown() {
// A list that has not synced since the tag existed: unknown is never
// presented as public, and it is never presented as private either.
setRow(isPrivate = null)

composeRule.onNodeWithTag(GithubRepoLinkTestTags.LINK).assertIsDisplayed()
composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).assertDoesNotExist()
}

@Test
fun rendersUnderTheTitleOfAGithubBackedListOnly() {
val githubList = ListSummary(
id = "L1",
title = "Repo issues",
description = null,
itemCount = 0,
folderId = null,
isPublic = false,
updatedAt = null,
parentId = null,
source = ListSource.GITHUB,
githubRepo = "octocat/Hello-World",
githubRepoPrivate = true,
)
composeRule.setContent {
InterlinedListTheme {
ListDetailScreen(
state = ListDetailUiState(
summary = githubList,
schema = ListSchema.EMPTY,
isLoading = false,
),
onBack = {},
onAddRow = {},
onEditRow = {},
onDeleteRow = {},
onDeleteList = {},
)
}
}

composeRule.onNodeWithTag(GithubRepoLinkTestTags.ROW).assertIsDisplayed()
composeRule.onNodeWithTag(GithubRepoLinkTestTags.PRIVATE_TAG).assertIsDisplayed()
// Refresh from GitHub is offered here and nowhere else.
composeRule.onNodeWithTag(ListDetailTestTags.REFRESH).assertIsDisplayed()
}

@Test
fun aLocalListShowsNoRepoLinkAndNoRefresh() {
composeRule.setContent {
InterlinedListTheme {
ListDetailScreen(
state = ListDetailUiState(
summary = ListSummary("L1", "Reading", null, 0, null, false, null),
schema = ListSchema.EMPTY,
isLoading = false,
),
onBack = {},
onAddRow = {},
onEditRow = {},
onDeleteRow = {},
onDeleteList = {},
)
}
}

composeRule.onNodeWithTag(GithubRepoLinkTestTags.ROW).assertDoesNotExist()
composeRule.onNodeWithTag(ListDetailTestTags.REFRESH).assertDoesNotExist()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ListsScreenTest {
onOpenConnections = {},
onSearchQueryChange = {},
onLoadMore = {},
onCreateList = {},
onNewList = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.interlinedlist.android.feature.lists.ui.list

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.interlinedlist.android.core.designsystem.theme.InterlinedListTheme
import com.interlinedlist.android.feature.lists.domain.GithubRepo
import com.interlinedlist.android.feature.lists.ui.github.GithubLinkProblem
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
* The "New list" sheet, in particular the GitHub half: picking a repository, and
* what a user without GitHub linked is shown instead of a broken picker.
*/
@RunWith(AndroidJUnit4::class)
class NewListSheetTest {

@get:Rule
val composeRule = createComposeRule()

private val helloWorld = GithubRepo("octocat", "Hello-World")
private val secretPlans = GithubRepo("acme", "secret-plans", isPrivate = true)

private fun setSheet(
state: NewListUiState,
onSelectRepo: (GithubRepo) -> Unit = {},
onOpenConnectedAccounts: () -> Unit = {},
) {
composeRule.setContent {
InterlinedListTheme {
NewListSheet(
state = state,
onSelectKind = {},
onTitleChange = {},
onPublicChange = {},
onRepoQueryChange = {},
onSelectRepo = onSelectRepo,
onSelectOrg = {},
onCreate = {},
onCancel = {},
onOpenConnectedAccounts = onOpenConnectedAccounts,
)
}
}
}

@Test
fun listsRepositories_andReportsTheOneThatIsPicked() {
var picked: GithubRepo? = null
setSheet(
NewListUiState(
kind = NewListKind.GITHUB,
repos = listOf(helloWorld, secretPlans),
),
onSelectRepo = { picked = it },
)

composeRule.onNodeWithTag(NewListTestTags.repo("octocat/Hello-World")).assertIsDisplayed()
composeRule.onNodeWithTag(NewListTestTags.repo("acme/secret-plans")).performClick()

assertThat(picked).isEqualTo(secretPlans)
}

@Test
fun explainsAnUnlinkedAccount_andRoutesToConnectedAccounts() {
var routed = false
setSheet(
NewListUiState(kind = NewListKind.GITHUB, linkProblem = GithubLinkProblem.NOT_LINKED),
onOpenConnectedAccounts = { routed = true },
)

composeRule.onNodeWithTag(NewListTestTags.LINK_PROBLEM).assertIsDisplayed()
// No picker at all, rather than an empty one.
composeRule.onNodeWithTag(NewListTestTags.REPO_SEARCH).assertDoesNotExist()
composeRule.onNodeWithTag(NewListTestTags.CREATE).assertIsNotEnabled()

composeRule.onNodeWithTag(NewListTestTags.LINK_ACTION).performClick()
assertThat(routed).isTrue()
}

@Test
fun explainsAnEmptyRepoList_asAnOrgApprovalProblem() {
setSheet(NewListUiState(kind = NewListKind.GITHUB, repos = emptyList()))

composeRule.onNodeWithTag(NewListTestTags.REPO_EMPTY).assertIsDisplayed()
}

@Test
fun theTitleFieldWaitsForARepositoryToBeChosen() {
setSheet(NewListUiState(kind = NewListKind.GITHUB, repos = listOf(helloWorld)))

// Nothing to title until there is a repository behind the list.
composeRule.onNodeWithTag(NewListTestTags.TITLE).assertDoesNotExist()
composeRule.onNodeWithTag(NewListTestTags.CREATE).assertIsNotEnabled()
}

@Test
fun theTitleFieldAppearsOnceARepositoryIsChosen() {
setSheet(
NewListUiState(
kind = NewListKind.GITHUB,
repos = listOf(helloWorld),
selectedRepo = helloWorld,
title = "Hello-World",
),
)

composeRule.onNodeWithTag(NewListTestTags.TITLE).assertIsDisplayed()
composeRule.onNodeWithTag(NewListTestTags.VISIBILITY).assertIsDisplayed()
}

@Test
fun aLocalListNeedsNoRepositoryPicker() {
setSheet(NewListUiState(kind = NewListKind.LOCAL, title = "Books"))

composeRule.onNodeWithTag(NewListTestTags.TITLE).assertIsDisplayed()
composeRule.onNodeWithTag(NewListTestTags.REPO_SEARCH).assertDoesNotExist()
composeRule.onNodeWithTag(NewListTestTags.LINK_PROBLEM).assertDoesNotExist()
}
}
Loading
Loading