Tp 44780 home loan close loan fragment vm test cases (#8764)

This commit is contained in:
Saurabh Chaudhary
2023-11-24 14:37:33 +05:30
committed by GitHub
parent a179faff08
commit 6b18df6473
3 changed files with 562 additions and 232 deletions

View File

@@ -96,134 +96,277 @@
"navigationHeader": {
"iconCode": "ICON_ARROW_LEFT_BLUE",
"backCta": {
"url": "hl/homeLoanIntro",
"parameters": [],
"url": "hl/homeLoanSteps/HL_WIDGETIZED_INFO",
"parameters": [
{
"key": "action",
"value": "GENERATE_SL"
},
{
"key": "loanApplicationId",
"value": "63bd7b1b-e621-46fb-8f14-4ff5353dc7b3"
},
{
"key": "loanActionType",
"value": "HL_NEW"
},
{
"key": "customerReferenceId",
"value": "facb981f-dd07-4757-a2bc-03b971d3b287"
}
],
"analyticsEventProperties": {
"name": "",
"properties": {}
"name": "New_HL_Top_Back_Button_Clicked",
"properties": {
"screenName": "Declare_Closed_Loan_Service"
}
}
},
"centerText": "Home Loan",
"helpBottomSheet": {
"title": {
"text": "Need Help?",
"textColor": "#1A1A1A",
"size": 18,
"font": "NAVI_BOLD",
"maskForAlfred": false
},
"helpItems": [
{
"startIcon": {
"iconCode": "ICON_HL_HELP_FAQ",
"iconHeight": "16",
"iconWidth": "16"
},
"title": {
"text": "FAQs",
"textColor": "#000000",
"size": 14,
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"ctaData": {
"url": "menu/faq",
"parameters": [
{
"key": "product",
"value": "LE"
},
{
"key": "subProduct",
"value": "HL"
}
]
}
},
{
"startIcon": {
"iconCode": "ICON_HL_HELP_CHAT",
"iconHeight": "16",
"iconWidth": "16"
},
"title": {
"text": "Chat with us",
"textColor": "#000000",
"size": 14,
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"ctaData": {
"url": "chatInHouse",
"parameters": [
{
"key": "CHAT_BOT_SCREEN_NAME",
"value": "HL_BANK_SELECTION_SCREEN"
},
{
"key": "CHAT_BOT_SOURCE_ID",
"value": "DEFAULT_HL"
}
],
"analyticsEventProperties": {
"name": "New_HL_Help_Option_Click",
"properties": {
"option": "Chat",
"screenName": "Declare_Closed_Loans"
}
}
}
},
{
"startIcon": {
"iconCode": "ICON_HL_HELP_EMAIL",
"iconHeight": "16",
"iconWidth": "16"
},
"title": {
"text": "Send E-mail",
"textColor": "#000000",
"size": 14,
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"ctaData": {
"url": "emailV2",
"parameters": [
{
"key": "product",
"value": "home"
}
],
"analyticsEventProperties": {
"name": "New_HL_Help_Option_Click",
"properties": {
"option": "Email",
"screenName": "Declare_Closed_Loans"
}
}
}
}
]
}
}
},
"content": {
"screenTitle": {
"text": "Improve your loan offer",
"font": "NAVI_BOLD",
"textColor": "#191919",
"size": 18,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
},
"graphData": {
"currentOfferLabel": {
"text": "Current loan offer",
"font": "NAVI_SEMI_BOLD",
"lockedOfferLabel": {
"text": "Select more loans to get an offer",
"textColor": "#6B6B6B",
"size": 12,
"textColor": "#1A1A1A"
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"currentOfferLabel": {
"text": "Current offer",
"textColor": "#1A1A1A",
"size": 12,
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"maxOfferLabel": {
"text": "Loan offer you can avail",
"font": "NAVI_SEMI_BOLD",
"textColor": "#1A1A1A",
"size": 12,
"textColor": "#1A1A1A"
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"currentOfferText": "AMOUNT_IN_TEXT",
"maxOfferText": "Upto AMOUNT_IN_TEXT",
"defaultVisibility": "SHOW",
"currentOffer": 2010100,
"maxOffer": 2110100
"currentOfferText": "AMOUNT_IN_TEXT",
"maxOfferText": "Upto AMOUNT_IN_TEXT",
"maxOfferAvailedText": "Max loan offer availed",
"currentOffer": 3560000,
"maxOffer": 3770000,
"minEmiThresholdForApproval": -21656,
"endIcon": {
"iconCode": "ICON_HL_GREY_LOCK",
"iconHeight": "18",
"iconWidth": "18"
}
},
"widgets": [
{
"widgetId": "NikhilKumar5",
"widgetId": "titleSubtitleSelectedCountWidget",
"widgetName": "TITLE_SUBTITLE_SELECTED_COUNT_WIDGET",
"widgetData": {
"title": {
"text": "Open Loans",
"font": "NAVI_BOLD",
"textColor": "#191919",
"size": 16,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
},
"subTitle": {
"text": "Select your closed loans or loans closing within the next 12 months",
"font": "NAVI_REGULAR",
"text": "Select your closed loans or loans closing within next 12 months",
"textColor": "#6B6B6B",
"size": 12,
"textColor": "#6B6B6B"
"font": "NAVI_REGULAR",
"maskForAlfred": false
},
"titleIcon": {
"iconCode": "GREY_DARK_INFO_ICON",
"iconHeight": "12",
"iconWidth": "12"
}
},
"isNewWidget": true
}
},
{
"widgetId": "NikhilKumar6",
"widgetId": "5:1:2018-07-13:1200000",
"widgetName": "LOAN_ITEM_WITH_CHECKBOX_DOCUMENT_WIDGET",
"widgetLayoutParams": {
"margin": "12,12,12,12"
},
"widgetData": {
"headerBGColor": "#F3F3FF",
"bodyBGColor": "#FFFFFF",
"bodyBGColor": "#ffffff",
"headerStartTitle": {
"text": "Impact of closing this loan",
"font": "NAVI_REGULAR",
"textColor": "#444444",
"size": 12,
"textColor": "#444444"
"font": "NAVI_REGULAR",
"maskForAlfred": false
},
"incrementText": {
"text": "₹0.5 Cr",
"font": "NAVI_BOLD",
"text": "Upto ₹ 2.1 Lakhs",
"textColor": "#191919",
"size": 12,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
},
"title": {
"text": "Personal loan",
"font": "NAVI_BOLD",
"text": "Personal Loan",
"textColor": "#191919",
"size": 16,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
},
"obligationId": "PL-03-2022",
"incrementAmount": 100000,
"obligationId": "5:1:2018-07-13:1200000",
"incrementAmount": 210000,
"emiAmount": 1719,
"keyValueFields": [
{
"label": {
"key": {
"text": "Loan amount",
"font": "NAVI_REGULAR",
"textColor": "#6B6B6B",
"size": 12,
"textColor": "#6B6B6B"
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"value": {
"text": "₹18 lakh",
"font": "NAVI_REGULAR",
"text": "₹ 12 Lakhs",
"textColor": "#444444",
"size": 12,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
}
},
{
"label": {
"key": {
"text": "Loan start date",
"font": "NAVI_REGULAR",
"textColor": "#6B6B6B",
"size": 12,
"textColor": "#6B6B6B"
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"value": {
"text": "10 Jul, 2022",
"font": "NAVI_REGULAR",
"text": "13th Jul 2018",
"textColor": "#444444",
"size": 12,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
}
}
],
"documentUploadOption": {
"text": "+ Add Document",
"textColor": "#FF3333",
"font": "NAVI_BOLD",
"text": "Add Document",
"size": 14,
"font": "NAVI_BOLD",
"textColor": "#FF5732",
"cta": {
"url": "homeLoanPostEligibilityV2/HL_UPLOAD_DOCUMENT",
"url": "hl/homeLoanSteps/HL_DOCUMENT_UPLOAD_SCREEN",
"parameters": [
{
"key": "documentType",
@@ -231,90 +374,105 @@
},
{
"key": "contextKey",
"value": "PL-03-2022"
"value": "5:1:2018-07-13:1200000"
},
{
"key": "loanApplicationId",
"value": "cc25a52e-3042-4b14-9782-fcbd6776d7c1"
"value": "63bd7b1b-e621-46fb-8f14-4ff5353dc7b3"
}
]
}
},
"textDrawableData": {
"left": {
"iconCode": "ICON_EXTRA_SMALL_ORANGE_PLUS"
}
},
"isSelected": false
},
"supportText": {
"text": "(Optional)",
"textColor": "#A8A8A8",
"font": "NAVI_SEMI_BOLD",
"size": 14
"textColor": "#A3A3AB",
"isSelected": false
},
"isNewWidget": true,
"isSelected": false
},
"widgetLayoutParams": {
"margin": "12,8,12,8",
"strokeWidth": 0
}
},
{
"widgetId": "NikhilKumar7",
"widgetId": "2:4:2023-03-21:7000",
"widgetName": "LOAN_ITEM_WITH_CHECKBOX_DOCUMENT_WIDGET",
"widgetLayoutParams": {
"margin": "12,12,12,12"
},
"widgetData": {
"headerBGColor": "#F3F3FF",
"bodyBGColor": "#FFFFFF",
"bodyBGColor": "#ffffff",
"headerStartTitle": {
"text": "Impact of closing this loan",
"font": "NAVI_REGULAR",
"textColor": "#444444",
"size": 12,
"textColor": "#444444"
"font": "NAVI_REGULAR",
"maskForAlfred": false
},
"incrementText": {
"text": "₹0.5 Cr",
"font": "NAVI_BOLD",
"text": "Upto ₹ 11000",
"textColor": "#191919",
"size": 12,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
},
"title": {
"text": "Personal loan",
"font": "NAVI_BOLD",
"text": "Housing Loan",
"textColor": "#191919",
"size": 16,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
},
"obligationId": "PL-03-2022",
"incrementAmount": 100000,
"obligationId": "2:4:2023-03-21:7000",
"incrementAmount": 11000,
"emiAmount": 89,
"keyValueFields": [
{
"label": {
"key": {
"text": "Loan amount",
"font": "NAVI_REGULAR",
"textColor": "#6B6B6B",
"size": 12,
"textColor": "#6B6B6B"
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"value": {
"text": "₹18 lakh",
"font": "NAVI_REGULAR",
"text": "₹ 7000",
"textColor": "#444444",
"size": 12,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
}
},
{
"label": {
"key": {
"text": "Loan start date",
"font": "NAVI_REGULAR",
"textColor": "#6B6B6B",
"size": 12,
"textColor": "#6B6B6B"
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"value": {
"text": "10 Jul, 2022",
"font": "NAVI_REGULAR",
"text": "21st Mar 2023",
"textColor": "#444444",
"size": 12,
"textColor": "#191919"
"font": "NAVI_BOLD",
"maskForAlfred": false
}
}
],
"documentUploadOption": {
"text": "+ Add Document",
"textColor": "#FF3333",
"font": "NAVI_BOLD",
"text": "Add Document",
"size": 14,
"font": "NAVI_BOLD",
"textColor": "#FF5732",
"cta": {
"url": "homeLoanPostEligibilityV2/HL_UPLOAD_DOCUMENT",
"url": "hl/homeLoanSteps/HL_DOCUMENT_UPLOAD_SCREEN",
"parameters": [
{
"key": "documentType",
@@ -322,113 +480,32 @@
},
{
"key": "contextKey",
"value": "PL-03-2022"
"value": "2:4:2023-03-21:7000"
},
{
"key": "loanApplicationId",
"value": "cc25a52e-3042-4b14-9782-fcbd6776d7c1"
"value": "63bd7b1b-e621-46fb-8f14-4ff5353dc7b3"
}
]
}
},
"supportText": {
"text": "(Optional)",
"textColor": "#A8A8A8",
"font": "NAVI_SEMI_BOLD",
"size": 14
},
"isSelected": false
}
},
{
"widgetId": "NikhilKumar8",
"widgetName": "LOAN_ITEM_WITH_CHECKBOX_DOCUMENT_WIDGET",
"widgetLayoutParams": {
"margin": "12,12,12,12"
},
"widgetData": {
"headerBGColor": "#F3F3FF",
"bodyBGColor": "#FFFFFF",
"headerStartTitle": {
"text": "Impact of closing this loan",
"font": "NAVI_REGULAR",
"size": 12,
"textColor": "#444444"
},
"incrementText": {
"text": "₹0.5 Cr",
"font": "NAVI_BOLD",
"size": 12,
"textColor": "#191919"
},
"title": {
"text": "Personal loan",
"font": "NAVI_BOLD",
"size": 16,
"textColor": "#191919"
},
"obligationId": "PL-03-2022",
"incrementAmount": 100000,
"keyValueFields": [
{
"label": {
"text": "Loan amount",
"font": "NAVI_REGULAR",
"size": 12,
"textColor": "#6B6B6B"
},
"value": {
"text": "₹18 lakh",
"font": "NAVI_REGULAR",
"size": 12,
"textColor": "#191919"
},
"textDrawableData": {
"left": {
"iconCode": "ICON_EXTRA_SMALL_ORANGE_PLUS"
}
},
{
"label": {
"text": "Loan start date",
"font": "NAVI_REGULAR",
"size": 12,
"textColor": "#6B6B6B"
},
"value": {
"text": "10 Jul, 2022",
"font": "NAVI_REGULAR",
"size": 12,
"textColor": "#191919"
}
}
],
"documentUploadOption": {
"text": "+ Add Document",
"textColor": "#FF3333",
"font": "NAVI_BOLD",
"size": 14,
"cta": {
"url": "homeLoanPostEligibilityV2/HL_UPLOAD_DOCUMENT",
"parameters": [
{
"key": "documentType",
"value": "HL_LOAN_CLOSURE_DOCUMENT"
},
{
"key": "contextKey",
"value": "PL-03-2022"
},
{
"key": "loanApplicationId",
"value": "cc25a52e-3042-4b14-9782-fcbd6776d7c1"
}
]
}
"isSelected": false
},
"supportText": {
"text": "(Optional)",
"textColor": "#A8A8A8",
"font": "NAVI_SEMI_BOLD",
"size": 14
"textColor": "#A3A3AB",
"isSelected": false
},
"isNewWidget": true,
"isSelected": false
},
"widgetLayoutParams": {
"margin": "12,8,12,8",
"strokeWidth": 0
}
}
],
@@ -436,23 +513,19 @@
"iconCode": "ICON_BLUE_BORDER_ALERT",
"title": {
"text": "Open Loans",
"size": 18,
"font": "NAVI_BOLD",
"size": 18
"maskForAlfred": false
},
"subTitle": {
"text": "Based on the data provided by you, we have auto-fetched your loan history. You can improve your offer by closing some of your loans.",
"size": 14,
"font": "NAVI_SEMI_BOLD",
"size": 14
"maskForAlfred": false
},
"footer": {
"cta": {
"title": "Okay",
"url": "",
"parameters": [],
"analyticsEventProperties": {
"name": "",
"properties": {}
}
"title": "Okay"
}
}
},
@@ -460,13 +533,15 @@
"iconCode": "ICON_BLUE_BORDER_ALERT",
"title": {
"text": "Add Document",
"size": 18,
"font": "NAVI_BOLD",
"size": 18
"maskForAlfred": false
},
"subTitle": {
"text": "We need the documents as a proof of your loan closure. You can also submit them later.",
"size": 14,
"font": "NAVI_SEMI_BOLD",
"size": 14
"maskForAlfred": false
},
"footer": {
"cta": {
@@ -475,21 +550,17 @@
"parameters": [
{
"key": "action",
"value": "IPA"
"value": "GENERATE_SL"
},
{
"key": "loanApplicationId",
"value": "a70c4638-9063-43ff-8737-9aa7ec20624e"
"value": "63bd7b1b-e621-46fb-8f14-4ff5353dc7b3"
},
{
"key": "referenceId",
"value": "3dd6e316-8806-4d7a-a2cb-2b32f18d7e54"
"value": "facb981f-dd07-4757-a2bc-03b971d3b287"
}
],
"analyticsEventProperties": {
"name": "",
"properties": {}
}
]
}
}
},
@@ -497,46 +568,78 @@
"iconCode": "ICON_BLUE_BORDER_ALERT",
"title": {
"text": "Max loan offer availed",
"size": 18,
"font": "NAVI_BOLD",
"size": 18
"maskForAlfred": false
},
"subTitle": {
"text": "You have already received our maximum offer. Please deselect other loans to select this one",
"size": 14,
"font": "NAVI_SEMI_BOLD",
"size": 14
"maskForAlfred": false
},
"footer": {
"cta": {
"title": "Okay",
"url": "",
"parameters": [],
"analyticsEventProperties": {
"name": "",
"properties": {}
}
"title": "Okay"
}
}
},
"insufficientLoansBottomSheet": {
"iconCode": "ICON_RED_BORDER_ALERT",
"title": {
"text": "Insufficient loans selected",
"size": 18,
"font": "NAVI_BOLD",
"maskForAlfred": false
},
"subTitle": {
"text": "Please select more loans to get an approved loan offer.",
"size": 14,
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"footer": {
"cta": {
"title": "Okay"
}
}
}
},
"footer": {
"cta": {
"title": "Continue",
"url": "hl/homeLoanLoader",
"parameters": [
{
"key": "action",
"value": "GENERATE_SL"
},
{
"key": "loanApplicationId",
"value": "63bd7b1b-e621-46fb-8f14-4ff5353dc7b3"
},
{
"key": "referenceId",
"value": "facb981f-dd07-4757-a2bc-03b971d3b287"
}
],
"analyticsEventProperties": {
"name": "New_HL_Back_button_clicked",
"properties": {
"screenName": "Declare_Closed_Loan_Service"
}
}
},
"progress": 50,
"footerCheckBox": {
"title": {
"text": "I confirm that I will close the selected loan(s)",
"font": "NAVI_SEMI_BOLD",
"text": "I confirm that I will close the selected loan(s) with my own funds",
"textColor": "#4D4D4D",
"size": 12,
"textColor": "#4D4D4D"
"font": "NAVI_SEMI_BOLD",
"maskForAlfred": false
},
"isChecked": false
},
"cta": {
"title": "Continue",
"url": "hl/homeLoanSteps/HL_FORM_SEARCH",
"parameters": [],
"analyticsEventProperties": {
"name": "",
"properties": {}
}
}
}
},

View File

@@ -19,9 +19,11 @@ import com.navi.homeloan.common.models.HomeLoanCloseLoansResponse
import com.navi.homeloan.common.models.SelectedLoansDetail
import com.navi.naviwidgets.models.response.LoanItemWithCheckBoxDocumentWidget
import kotlinx.coroutines.launch
import com.navi.hl.utils.HLCoroutineDispatcherProvider
class HomeLoanCloseLoansFragmentVM(
private val repository: HomeLoanCloseLoansRepository = HomeLoanCloseLoansRepository()
private val repository: HomeLoanCloseLoansRepository = HomeLoanCloseLoansRepository(),
private val coroutineDispatcherProvider: HLCoroutineDispatcherProvider = HLCoroutineDispatcherProvider()
) : BaseVM() {
private val _hlCloseLoansScreenResponse = MutableLiveData<HomeLoanCloseLoansResponse?>()
@@ -35,11 +37,10 @@ class HomeLoanCloseLoansFragmentVM(
var defaultLoanSelectedSum: Long = 0
fun fetchCloseLoansResponse(queryMap: HashMap<String, String>) =
viewModelScope.launch {
viewModelScope.launch(coroutineDispatcherProvider.io) {
val response = repository.fetchCloseLoansResponse(queryMap)
if (response.error == null && response.errors.isNullOrEmpty()) {
_hlCloseLoansScreenResponse.value =
updateSelectedItem(response.data, queryMap[Constants.CONTEXT_KEY])
_hlCloseLoansScreenResponse.postValue(updateSelectedItem(response.data, queryMap[Constants.CONTEXT_KEY]))
} else {
setErrorData(
errors = response.errors,
@@ -106,7 +107,7 @@ class HomeLoanCloseLoansFragmentVM(
coroutineScope.launch {
val response = repository.postHomeLoanObligationIds(queryMap, obligationIds)
if (response.error == null && response.errors.isNullOrEmpty()) {
_hlObligationsResponse.value = ctaData
_hlObligationsResponse.postValue(ctaData)
} else {
setErrorData(
errors = response.errors,

View File

@@ -0,0 +1,226 @@
package com.navi.hl.steps.viewmodel
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.google.common.reflect.TypeToken
import com.navi.base.model.CtaData
import com.navi.common.model.UploadDataAsyncResponse
import com.navi.common.network.models.RepoResult
import com.navi.hl.common.mockUtils.TestDispatcher
import com.navi.hl.mockUtils.mockCoroutinesDispatcherProvider
import com.navi.hl.steps.repository.HomeLoanCloseLoansRepository
import com.navi.hl.utils.mockResponseForUnitTest
import com.navi.homeloan.common.models.HomeLoanCloseLoansResponse
import com.navi.homeloan.common.models.SelectedLoansDetail
import com.navi.naviwidgets.models.NaviWidget
import com.navi.naviwidgets.models.response.LoanItemWithCheckBoxDocumentWidget
import io.mockk.MockKAnnotations
import io.mockk.coEvery
import io.mockk.impl.annotations.RelaxedMockK
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertNotNull
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import com.navi.naviwidgets.models.response.TitleSubtitleSelectedCountWidget
@RunWith(JUnit4::class)
class HomeLoanCloseLoansFragmentVMTest {
@RelaxedMockK
private lateinit var repository: HomeLoanCloseLoansRepository
@OptIn(InternalCoroutinesApi::class)
@RelaxedMockK
private lateinit var testDispatcher: TestDispatcher
@ExperimentalCoroutinesApi
// To make sure unit test executes in sequence
private val coroutineDispatcher = UnconfinedTestDispatcher()
// To Test LiveData
@get:Rule
var rule: TestRule = InstantTaskExecutorRule()
private lateinit var viewModel: HomeLoanCloseLoansFragmentVM
@OptIn(InternalCoroutinesApi::class, ExperimentalCoroutinesApi::class)
@Before
fun setUp() {
MockKAnnotations.init(this, relaxUnitFun = true)
testDispatcher = TestDispatcher()
viewModel = HomeLoanCloseLoansFragmentVM(repository, mockCoroutinesDispatcherProvider(coroutineDispatcher))
}
private fun getCloseLoansScreenMockData(): RepoResult<HomeLoanCloseLoansResponse> {
val type = object : TypeToken<HomeLoanCloseLoansResponse>() {}.type
return mockResponseForUnitTest(type, "closeLoansScreenResponse")
}
@InternalCoroutinesApi
@Test
fun fetchCloseLoansResponseTest() =
runBlocking(testDispatcher) {
viewModel.updateCoroutineScope(this)
val queryMap = HashMap<String, String>()
coEvery { repository.fetchCloseLoansResponse(queryMap) } returns getCloseLoansScreenMockData()
viewModel.fetchCloseLoansResponse(queryMap)
//screen header test asserts
assertEquals("Home Loan", viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.centerText)
assertEquals("ICON_ARROW_LEFT_BLUE", viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.iconCode)
assertEquals("Need Help?", viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.title?.text)
assertEquals(3, viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.size)
assertEquals("FAQs", viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.get(0)?.title?.text)
assertEquals("ICON_HL_HELP_FAQ", viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.get(0)?.startIcon?.iconCode)
assertNotNull(viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.get(0)?.ctaData?.url)
assertEquals("Chat with us", viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.get(1)?.title?.text)
assertEquals("ICON_HL_HELP_CHAT", viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.get(1)?.startIcon?.iconCode)
assertNotNull(viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.get(1)?.ctaData?.url)
assertEquals("Send E-mail", viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.get(2)?.title?.text)
assertEquals("ICON_HL_HELP_EMAIL", viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.get(2)?.startIcon?.iconCode)
assertNotNull(viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.helpBottomSheet?.helpItems?.get(2)?.ctaData?.url)
assertNotNull(viewModel.hlCloseLoansScreenResponse.value?.header?.navigationHeader?.backCta?.url)
//screen footer test asserts
assertEquals("Continue", viewModel.hlCloseLoansScreenResponse.value?.footer?.cta?.title)
assertNotNull(viewModel.hlCloseLoansScreenResponse.value?.footer?.cta?.url)
assertEquals(50, viewModel.hlCloseLoansScreenResponse.value?.footer?.progress)
assertEquals("I confirm that I will close the selected loan(s) with my own funds", viewModel.hlCloseLoansScreenResponse.value?.footer?.footerCheckBox?.title?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.footer?.footerCheckBox?.isChecked)
//screen content test asserts
assertEquals("Improve your loan offer", viewModel.hlCloseLoansScreenResponse.value?.content?.screenTitle?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.screenTitle?.maskForAlfred)
assertEquals("Select more loans to get an offer", viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.lockedOfferLabel?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.lockedOfferLabel?.maskForAlfred)
assertEquals("Current offer", viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.currentOfferLabel?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.currentOfferLabel?.maskForAlfred)
assertEquals("Loan offer you can avail", viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.maxOfferLabel?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.maxOfferLabel?.maskForAlfred)
assertEquals("₹AMOUNT_IN_TEXT", viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.currentOfferText)
assertEquals("Upto ₹AMOUNT_IN_TEXT", viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.maxOfferText)
assertEquals(3560000L, viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.currentOffer)
assertEquals(3770000L, viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.maxOffer)
assertEquals(-21656L, viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.minEmiThresholdForApproval)
assertEquals("ICON_HL_GREY_LOCK", viewModel.hlCloseLoansScreenResponse.value?.content?.graphData?.endIcon?.iconCode)
assertEquals(3, viewModel.hlCloseLoansScreenResponse.value?.content?.widgets?.size)
assertEquals("TITLE_SUBTITLE_SELECTED_COUNT_WIDGET", viewModel.hlCloseLoansScreenResponse.value?.content?.widgets?.get(0)?.widgetNameForBaseAdapter)
assertEquals("LOAN_ITEM_WITH_CHECKBOX_DOCUMENT_WIDGET", viewModel.hlCloseLoansScreenResponse.value?.content?.widgets?.get(1)?.widgetNameForBaseAdapter)
assertEquals("LOAN_ITEM_WITH_CHECKBOX_DOCUMENT_WIDGET", viewModel.hlCloseLoansScreenResponse.value?.content?.widgets?.get(2)?.widgetNameForBaseAdapter)
val selectedCountWidget: NaviWidget? = viewModel.hlCloseLoansScreenResponse.value?.content?.widgets?.get(0)
if (selectedCountWidget != null && selectedCountWidget is TitleSubtitleSelectedCountWidget) {
assertEquals("Open Loans", selectedCountWidget.widgetData()?.title?.text)
assertEquals(false, selectedCountWidget.widgetData()?.title?.maskForAlfred)
assertEquals("Select your closed loans or loans closing within next 12 months", selectedCountWidget.widgetData()?.subTitle?.text)
assertEquals(false, selectedCountWidget.widgetData()?.subTitle?.maskForAlfred)
assertEquals("GREY_DARK_INFO_ICON", selectedCountWidget.widgetData()?.titleIcon?.iconCode)
}
val loanItemWithCheckBoxDocumentWidget: NaviWidget? = viewModel.hlCloseLoansScreenResponse.value?.content?.widgets?.get(1)
if (loanItemWithCheckBoxDocumentWidget != null && loanItemWithCheckBoxDocumentWidget is LoanItemWithCheckBoxDocumentWidget) {
assertEquals("#F3F3FF", loanItemWithCheckBoxDocumentWidget.widgetData()?.headerBGColor)
assertEquals("#ffffff", loanItemWithCheckBoxDocumentWidget.widgetData()?.bodyBGColor)
assertEquals("Impact of closing this loan", loanItemWithCheckBoxDocumentWidget.widgetData()?.headerStartTitle?.text)
assertEquals(false, loanItemWithCheckBoxDocumentWidget.widgetData()?.headerStartTitle?.maskForAlfred)
assertEquals("Upto ₹ 2.1 Lakhs", loanItemWithCheckBoxDocumentWidget.widgetData()?.incrementText?.text)
assertEquals(false, loanItemWithCheckBoxDocumentWidget.widgetData()?.incrementText?.maskForAlfred)
assertEquals("Personal Loan", loanItemWithCheckBoxDocumentWidget.widgetData()?.title?.text)
assertEquals(false, loanItemWithCheckBoxDocumentWidget.widgetData()?.title?.maskForAlfred)
assertEquals("5:1:2018-07-13:1200000", loanItemWithCheckBoxDocumentWidget.widgetData()?.obligationId)
assertEquals(210000L, loanItemWithCheckBoxDocumentWidget.widgetData()?.incrementAmount)
assertEquals(1719L, loanItemWithCheckBoxDocumentWidget.widgetData()?.emiAmount)
assertEquals("Add Document", loanItemWithCheckBoxDocumentWidget.widgetData()?.documentUploadOption?.text)
assertEquals("ICON_EXTRA_SMALL_ORANGE_PLUS", loanItemWithCheckBoxDocumentWidget.widgetData()?.documentUploadOption?.textDrawableData?.left?.iconCode)
assertEquals("(Optional)", loanItemWithCheckBoxDocumentWidget.widgetData()?.supportText?.text)
assertEquals(false, loanItemWithCheckBoxDocumentWidget.widgetData()?.isSelected)
}
val loanItemWithCheckBoxDocumentWidget2: NaviWidget? = viewModel.hlCloseLoansScreenResponse.value?.content?.widgets?.get(2)
if (loanItemWithCheckBoxDocumentWidget2 != null && loanItemWithCheckBoxDocumentWidget2 is LoanItemWithCheckBoxDocumentWidget) {
assertEquals("#F3F3FF", loanItemWithCheckBoxDocumentWidget2.widgetData()?.headerBGColor)
assertEquals("#ffffff", loanItemWithCheckBoxDocumentWidget2.widgetData()?.bodyBGColor)
assertEquals("Impact of closing this loan", loanItemWithCheckBoxDocumentWidget2.widgetData()?.headerStartTitle?.text)
assertEquals(false, loanItemWithCheckBoxDocumentWidget2.widgetData()?.headerStartTitle?.maskForAlfred)
assertEquals("Upto ₹ 11000", loanItemWithCheckBoxDocumentWidget2.widgetData()?.incrementText?.text)
assertEquals(false, loanItemWithCheckBoxDocumentWidget2.widgetData()?.incrementText?.maskForAlfred)
assertEquals("Housing Loan", loanItemWithCheckBoxDocumentWidget2.widgetData()?.title?.text)
assertEquals(false, loanItemWithCheckBoxDocumentWidget2.widgetData()?.title?.maskForAlfred)
assertEquals("2:4:2023-03-21:7000", loanItemWithCheckBoxDocumentWidget2.widgetData()?.obligationId)
assertEquals(11000L, loanItemWithCheckBoxDocumentWidget2.widgetData()?.incrementAmount)
assertEquals(89L, loanItemWithCheckBoxDocumentWidget2.widgetData()?.emiAmount)
assertEquals("Add Document", loanItemWithCheckBoxDocumentWidget2.widgetData()?.documentUploadOption?.text)
assertEquals("ICON_EXTRA_SMALL_ORANGE_PLUS", loanItemWithCheckBoxDocumentWidget2.widgetData()?.documentUploadOption?.textDrawableData?.left?.iconCode)
assertEquals("(Optional)", loanItemWithCheckBoxDocumentWidget2.widgetData()?.supportText?.text)
assertEquals(false, loanItemWithCheckBoxDocumentWidget2.widgetData()?.isSelected)
}
assertEquals("ICON_BLUE_BORDER_ALERT", viewModel.hlCloseLoansScreenResponse.value?.content?.openLoansInfoBottomSheet?.iconCode)
assertEquals("Open Loans", viewModel.hlCloseLoansScreenResponse.value?.content?.openLoansInfoBottomSheet?.title?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.openLoansInfoBottomSheet?.title?.maskForAlfred)
assertEquals("Based on the data provided by you, we have auto-fetched your loan history. You can improve your offer by closing some of your loans.", viewModel.hlCloseLoansScreenResponse.value?.content?.openLoansInfoBottomSheet?.subTitle?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.openLoansInfoBottomSheet?.subTitle?.maskForAlfred)
assertEquals("Okay", viewModel.hlCloseLoansScreenResponse.value?.content?.openLoansInfoBottomSheet?.footer?.cta?.title)
assertEquals("ICON_BLUE_BORDER_ALERT", viewModel.hlCloseLoansScreenResponse.value?.content?.addDocumentBottomSheet?.iconCode)
assertEquals("Add Document", viewModel.hlCloseLoansScreenResponse.value?.content?.addDocumentBottomSheet?.title?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.addDocumentBottomSheet?.title?.maskForAlfred)
assertEquals("We need the documents as a proof of your loan closure. You can also submit them later.", viewModel.hlCloseLoansScreenResponse.value?.content?.addDocumentBottomSheet?.subTitle?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.addDocumentBottomSheet?.subTitle?.maskForAlfred)
assertEquals("ICON_BLUE_BORDER_ALERT", viewModel.hlCloseLoansScreenResponse.value?.content?.maxLoanAvailedBottomSheet?.iconCode)
assertEquals("Max loan offer availed", viewModel.hlCloseLoansScreenResponse.value?.content?.maxLoanAvailedBottomSheet?.title?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.maxLoanAvailedBottomSheet?.title?.maskForAlfred)
assertEquals("You have already received our maximum offer. Please deselect other loans to select this one", viewModel.hlCloseLoansScreenResponse.value?.content?.maxLoanAvailedBottomSheet?.subTitle?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.maxLoanAvailedBottomSheet?.subTitle?.maskForAlfred)
assertEquals("Okay", viewModel.hlCloseLoansScreenResponse.value?.content?.maxLoanAvailedBottomSheet?.footer?.cta?.title)
assertEquals("ICON_RED_BORDER_ALERT", viewModel.hlCloseLoansScreenResponse.value?.content?.insufficientLoansBottomSheet?.iconCode)
assertEquals("Insufficient loans selected", viewModel.hlCloseLoansScreenResponse.value?.content?.insufficientLoansBottomSheet?.title?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.insufficientLoansBottomSheet?.title?.maskForAlfred)
assertEquals("Please select more loans to get an approved loan offer.", viewModel.hlCloseLoansScreenResponse.value?.content?.insufficientLoansBottomSheet?.subTitle?.text)
assertEquals(false, viewModel.hlCloseLoansScreenResponse.value?.content?.insufficientLoansBottomSheet?.subTitle?.maskForAlfred)
assertEquals("Okay", viewModel.hlCloseLoansScreenResponse.value?.content?.insufficientLoansBottomSheet?.footer?.cta?.title)
}
@Test
fun getSelectedCountTest() {
val queryMap = HashMap<String, String>()
coEvery { repository.fetchCloseLoansResponse(queryMap) } returns getCloseLoansScreenMockData()
viewModel.fetchCloseLoansResponse(queryMap)
val response = SelectedLoansDetail(
openLoansCount = 2,
selectedCount = 0,
incrementAmount = 0,
selectedLoansObligationIds = mutableListOf(),
emiAmount = 0
)
assertEquals(response, viewModel.getSelectedCount())
}
@InternalCoroutinesApi
@Test
fun postHomeLoanObligationIdsTest() =
runBlocking(testDispatcher) {
viewModel.updateCoroutineScope(this)
val queryMap = HashMap<String, String>()
val obligationIds = mutableListOf<String?>()
val ctaData = CtaData(
title = "Okay"
)
val mockResponse: RepoResult<Any> = RepoResult(
statusCode = 200,
data = UploadDataAsyncResponse(
status = "SUCCESS",
),
)
coEvery { repository.postHomeLoanObligationIds(queryMap, obligationIds) } returns mockResponse
viewModel.postHomeLoanObligationIds(queryMap, obligationIds, ctaData)
assertEquals("Okay", viewModel.hlObligationsResponse.value?.title)
}
}