From b0f27c111e7159ab97f888c4f86f42c7ffc9b841 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 24 Oct 2023 11:35:11 +0200 Subject: [PATCH] PIN : add some tests to PinEntry --- .../lockscreen/impl/pin/model/PinEntryTest.kt | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/pin/model/PinEntryTest.kt diff --git a/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/pin/model/PinEntryTest.kt b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/pin/model/PinEntryTest.kt new file mode 100644 index 0000000000..38abb2d295 --- /dev/null +++ b/features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/pin/model/PinEntryTest.kt @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.lockscreen.impl.pin.model + +import com.google.common.truth.Truth.assertThat +import org.junit.Test + +class PinEntryTest { + + @Test + fun `when using fillWith with empty string ensure pin is empty`() { + val pinEntry = PinEntry.createEmpty(4) + val newPinEntry = pinEntry.fillWith("") + assertThat(newPinEntry.isEmpty()).isTrue() + } + + @Test + fun `when using fillWith with bigger string than size ensure pin is complete`() { + val pinEntry = PinEntry.createEmpty(4) + val newPinEntry = pinEntry.fillWith("12345") + assertThat(newPinEntry.isComplete()).isTrue() + newPinEntry.assertText("1234") + } + + @Test + fun `when using fillWith with non digit string ensure pin is filtering`() { + val pinEntry = PinEntry.createEmpty(4) + val newPinEntry = pinEntry.fillWith("12aa") + newPinEntry.assertText("12") + } + + @Test + fun `when using clear ensure pin is empty`() { + val pinEntry = PinEntry.createEmpty(4) + val newPinEntry = pinEntry.clear() + assertThat(newPinEntry.isEmpty()).isTrue() + assertThat(newPinEntry.isComplete()).isFalse() + newPinEntry.assertText("") + } + + @Test + fun `when using deleteLast ensure pin correct`() { + val pinEntry = PinEntry.createEmpty(4) + val newPinEntry = pinEntry.fillWith("1234").deleteLast() + newPinEntry.assertText("123") + } + + @Test + fun `when using deleteLast with empty pin ensure pin is empty`() { + val pinEntry = PinEntry.createEmpty(4) + val newPinEntry = pinEntry.deleteLast() + assertThat(newPinEntry.isEmpty()).isTrue() + } + + @Test + fun `when using addDigit with complete pin ensure pin is complete`() { + val pinEntry = PinEntry.createEmpty(4) + val newPinEntry = pinEntry + .addDigit('1') + .addDigit('2') + .addDigit('3') + .addDigit('4') + .addDigit('5') + assertThat(newPinEntry.isComplete()).isTrue() + newPinEntry.assertText("1234") + } +}