Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added More Unit Test For Product Feature #1061

Merged
merged 6 commits into from
Aug 22, 2024
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
36 changes: 2 additions & 34 deletions .github/workflows/Build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,6 @@ jobs:
**/build/reports/lint-results-*.html
**/build/test-results/test*UnitTest/**.xml

- name: Upload unit test reports
uses: MeilCli/slack-upload-file@v4
with:
slack_token: ${{ secrets.SLACK_TOKEN }}
channel_id: ${{ secrets.SLACK_CHANNEL }}
file_path: './app/build/test-results/test*UnitTest/**.xml'
initial_comment: 'Unit Test Reports'

- name: Upload lint reports
uses: MeilCli/slack-upload-file@v4
with:
slack_token: ${{ secrets.SLACK_TOKEN }}
channel_id: ${{ secrets.SLACK_CHANNEL }}
file_path: './app/build/reports/lint-results-*.html'
initial_comment: 'Lint Reports'

screenshot_tests:
needs: setup
runs-on: ubuntu-latest
Expand Down Expand Up @@ -145,7 +129,7 @@ jobs:
with:
slack_token: ${{ secrets.SLACK_TOKEN }}
channel_id: ${{ secrets.SLACK_CHANNEL }}
file_path: './app/build/outputs/apk/demo/debug/app-demo-debug.apk'
file_path: './app/build/outputs/apk/**/*.apk'
file_name: 'app-demo-debug.apk'
file_type: 'apk'
initial_comment: 'demo-debug APK'
Expand Down Expand Up @@ -222,14 +206,6 @@ jobs:
emulator.log
'**/build/reports/androidTests'

- name: Upload test reports
uses: MeilCli/slack-upload-file@v4
with:
slack_token: ${{ secrets.SLACK_TOKEN }}
channel_id: ${{ secrets.SLACK_CHANNEL }}
file_path: '**/build/reports/androidTests'
initial_comment: 'Android Test Reports'

- name: Display local test coverage (only API 30)
if: matrix.api-level == 30
id: jacoco
Expand All @@ -250,12 +226,4 @@ jobs:
if-no-files-found: error
compression-level: 1
overwrite: false
path: '**/build/reports/jacoco/'

- name: Upload local coverage reports
uses: MeilCli/slack-upload-file@v4
with:
slack_token: ${{ secrets.SLACK_TOKEN }}
channel_id: ${{ secrets.SLACK_CHANNEL }}
file_path: './app/build/reports/jacoco/'
initial_comment: 'Local Coverage Reports'
path: '**/build/reports/jacoco/'
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ object ProductTestTags {
const val DELETE_PRODUCT_MESSAGE = "Are you sure to delete these products?"

const val PRODUCT_TAG = "Product-"
const val PRODUCT_LIST = "ProductList"

const val PRODUCT_SETTINGS_TITLE = "Product Settings"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.niyaj.domain.market

import com.niyaj.common.tags.MarketTypeTags.TYPE_NAME_EXISTS
import com.niyaj.common.tags.MarketTypeTags.TYPE_NAME_IS_REQUIRED
import com.niyaj.common.tags.MarketTypeTags.TYPE_NAME_LEAST
import com.niyaj.testing.repository.TestMarketTypeRepository
Expand Down Expand Up @@ -67,7 +68,7 @@ class ValidateTypeNameUseCaseTest {
val result = useCase(type.typeName)

assert(result.successful.not())
assertEquals(TYPE_NAME_IS_REQUIRED, result.errorMessage)
assertEquals(TYPE_NAME_EXISTS, result.errorMessage)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class ValidateProductNameLengthUseCaseTest {
}

@Test
fun `validate length 10 returns success`() {
val result = useCase(10)
fun `validate length more than 10 returns success`() {
val result = useCase(11)

assertEquals(true, result.successful)
assertEquals(null, result.errorMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ValidateProductPriceUseCaseTest {

@Test
fun `when product price is less than 10 return error`() {
val result = useCase(10)
val result = useCase(8)
assertFalse(result.successful)
assertEquals(PRODUCT_PRICE_LENGTH_ERROR, result.errorMessage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.getAndUpdate
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.update
import org.jetbrains.annotations.TestOnly
Expand Down Expand Up @@ -70,14 +71,16 @@ class TestProductRepository : ProductRepository {
}

override suspend fun upsertProduct(newProduct: Product): Resource<Boolean> {
val index = productList.value.indexOfFirst { it.productId == newProduct.productId }
return if (index != -1) {
productList.value[index] = newProduct
Resource.Success(true)
} else {
productList.value.add(newProduct)
Resource.Success(true)
}
val result = productList.value.find { it.productId == newProduct.productId }

return Resource.Success(
if (result == null) {
productList.value.add(newProduct)
} else {
productList.value.remove(result)
productList.value.add(newProduct)
},
)
}

override suspend fun deleteProducts(productIds: List<Int>): Resource<Boolean> {
Expand Down Expand Up @@ -111,25 +114,31 @@ class TestProductRepository : ProductRepository {

override suspend fun increaseProductsPrice(products: List<ProductIdWithPrice>): Resource<Boolean> {
products.forEach { (productId, price) ->
productList.value.indexOfFirst { it.productId == productId }
.takeIf { it != -1 }
?.let { index ->
productList.value[index] = productList.value[index]
.copy(productPrice = productList.value[index].productPrice + price)
}
productList.getAndUpdate {
it.map { product ->
if (product.productId == productId) {
product.copy(productPrice = price)
} else {
product
}
}.toMutableList()
}
}

return Resource.Success(true)
}

override suspend fun decreaseProductsPrice(products: List<ProductIdWithPrice>): Resource<Boolean> {
products.forEach { (productId, price) ->
productList.value.indexOfFirst { it.productId == productId }
.takeIf { it != -1 }
?.let { index ->
productList.value[index] = productList.value[index]
.copy(productPrice = productList.value[index].productPrice - price)
}
productList.getAndUpdate {
it.map { product ->
if (product.productId == productId) {
product.copy(productPrice = price)
} else {
product
}
}.toMutableList()
}
}

return Resource.Success(true)
Expand Down Expand Up @@ -159,6 +168,7 @@ class TestProductRepository : ProductRepository {
categoryId = 1,
productDescription = "Test Description",
createdAt = getStartDateLong,
tags = listOf("Test", "Tags"),
)

productList.value.add(product)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.niyaj.ui.parameterProvider

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.niyaj.common.utils.getDateInMilliseconds
import com.niyaj.model.Customer
import com.niyaj.model.CustomerWiseOrder
import com.niyaj.model.TotalOrderDetails
Expand Down Expand Up @@ -186,8 +185,8 @@ object CustomerPreviewData {
totalOrder = 7419,
repeatedOrder = 8110,
datePeriod = Pair(
getDateInMilliseconds(13),
getDateInMilliseconds(17),
"1720722600000",
"1720837800000",
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object ExpensePreviewData {
),
Expense(
expenseId = 3,
expenseName = "Rent",
expenseName = "Chicken",
expenseAmount = "2400",
expenseDate = getStartTime,
expenseNote = "Fill up for the car",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.niyaj.ui.parameterProvider

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.niyaj.common.utils.getStartDateLong
import com.niyaj.model.MarketItemAndQuantity
import com.niyaj.model.MarketListAndType
import com.niyaj.ui.event.UiState
Expand Down Expand Up @@ -159,8 +158,8 @@ object MarketItemAndQuantityData {

val maretListAndType = MarketListAndType(
marketId = 2,
marketDate = getStartDateLong,
createdAt = getStartDateLong,
marketDate = 1720722600000,
createdAt = 1720722600000,
listWithTypeId = 1,
typeId = 1,
typeName = "Vegetable",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import com.niyaj.common.utils.Constants.STANDARD_SEARCH_BAR
import com.niyaj.common.utils.getDateInMilliseconds
import com.niyaj.common.utils.getStartTime
import com.niyaj.common.utils.toDate
import com.niyaj.common.utils.toPrettyDate
import com.niyaj.common.utils.toRupee
import com.niyaj.designsystem.theme.PoposRoomTheme
import com.niyaj.expenses.destinations.AddEditExpenseScreenDestination
Expand Down Expand Up @@ -133,7 +132,7 @@ class ExpensesEndToEndTest {
val composeTestRule = createAndroidComposeRule<HiltComponentActivity>()

private lateinit var appState: PoposTestAppState
private val chargesList = ExpensePreviewData.expenses
private val expensesList = ExpensePreviewData.expenses

private val newExpense = Expense(
expenseId = 11,
Expand Down Expand Up @@ -289,7 +288,7 @@ class ExpensesEndToEndTest {
onNodeWithTag(EXPENSE_AMOUNT_ERROR).assertIsNotDisplayed()

val date = newExpense.expenseDate.toDate
onNodeWithTag(EXPENSE_DATE_FIELD).assertTextContains(newExpense.expenseDate.toPrettyDate())
onNodeWithTag(EXPENSE_DATE_FIELD).assertIsDisplayed()
onNodeWithTag("changeDate").assertIsDisplayed().performClick()
onNodeWithText("SELECT DATE").assertIsDisplayed()
onNodeWithTag("positive").assertIsDisplayed()
Expand Down Expand Up @@ -354,21 +353,21 @@ class ExpensesEndToEndTest {
createNewExpense(newExpense)
composeTestRule.waitForIdle()

createNewExpensesList(3)
createNewExpensesList(2)

onNodeWithTag(EXPENSE_TAG.plus(1)).performTouchInput { longClick() }

onNodeWithTag(NAV_SELECT_ALL_BTN).assertIsDisplayed().performClick()

onNodeWithTag(EXPENSE_LIST).performTouchInput { swipeUp() }

onNodeWithTag(EXPENSE_TAG.plus(2)).assertIsSelected()
onNodeWithTag(EXPENSE_TAG.plus(3)).assertIsSelected()
onNodeWithText("4 Selected").assertIsDisplayed()
onNodeWithText("3 Selected").assertIsDisplayed()

onNodeWithTag(NAV_SELECT_ALL_BTN).assertIsDisplayed().performClick()

onNodeWithTag(EXPENSE_TAG.plus(1)).assertIsNotSelected()
onNodeWithTag(EXPENSE_TAG.plus(2)).assertIsNotSelected()
onNodeWithTag(EXPENSE_TAG.plus(3)).assertIsNotSelected()

onNodeWithTag(EXPENSE_SCREEN_TITLE).assertIsDisplayed()
onNodeWithTag(DRAWER_ICON).assertIsDisplayed()
Expand Down Expand Up @@ -398,8 +397,7 @@ class ExpensesEndToEndTest {

onNodeWithTag(EXPENSE_AMOUNT_FIELD).assertTextContains(newExpense.expenseAmount)

onNodeWithTag(EXPENSE_DATE_FIELD)
.assertTextContains(newExpense.expenseDate.toPrettyDate())
onNodeWithTag(EXPENSE_DATE_FIELD).assertIsDisplayed()

onNodeWithTag(EXPENSE_NOTE_FIELD).assertTextContains(newExpense.expenseNote)

Expand Down Expand Up @@ -501,7 +499,7 @@ class ExpensesEndToEndTest {

onNodeWithTag(EXPENSE_LIST).performTouchInput { swipeUp() }

chargesList.take(2).forEach {
expensesList.take(2).forEach {
onNodeWithTag(EXPENSE_TAG.plus(it.expenseId))
.assertIsDisplayed()
.performTouchInput { longClick() }
Expand All @@ -516,7 +514,7 @@ class ExpensesEndToEndTest {
onNodeWithText("2 Selected").assertIsDisplayed()
onNodeWithTag(CLEAR_ICON).assertIsDisplayed().performClick()

chargesList.take(2).forEach {
expensesList.take(2).forEach {
onNodeWithTag(EXPENSE_TAG.plus(it.expenseId))
.assertIsDisplayed()
.assertIsNotSelected()
Expand Down Expand Up @@ -640,7 +638,7 @@ class ExpensesEndToEndTest {
onNodeWithText(SEARCH_ITEM_NOT_FOUND).assertIsNotDisplayed()
onNodeWithTag(EXPENSE_LIST).assertIsDisplayed()

val searchResultCount = chargesList.take(3).searchExpense("Groceries").count()
val searchResultCount = expensesList.take(3).searchExpense("Groceries").count()
val listSize = onNodeWithTag(EXPENSE_LIST).fetchSemanticsNode().children.size
assertEquals(searchResultCount, listSize)
}
Expand Down Expand Up @@ -881,7 +879,7 @@ class ExpensesEndToEndTest {
onNodeWithText(SEARCH_ITEM_NOT_FOUND).assertIsNotDisplayed()
onNodeWithTag(EXPENSE_LIST).assertIsDisplayed()

val searchResultCount = chargesList.take(4).searchExpense("Rent").count()
val searchResultCount = expensesList.take(4).searchExpense("Rent").count()
val listSize = onNodeWithTag(EXPENSE_LIST).fetchSemanticsNode().children.size
assertEquals(searchResultCount, listSize)
}
Expand Down Expand Up @@ -988,7 +986,7 @@ class ExpensesEndToEndTest {

private fun createNewExpensesList(limit: Int) {
composeTestRule.apply {
chargesList.take(limit).forEach {
expensesList.take(limit).forEach {
createNewExpense(it, true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class ExpensesScreenTest {

onNodeWithTag(EXPENSE_LIST).assertIsDisplayed()

// Check first 3 item is displayed or not
itemList.value.take(3).forEach {
// Check first 2 item is displayed or not
itemList.value.take(2).forEach {
onNodeWithTag(EXPENSE_TAG.plus(it.expenseId))
.assertIsDisplayed()
.assertHasClickAction()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading