Skip to content

Commit 2d7b71f

Browse files
committed
extracting stage ordering to its own class with test
1 parent 1a76b4d commit 2d7b71f

File tree

4 files changed

+114
-10
lines changed

4 files changed

+114
-10
lines changed

vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,7 @@ class FtueAuthVariant(
252252
}
253253

254254
private fun FlowResult.orderedStages() = when {
255-
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> missingStages.sortedBy {
256-
when (it) {
257-
is Stage.Email -> 0
258-
is Stage.Msisdn -> 1
259-
is Stage.Terms -> 2
260-
is Stage.ReCaptcha -> 3
261-
is Stage.Other -> 4
262-
is Stage.Dummy -> 5
263-
}
264-
}
255+
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> missingStages.sortedWith(FtueMissingRegistrationStagesComparator())
265256
else -> missingStages
266257
}
267258

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.features.onboarding.ftueauth
18+
19+
import org.matrix.android.sdk.api.auth.registration.Stage
20+
21+
class FtueMissingRegistrationStagesComparator : Comparator<Stage> {
22+
23+
override fun compare(a: Stage?, b: Stage?): Int {
24+
return (a?.toPriority() ?: 0) - (b?.toPriority() ?: 0)
25+
}
26+
27+
private fun Stage.toPriority() = when (this) {
28+
is Stage.Email -> 0
29+
is Stage.Msisdn -> 1
30+
is Stage.Terms -> 2
31+
is Stage.ReCaptcha -> 3
32+
is Stage.Other -> 4
33+
is Stage.Dummy -> 5
34+
}
35+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.features.onboarding.ftueauth
18+
19+
import im.vector.app.test.fixtures.aDummyStage
20+
import im.vector.app.test.fixtures.aMsisdnStage
21+
import im.vector.app.test.fixtures.aRecaptchaStage
22+
import im.vector.app.test.fixtures.aTermsStage
23+
import im.vector.app.test.fixtures.anEmailStage
24+
import im.vector.app.test.fixtures.anOtherStage
25+
import org.amshove.kluent.shouldBeEqualTo
26+
import org.junit.Test
27+
28+
class FtueMissingRegistrationStagesComparatorTest {
29+
30+
@Test
31+
fun `when ordering stages, then prioritizes email`() {
32+
val input = listOf(
33+
aDummyStage(),
34+
anOtherStage(),
35+
aMsisdnStage(),
36+
anEmailStage(),
37+
aRecaptchaStage(),
38+
aTermsStage()
39+
)
40+
41+
val result = input.sortedWith(FtueMissingRegistrationStagesComparator())
42+
43+
result shouldBeEqualTo listOf(
44+
anEmailStage(),
45+
aMsisdnStage(),
46+
aTermsStage(),
47+
aRecaptchaStage(),
48+
anOtherStage(),
49+
aDummyStage()
50+
)
51+
}
52+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.test.fixtures
18+
19+
import org.matrix.android.sdk.api.auth.registration.Stage
20+
21+
fun aDummyStage() = Stage.Dummy(mandatory = true)
22+
fun anEmailStage() = Stage.Email(mandatory = true)
23+
fun aMsisdnStage() = Stage.Msisdn(mandatory = true)
24+
fun aTermsStage() = Stage.Terms(mandatory = true, policies = emptyMap<String, String>())
25+
fun aRecaptchaStage() = Stage.ReCaptcha(mandatory = true, publicKey = "any-key")
26+
fun anOtherStage() = Stage.Other(mandatory = true, type = "raw-type", params = emptyMap<String, String>())

0 commit comments

Comments
 (0)