-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix ValueValidator not returning isValid for empty rule sets.
fix outcome() not returning SUCCESS for empty rule sets
- Loading branch information
Showing
18 changed files
with
288 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
4 changes: 0 additions & 4 deletions
4
library/src/androidInstrumentedTest/kotlin/com/chrisjenx/yakcov/IOSIgnore.android.kt
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
library/src/androidInstrumentedTest/kotlin/com/chrisjenx/yakcov/PlatformIgnore.android.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,10 @@ | ||
package com.chrisjenx.yakcov | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class IOSIgnore | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class AndroidJUnitIgnore | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class JSIgnore() |
4 changes: 0 additions & 4 deletions
4
library/src/androidUnitTest/kotlin/com/chrisjenx/yakcov/IOSIgnore.android.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
library/src/androidUnitTest/kotlin/com/chrisjenx/yakcov/PlatformIgnore.android.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,9 @@ | ||
package com.chrisjenx.yakcov | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class IOSIgnore | ||
|
||
actual typealias AndroidJUnitIgnore = org.junit.Ignore | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class JSIgnore() |
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
4 changes: 0 additions & 4 deletions
4
library/src/commonTest/kotlin/com/chrisjenx/yakcov/IOSIgnore.kt
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
library/src/commonTest/kotlin/com/chrisjenx/yakcov/PlatformIgnore.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,10 @@ | ||
package com.chrisjenx.yakcov | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
expect annotation class IOSIgnore() | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
expect annotation class AndroidJUnitIgnore() | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
expect annotation class JSIgnore() |
205 changes: 205 additions & 0 deletions
205
library/src/commonTest/kotlin/com/chrisjenx/yakcov/ValueValidatorTest.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,205 @@ | ||
package com.chrisjenx.yakcov | ||
|
||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.runComposeUiTest | ||
import com.chrisjenx.yakcov.strings.Required | ||
import org.jetbrains.compose.resources.stringResource | ||
import yakcov.library.generated.resources.Res | ||
import yakcov.library.generated.resources.ruleRequired | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertNotNull | ||
import kotlin.test.assertNull | ||
import kotlin.test.assertTrue | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
class ValueValidatorTest { | ||
|
||
private val noRulesValueValidator = object : ValueValidator<String, String>( | ||
state = mutableStateOf(""), | ||
rules = emptyList(), | ||
validateMapper = { validate(it) } | ||
) {} | ||
|
||
private val ruleValueValidator = object : ValueValidator<String, String>( | ||
state = mutableStateOf(""), | ||
rules = listOf(Required), | ||
validateMapper = { validate(it) } | ||
) {} | ||
|
||
|
||
@Test | ||
fun noRulesValueValidator() { | ||
assertEquals( | ||
expected = ValueValidator.InternalState.Validating(), | ||
noRulesValueValidator.internalState, | ||
"internalState should be Validating" | ||
) | ||
assertTrue(noRulesValueValidator.isValid, "isValid should be true") | ||
assertEquals( | ||
expected = 0, noRulesValueValidator.validationResults.size, | ||
"Should have no validation results" | ||
) | ||
assertFalse( | ||
noRulesValueValidator.isError(), | ||
"isError should be false" | ||
) | ||
assertEquals( | ||
expected = ValidationResult.Outcome.SUCCESS, | ||
noRulesValueValidator.outcome(), | ||
"outcome should be SUCCESS" | ||
) | ||
} | ||
|
||
@Test | ||
@AndroidJUnitIgnore | ||
@JSIgnore | ||
fun noRulesValueValidatorCompose() = runComposeUiTest { | ||
setContent { | ||
assertEquals( | ||
expected = null, noRulesValueValidator.getValidationResultString(), | ||
"format should be null" | ||
) | ||
assertEquals( | ||
expected = null, noRulesValueValidator.supportingText(), | ||
"supportingText should be null" | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun rulesValueValidator_notValidating() { | ||
assertEquals( | ||
expected = ValueValidator.InternalState.Initial, | ||
ruleValueValidator.internalState, | ||
"internalState should be Initial" | ||
) | ||
assertFalse( | ||
ruleValueValidator.isValid, | ||
"isValid should be false" | ||
) | ||
assertEquals( | ||
expected = 1, ruleValueValidator.validationResults.size, | ||
"Should have 1 validation results" | ||
) | ||
assertFalse( | ||
ruleValueValidator.isError(), | ||
"isError should be false" | ||
) | ||
assertNull( | ||
ruleValueValidator.outcome(), | ||
"outcome should be null" | ||
) | ||
} | ||
|
||
@Test | ||
fun rulesValueValidator_validating() { | ||
ruleValueValidator.validate(value = null) // Start validating | ||
assertEquals( | ||
expected = ValueValidator.InternalState.Validating(), | ||
ruleValueValidator.internalState, | ||
"internalState should be Validating" | ||
) | ||
assertFalse( | ||
ruleValueValidator.isValid, | ||
"isValid should be false" | ||
) | ||
assertEquals( | ||
expected = 1, ruleValueValidator.validationResults.size, | ||
"Should have 1 validation results" | ||
) | ||
assertTrue( | ||
ruleValueValidator.isError(), | ||
"isError should be true" | ||
) | ||
assertEquals( | ||
expected = ValidationResult.Outcome.ERROR, | ||
ruleValueValidator.outcome(), | ||
"outcome should be ERROR" | ||
) | ||
} | ||
|
||
@Test | ||
fun rulesValueValidator_valid() { | ||
ruleValueValidator.validate(value = "Value") // Start validating | ||
assertEquals( | ||
expected = ValueValidator.InternalState.Validating(), | ||
ruleValueValidator.internalState, | ||
"internalState should be Validating" | ||
) | ||
assertTrue( | ||
ruleValueValidator.isValid, | ||
"isValid should be true" | ||
) | ||
assertEquals( | ||
expected = 1, ruleValueValidator.validationResults.size, | ||
"Should have 1 validation results" | ||
) | ||
assertFalse( | ||
ruleValueValidator.isError(), | ||
"isError should be false" | ||
) | ||
assertEquals( | ||
expected = ValidationResult.Outcome.SUCCESS, | ||
ruleValueValidator.outcome(), | ||
"outcome should be SUCCESS" | ||
) | ||
} | ||
|
||
@Test | ||
@AndroidJUnitIgnore | ||
@JSIgnore | ||
fun rulesValueValidatorCompose_notValidating() = runComposeUiTest { | ||
setContent { | ||
assertEquals( | ||
expected = stringResource(Res.string.ruleRequired), | ||
ruleValueValidator.getValidationResultString(), | ||
"getValidationResultString should be Required" | ||
) | ||
assertEquals( | ||
expected = null, ruleValueValidator.supportingText(), | ||
"supportingText should be null" | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
@AndroidJUnitIgnore | ||
@JSIgnore | ||
fun rulesValueValidatorCompose_validating() = runComposeUiTest { | ||
ruleValueValidator.validate(value = null) // Start validating | ||
setContent { | ||
assertEquals( | ||
expected = stringResource(Res.string.ruleRequired), | ||
ruleValueValidator.getValidationResultString(), | ||
"getValidationResultString should be Required" | ||
) | ||
assertNotNull( | ||
ruleValueValidator.supportingText(), | ||
"supportingText should not be null" | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
@AndroidJUnitIgnore | ||
@JSIgnore | ||
fun rulesValueValidatorCompose_success() = runComposeUiTest { | ||
// Note, these might change as we want to support, alwaysShowRules, which means SUCCESS will | ||
// need to return the rule message. | ||
ruleValueValidator.validate(value = "Value") // Start validating | ||
setContent { | ||
assertNull( | ||
ruleValueValidator.getValidationResultString(), | ||
"getValidationResultString should be Required" | ||
) | ||
assertNull( | ||
ruleValueValidator.supportingText(), | ||
"supportingText should be null" | ||
) | ||
} | ||
} | ||
|
||
} |
3 changes: 0 additions & 3 deletions
3
library/src/iosTest/kotlin/com/chrisjenx/yakcov/IOSIgnore.ios.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
library/src/iosTest/kotlin/com/chrisjenx/yakcov/PlatformIgnore.ios.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,9 @@ | ||
package com.chrisjenx.yakcov | ||
|
||
actual typealias IOSIgnore = kotlin.test.Ignore | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class AndroidJUnitIgnore | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class JSIgnore() |
4 changes: 0 additions & 4 deletions
4
library/src/jsTest/kotlin/com/chrisjenx/yakcov/IOSIgnore.js.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
library/src/jsTest/kotlin/com/chrisjenx/yakcov/PlatformIgnore.js.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,9 @@ | ||
package com.chrisjenx.yakcov | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class IOSIgnore | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class AndroidJUnitIgnore | ||
|
||
actual typealias JSIgnore = kotlin.test.Ignore |
4 changes: 0 additions & 4 deletions
4
library/src/jvmTest/kotlin/com/chrisjenx/yakcov/IOSIgnore.jvm.kt
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
library/src/jvmTest/kotlin/com/chrisjenx/yakcov/PlatformIgnore.jvm.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,10 @@ | ||
package com.chrisjenx.yakcov | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class IOSIgnore | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class AndroidJUnitIgnore | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
actual annotation class JSIgnore actual constructor() |
4 changes: 0 additions & 4 deletions
4
library/src/wasmJsTest/kotlin/com/chrisjenx/yakcov/IOSIgnore.wasmJs.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.