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
Expand Up @@ -5,6 +5,8 @@ import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import org.junit.Rule
import org.junit.Test
import to.bitkit.models.widget.BlockModel
import to.bitkit.models.widget.BlocksPreferences
import to.bitkit.test.annotations.ComposeUi
import to.bitkit.ui.theme.AppThemeSurface

Expand All @@ -20,27 +22,23 @@ class BlockCardTest {
private val testTransactions = "2,175"
private val testSize = "1,606Kb"
private val testFees = "25 059 357"
private val testSource = "mempool.io"

private val fullBlock = BlockModel(
height = testBlock,
time = testTime,
date = testDate,
transactionCount = testTransactions,
size = testSize,
fees = testFees,
)

@Test
fun testBlockCardWithAllElements() {
fun testBlockCardWithDefaultFields() {
composeTestRule.setContent {
AppThemeSurface {
BlockCard(
showBlock = true,
showTime = true,
showDate = true,
showTransactions = true,
showSize = true,
showFees = true,
showSource = true,
block = testBlock,
time = testTime,
date = testDate,
transactions = testTransactions,
size = testSize,
fees = testFees,
source = testSource,
preferences = BlocksPreferences(),
block = fullBlock,
)
}
}
Expand All @@ -49,66 +47,58 @@ class BlockCardTest {
composeTestRule.onNodeWithTag("time_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("date_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("transactions_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("source_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertDoesNotExist()

composeTestRule.onNodeWithTag("block_text", useUnmergedTree = true).assertTextEquals(testBlock)
composeTestRule.onNodeWithTag("time_text", useUnmergedTree = true).assertTextEquals(testTime)
composeTestRule.onNodeWithTag("date_text", useUnmergedTree = true).assertTextEquals(testDate)
composeTestRule.onNodeWithTag("transactions_text", useUnmergedTree = true).assertTextEquals(testTransactions)
composeTestRule.onNodeWithTag("size_text", useUnmergedTree = true).assertTextEquals(testSize)
composeTestRule.onNodeWithTag("fees_text", useUnmergedTree = true).assertTextEquals(testFees)
composeTestRule.onNodeWithTag("source_text", useUnmergedTree = true).assertTextEquals(testSource)
}

@Test
fun testBlockCardWithoutSource() {
fun testBlockCardWithSizeAndFees() {
composeTestRule.setContent {
AppThemeSurface {
BlockCard(
showBlock = true,
showTime = true,
showDate = true,
showTransactions = true,
showSize = true,
showFees = true,
showSource = false,
block = testBlock,
time = testTime,
date = testDate,
transactions = testTransactions,
size = testSize,
fees = testFees,
source = testSource,
preferences = BlocksPreferences(
showBlock = true,
showTime = true,
showDate = false,
showTransactions = false,
showSize = true,
showFees = true,
),
block = fullBlock,
)
}
}

composeTestRule.onNodeWithTag("block_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("source_row", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("source_text", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("time_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertExists()
composeTestRule.onNodeWithTag("date_row", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("transactions_row", useUnmergedTree = true).assertDoesNotExist()

composeTestRule.onNodeWithTag("size_text", useUnmergedTree = true).assertTextEquals(testSize)
composeTestRule.onNodeWithTag("fees_text", useUnmergedTree = true).assertTextEquals(testFees)
}

@Test
fun testBlockCardWithoutFees() {
composeTestRule.setContent {
AppThemeSurface {
BlockCard(
showBlock = true,
showTime = true,
showDate = true,
showTransactions = true,
showSize = true,
showFees = false,
showSource = true,
block = testBlock,
time = testTime,
date = testDate,
transactions = testTransactions,
size = testSize,
fees = testFees,
source = testSource,
preferences = BlocksPreferences(
showBlock = true,
showTime = true,
showDate = true,
showTransactions = false,
showSize = false,
showFees = false,
),
block = fullBlock,
)
}
}
Expand All @@ -123,20 +113,22 @@ class BlockCardTest {
composeTestRule.setContent {
AppThemeSurface {
BlockCard(
showBlock = true,
showTime = false,
showDate = false,
showTransactions = false,
showSize = false,
showFees = false,
showSource = false,
block = testBlock,
time = "",
date = "",
transactions = "",
size = "",
fees = "",
source = "",
preferences = BlocksPreferences(
showBlock = true,
showTime = false,
showDate = false,
showTransactions = false,
showSize = false,
showFees = false,
),
block = BlockModel(
height = testBlock,
time = "",
date = "",
transactionCount = "",
size = "",
fees = "",
),
)
}
}
Expand All @@ -147,28 +139,22 @@ class BlockCardTest {
composeTestRule.onNodeWithTag("transactions_row", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("source_row", useUnmergedTree = true).assertDoesNotExist()
}

@Test
fun testBlockCardWithEmptyValues() {
composeTestRule.setContent {
AppThemeSurface {
BlockCard(
showBlock = true,
showTime = true,
showDate = true,
showTransactions = true,
showSize = true,
showFees = true,
showSource = true,
block = "",
time = "",
date = "",
transactions = "",
size = "",
fees = "",
source = "",
preferences = BlocksPreferences(),
block = BlockModel(
height = "",
time = "",
date = "",
transactionCount = "",
size = "",
fees = "",
),
)
}
}
Expand All @@ -179,28 +165,15 @@ class BlockCardTest {
composeTestRule.onNodeWithTag("transactions_row", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("size_row", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("fees_row", useUnmergedTree = true).assertDoesNotExist()
composeTestRule.onNodeWithTag("source_row", useUnmergedTree = true).assertDoesNotExist()
}

@Test
fun testBlockCardSmallWithAllElements() {
fun testBlockCardSmallWithDefaultFields() {
composeTestRule.setContent {
AppThemeSurface {
BlockCardSmall(
showBlock = true,
showTime = true,
showDate = true,
showTransactions = true,
showSize = true,
showFees = true,
showSource = true,
block = testBlock,
time = testTime,
date = testDate,
transactions = testTransactions,
size = testSize,
fees = testFees,
source = testSource,
preferences = BlocksPreferences(),
block = fullBlock,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ fun AppWidgetConfigScreen(

AppWidgetType.BLOCKS -> BlocksConfigContent(
state = state,
onToggleBlock = { viewModel.toggleBlockShowBlock() },
onToggleTime = { viewModel.toggleBlockShowTime() },
onToggleDate = { viewModel.toggleBlockShowDate() },
onToggleTransactions = { viewModel.toggleBlockShowTransactions() },
onToggleSize = { viewModel.toggleBlockShowSize() },
onToggleFees = { viewModel.toggleBlockShowFees() },
onToggleSource = { viewModel.toggleBlockShowSource() },
onToggleField = { viewModel.toggleBlockField(it) },
onReset = { viewModel.resetPreferences() },
onSave = { viewModel.saveAndFinish(onConfirm) },
onCancel = onCancel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import to.bitkit.data.dto.price.GraphPeriod
import to.bitkit.data.dto.price.TradingPair
import to.bitkit.models.widget.ArticleModel
import to.bitkit.models.widget.BlocksPreferences
import to.bitkit.models.widget.BlocksWidgetField
import to.bitkit.models.widget.toggleField
import to.bitkit.models.widget.HeadlinePreferences
import to.bitkit.models.widget.PricePreferences
import to.bitkit.models.widget.WeatherDataOption
Expand Down Expand Up @@ -118,49 +120,9 @@ class AppWidgetConfigViewModel @Inject constructor(
}
}

fun toggleBlockShowBlock() {
fun toggleBlockField(field: BlocksWidgetField) {
_uiState.update {
it.copy(blocksPreferences = it.blocksPreferences.copy(showBlock = !it.blocksPreferences.showBlock))
}
}

fun toggleBlockShowTime() {
_uiState.update {
it.copy(blocksPreferences = it.blocksPreferences.copy(showTime = !it.blocksPreferences.showTime))
}
}

fun toggleBlockShowDate() {
_uiState.update {
it.copy(blocksPreferences = it.blocksPreferences.copy(showDate = !it.blocksPreferences.showDate))
}
}

fun toggleBlockShowTransactions() {
_uiState.update {
it.copy(
blocksPreferences = it.blocksPreferences.copy(
showTransactions = !it.blocksPreferences.showTransactions,
),
)
}
}

fun toggleBlockShowSize() {
_uiState.update {
it.copy(blocksPreferences = it.blocksPreferences.copy(showSize = !it.blocksPreferences.showSize))
}
}

fun toggleBlockShowFees() {
_uiState.update {
it.copy(blocksPreferences = it.blocksPreferences.copy(showFees = !it.blocksPreferences.showFees))
}
}

fun toggleBlockShowSource() {
_uiState.update {
it.copy(blocksPreferences = it.blocksPreferences.copy(showSource = !it.blocksPreferences.showSource))
it.copy(blocksPreferences = it.blocksPreferences.toggleField(field))
}
}

Expand Down Expand Up @@ -307,7 +269,6 @@ private fun HomeBlocksPreferences.toInApp() = BlocksPreferences(
showTransactions = showTransactions,
showSize = showSize,
showFees = showFees,
showSource = showSource,
)

private fun BlocksPreferences.toHome() = HomeBlocksPreferences(
Expand All @@ -317,7 +278,6 @@ private fun BlocksPreferences.toHome() = HomeBlocksPreferences(
showTransactions = showTransactions,
showSize = showSize,
showFees = showFees,
showSource = showSource,
)

private fun HomeWeatherPreferences.toInApp() = WeatherPreferences(selectedOption = selectedOption)
Expand Down
Loading
Loading