Skip to content

Commit

Permalink
Added viewing the list of servers on Android [#3]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Feb 18, 2024
1 parent 3e51541 commit b2b3b4a
Show file tree
Hide file tree
Showing 12 changed files with 630 additions and 33 deletions.
1 change: 1 addition & 0 deletions androidVariant/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ android {
compileSdk = 34
defaultConfig {
applicationId = "org.comixedproject.variant.android"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
minSdk = 24
targetSdk = 34
versionCode = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Variant - A digital comic book reading application for the iPad and Android tablets.
* Copyright (C) 2024, The ComiXed Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

package org.comixedproject.variant.android.view.main

import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import org.comixedproject.variant.android.VariantTheme
import org.comixedproject.variant.model.OPDSServer
import org.junit.Rule
import org.junit.Test

class HomeViewKtTest {
val SERVER_LIST = listOf<OPDSServer>(
OPDSServer(
"1",
"Home Server",
"http://comixedproject.org:7171/opds",
"[email protected]",
"my!password"
)
)

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun testHomeViewHasTitle() {
composeTestRule.setContent {
VariantTheme {
HomeView(serverList = SERVER_LIST)
}
}

composeTestRule.onNodeWithTag(TAG_TITLE_TEXT).assertExists()
}

@Test
fun testHomeViewHasBottomBar() {
composeTestRule.setContent {
VariantTheme {
HomeView(serverList = SERVER_LIST)
}
}

composeTestRule.onNodeWithTag(TAG_BOTTOM_BAR).assertExists()
}

@Test
fun testHomeViewHasAddServerButton() {
composeTestRule.setContent {
VariantTheme {
HomeView(serverList = SERVER_LIST)
}
}

composeTestRule.onNodeWithTag(TAG_ADD_SERVER_BUTTON).assertExists()
}

@Test
fun testHomeViewHasAddServerList() {
composeTestRule.setContent {
VariantTheme {
HomeView(serverList = SERVER_LIST)
}
}

composeTestRule.onNodeWithTag(TAG_SERVER_LIST).assertExists()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Variant - A digital comic book reading application for the iPad and Android tablets.
* Copyright (C) 2024, The ComiXed Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

package org.comixedproject.variant.android.view.opds

import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import org.comixedproject.variant.android.VariantTheme
import org.comixedproject.variant.model.OPDSServer
import org.junit.Rule
import org.junit.Test

class ServerEntryKtTest {
val SERVER = OPDSServer(
"1",
"Home Server",
"http://comixedproject.org:7171/opds",
"[email protected]",
"my!password"
)

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun testServerEntryServerName() {
composeTestRule.setContent {
VariantTheme {
ServerEntry(server = SERVER)
}
}

composeTestRule.onNodeWithTag(TAG_SERVER_NAME).assertTextContains(SERVER.name)
}

@Test
fun testServerEntryServerUrl() {
composeTestRule.setContent {
VariantTheme {
ServerEntry(server = SERVER)
}
}

composeTestRule.onNodeWithTag(TAG_SERVER_URL).assertTextContains(SERVER.url)
}

@Test
fun testServerEntryUsername() {
composeTestRule.setContent {
VariantTheme {
ServerEntry(server = SERVER)
}
}

composeTestRule.onNodeWithTag(TAG_USERNAME).assertTextContains(SERVER.username)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Variant - A digital comic book reading application for the iPad and Android tablets.
* Copyright (C) 2024, The ComiXed Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

package org.comixedproject.variant.android.view.opds

import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import org.comixedproject.variant.android.VariantTheme
import org.comixedproject.variant.model.OPDSServer
import org.junit.Rule
import org.junit.Test

class ServerListKtTest {
val SERVER_LIST = listOf<OPDSServer>(
OPDSServer(
"1",
"Home Server",
"http://comixedproject.org:7171/opds",
"[email protected]",
"my!password"
)
)

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun testServerList() {
composeTestRule.setContent {
VariantTheme {
ServerList(serverList = SERVER_LIST)
}
}

composeTestRule.onNodeWithTag(TAG_SERVER_LIST_COLUMN).assertExists()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,54 @@ package org.comixedproject.variant.android
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import org.comixedproject.variant.Greeting
import org.comixedproject.variant.android.view.main.HomeView
import org.comixedproject.variant.model.OPDSServer

class MainActivity : ComponentActivity() {
val serverList = listOf(
OPDSServer(
"1",
"Server 1",
"http://comixedproject.org:7171/opds",
"[email protected]",
"my!password"
),
OPDSServer(
"2",
"Server 2",
"http://comixedproject.org:7171/opds",
"[email protected]",
"my!password"
),
OPDSServer(
"3",
"Server 3",
"http://comixedproject.org:7171/opds",
"[email protected]",
"my!password"
),
OPDSServer(
"4",
"Server 4",
"http://comixedproject.org:7171/opds",
"[email protected]",
"my!password"
),
OPDSServer(
"5",
"Server 5",
"http://comixedproject.org:7171/opds",
"[email protected]",
"my!password"
),
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
GreetingView(Greeting().greet())
}
VariantTheme {
HomeView(serverList)
}
}
}
}

@Composable
fun GreetingView(text: String) {
Text(text = text)
}

@Preview
@Composable
fun DefaultPreview() {
MyApplicationTheme {
GreetingView("Hello, Android!")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun MyApplicationTheme(
fun VariantTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
Expand Down
Loading

0 comments on commit b2b3b4a

Please sign in to comment.