-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: API to get position of adapter item
- Loading branch information
Showing
9 changed files
with
98 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...adapter/tests/api/position/WhenCallingGetItemPosition_ThenItemPosition_ShouldBeCorrect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@file:Suppress("ClassName") | ||
|
||
package com.idanatz.oneadapter.tests.api.position | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.idanatz.oneadapter.external.modules.ItemModule | ||
import com.idanatz.oneadapter.helpers.BaseTest | ||
import com.idanatz.oneadapter.models.TestModel | ||
import com.idanatz.oneadapter.test.R | ||
import org.amshove.kluent.shouldEqualTo | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
private const val POSITION_TO_SCROLL_TO = 10 | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class WhenCallingGetItemPosition_ThenItemPosition_ShouldBeCorrect : BaseTest() { | ||
|
||
@Test | ||
fun test() { | ||
configure { | ||
val models = modelGenerator.generateModels(15) | ||
var positionToScrollTo = -1 | ||
|
||
prepareOnActivity { | ||
oneAdapter.attachItemModule(TestItemModule()) | ||
} | ||
actOnActivity { | ||
oneAdapter.add(models) | ||
runWithDelay { // run with delay to let the items settle | ||
positionToScrollTo = oneAdapter.getItemPosition(models[POSITION_TO_SCROLL_TO]) | ||
recyclerView.smoothScrollToPosition(positionToScrollTo) | ||
} | ||
} | ||
untilAsserted { | ||
oneAdapter.getItemPosition(models[0]) shouldEqualTo 0 | ||
positionToScrollTo shouldEqualTo POSITION_TO_SCROLL_TO | ||
models[POSITION_TO_SCROLL_TO].onBindCalls shouldEqualTo 1 | ||
} | ||
} | ||
} | ||
|
||
inner class TestItemModule : ItemModule<TestModel>() { | ||
init { | ||
config = modulesGenerator.generateValidItemModuleConfig(R.layout.test_model_large) | ||
onBind { model, _, _ -> | ||
model.onBindCalls++ | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../tests/api/position/WhenPassingMissingItem_ThenGetItemPosition_ShouldReturnProperValue.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@file:Suppress("ClassName") | ||
|
||
package com.idanatz.oneadapter.tests.api.position | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.idanatz.oneadapter.helpers.BaseTest | ||
import org.amshove.kluent.shouldEqualTo | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class WhenPassingMissingItem_ThenGetItemPosition_ShouldReturnProperValue : BaseTest() { | ||
|
||
@Test | ||
fun test() { | ||
configure { | ||
var position = 0 | ||
act { | ||
position = oneAdapter.getItemPosition(modelGenerator.generateModel()) | ||
} | ||
assert { | ||
position shouldEqualTo -1 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
...iew_type/WhenPassingNotDiffableClass_ThenGetItemViewTypeFromClass_ShouldThrowException.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters