Skip to content

Commit

Permalink
applied spotless and detekt on groups module (#2248)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay authored Nov 30, 2024
1 parent 8aa5800 commit b17c6d6
Show file tree
Hide file tree
Showing 21 changed files with 729 additions and 576 deletions.
6 changes: 3 additions & 3 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ complexity:
]
# Modifying default values 11 to 20
thresholdInFiles: 20
thresholdInClasses: 20
thresholdInClasses: 30
thresholdInInterfaces: 20
thresholdInObjects: 20
thresholdInEnums: 20
Expand Down Expand Up @@ -785,7 +785,7 @@ style:
maxChainedCalls: 5
MaxLineLength:
active: true
maxLineLength: 150
maxLineLength: 250
excludePackageStatements: true
excludeImportStatements: true
excludeCommentStatements: false
Expand Down Expand Up @@ -828,7 +828,7 @@ style:
active: false
ReturnCount:
active: true
max: 4
max: 5
excludedFunctions:
- "equals"
excludeLabeled: false
Expand Down
9 changes: 9 additions & 0 deletions feature/groups/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.groups

import androidx.activity.ComponentActivity
Expand Down Expand Up @@ -35,15 +44,14 @@ import com.mifos.core.domain.use_cases.GroupsListPagingDataSource
import com.mifos.core.objects.group.Group
import com.mifos.core.testing.repository.TestGroupsListRepository
import com.mifos.core.testing.repository.sampleGroups
import com.mifos.feature.groups.group_list.GroupsListScreen
import com.mifos.feature.groups.groupList.GroupsListScreen
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.runBlocking
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertEquals


class GroupListScreenTest {

@get:Rule
Expand All @@ -61,7 +69,7 @@ class GroupListScreenTest {
),
pagingSourceFactory: () -> PagingSource<Int, Group> = {
GroupsListPagingDataSource(repository, pageSize)
}
},
): Pager<Int, Group> {
return Pager(config = config, pagingSourceFactory = pagingSourceFactory)
}
Expand All @@ -75,7 +83,7 @@ class GroupListScreenTest {
),
pagingSourceFactory: () -> PagingSource<Int, Group> = {
GroupsListPagingDataSource(repository, pageSize)
}
},
): Pager<Int, Group> {
return Pager(config = config, pagingSourceFactory = pagingSourceFactory)
}
Expand All @@ -98,9 +106,9 @@ class GroupListScreenTest {
source = LoadStates(
LoadState.Loading,
LoadState.NotLoading(false),
LoadState.NotLoading(false)
LoadState.NotLoading(false),
),
mediator = null
mediator = null,
)
assert(loadStates.isNotEmpty())
assertEquals(loadStates.first(), expected)
Expand All @@ -124,7 +132,6 @@ class GroupListScreenTest {
onGroupClick = {},
onSelectItem = {},
onAddGroupClick = {},
onSyncClick = {},
resetSelectionMode = {},
)
}
Expand All @@ -139,7 +146,6 @@ class GroupListScreenTest {
.onChildren()
.onLast()
.assertTextContains(composeTestRule.activity.resources.getString(R.string.feature_groups_no_more_groups_available))

}

@Test
Expand All @@ -153,7 +159,7 @@ class GroupListScreenTest {
// Adding some delay to test refresh state
lazyPagingItems = pager.flow.onStart { delay(5000) }.collectAsLazyPagingItems()
refreshState = rememberSwipeRefreshState(
isRefreshing = lazyPagingItems.loadState.refresh is LoadState.Loading
isRefreshing = lazyPagingItems.loadState.refresh is LoadState.Loading,
)

GroupsListScreen(
Expand All @@ -164,7 +170,6 @@ class GroupListScreenTest {
onGroupClick = {},
onSelectItem = {},
onAddGroupClick = {},
onSyncClick = {},
resetSelectionMode = {},
)
}
Expand All @@ -177,7 +182,7 @@ class GroupListScreenTest {
// Check initial refresh state is true
assertEquals(true, refreshState.isRefreshing)

//Perform refresh and check refresh state is true
// Perform refresh and check refresh state is true
lazyPagingItems.refresh()

assertEquals(true, refreshState.isRefreshing)
Expand All @@ -201,7 +206,6 @@ class GroupListScreenTest {
onGroupClick = {},
onSelectItem = {},
onAddGroupClick = {},
onSyncClick = {},
resetSelectionMode = {},
)
}
Expand Down Expand Up @@ -237,7 +241,6 @@ class GroupListScreenTest {
repository.setGroupsData(sampleGroups)
val pager = createPager()


lateinit var lazyPagingItems: LazyPagingItems<Group>
lateinit var lazyListState: LazyListState

Expand All @@ -253,7 +256,6 @@ class GroupListScreenTest {
onGroupClick = {},
onSelectItem = {},
onAddGroupClick = {},
onSyncClick = {},
resetSelectionMode = {},
)
}
Expand All @@ -271,10 +273,10 @@ class GroupListScreenTest {
assertEquals(
expected = sampleGroups.take(pageSize),
actual = lazyPagingItems.itemSnapshotList.items,
message = "Sample Groups are differ from Snapshot items"
message = "Sample Groups are differ from Snapshot items",
)

//Check paged item is being displayed
// Check paged item is being displayed
sampleGroups.take(pageSize).forEach { group ->
group.name?.let {
composeTestRule
Expand Down Expand Up @@ -312,7 +314,6 @@ class GroupListScreenTest {
onGroupClick = {},
onSelectItem = {},
onAddGroupClick = {},
onSyncClick = {},
resetSelectionMode = {},
)
}
Expand All @@ -327,12 +328,12 @@ class GroupListScreenTest {

assertEquals(
pageSize * 2,
lazyPagingItems.itemSnapshotList.items.size
lazyPagingItems.itemSnapshotList.items.size,
)

assertEquals(
LoadState.NotLoading(false),
lazyPagingItems.loadState.append
lazyPagingItems.loadState.append,
)

composeTestRule.runOnIdle {
Expand All @@ -346,9 +347,8 @@ class GroupListScreenTest {
// end of pagination reached so total item will be (pageSize * 3) + 1 = 31
assertEquals(
pageSize * 3 + 1,
lazyListState.layoutInfo.totalItemsCount
lazyListState.layoutInfo.totalItemsCount,
)

}

@Test
Expand Down Expand Up @@ -380,7 +380,6 @@ class GroupListScreenTest {
}
},
onAddGroupClick = {},
onSyncClick = {},
resetSelectionMode = {
selectedItems.clear()
},
Expand Down Expand Up @@ -429,14 +428,13 @@ class GroupListScreenTest {
}
}


// Check item has been selected
assert(selectedItems.contains(sampleGroups[4]))

//Check both item has been selected
// Check both item has been selected
assertEquals(
2,
selectedItems.size
selectedItems.size,
)

composeTestRule.waitForIdle()
Expand All @@ -456,26 +454,26 @@ class GroupListScreenTest {

composeTestRule.waitForIdle()

//check for Contextual TopAppBar Visibility
// check for Contextual TopAppBar Visibility
composeTestRule
.onNodeWithContentDescription("GroupList::ContextualTopAppBar")
.assertIsDisplayed()

//Check reset selection IconButton is visible or not
// Check reset selection IconButton is visible or not
composeTestRule
.onNodeWithContentDescription("reset selection")
.assertIsDisplayed()
.assertHasClickAction()

//Check selected text is visible or not
// Check selected text is visible or not
composeTestRule
.onNodeWithContentDescription("GroupList::ContextualTopAppBar")
.assertIsDisplayed()
.onChildren()[1]
.assertTextContains("${selectedItems.size} selected")
.assertIsDisplayed()

//Check Sync Button is visible or not
// Check Sync Button is visible or not
composeTestRule
.onNodeWithContentDescription("GroupList::ContextualTopAppBar")
.assertIsDisplayed()
Expand All @@ -497,7 +495,7 @@ class GroupListScreenTest {
// and selected list only contain 1 item
assert(selectedItems.size == 1)

//also check the background color of that item is set to surfaceColor
// also check the background color of that item is set to surfaceColor
sampleGroups[2].name?.let {
val data = composeTestRule
.onNodeWithTag(it)
Expand All @@ -518,4 +516,4 @@ class GroupListScreenTest {
// check selected items list should be empty
assert(selectedItems.isEmpty())
}
}
}
9 changes: 9 additions & 0 deletions feature/groups/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.
See https://github.com/openMF/android-client/blob/master/LICENSE.md
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Loading

0 comments on commit b17c6d6

Please sign in to comment.