-
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.
Use ViewModels for simplified testing
- Loading branch information
1 parent
1cd498d
commit 5f56791
Showing
11 changed files
with
163 additions
and
156 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
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 @@ | ||
import Foundation | ||
|
||
extension LoginScreen { | ||
final class ViewModel: ObservableObject { | ||
@Published | ||
var identifier = "" | ||
|
||
var canSubmit: Bool { 3 ... 254 ~= identifier.count } | ||
} | ||
} |
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,15 @@ | ||
import Foundation | ||
|
||
extension RegisterScreen { | ||
final class ViewModel: ObservableObject { | ||
@Published | ||
var username = "" | ||
|
||
@Published | ||
var email = "" | ||
|
||
var isUsernameValid: Bool { 3 ... 50 ~= username.count } | ||
var isEmailValid: Bool { 3 ... 254 ~= email.count && email.contains("@") } | ||
var canSubmit: Bool { isUsernameValid && isEmailValid } | ||
} | ||
} |
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
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,23 @@ | ||
import XCTest | ||
|
||
@testable | ||
import Fyreplace | ||
|
||
final class LoginScreenViewModelTests: XCTestCase { | ||
func testIdentifierMustHaveCorrectLength() { | ||
let viewModel = LoginScreen.ViewModel() | ||
|
||
for i in 0 ..< 3 { | ||
viewModel.identifier = .init(repeating: "a", count: i) | ||
XCTAssertFalse(viewModel.canSubmit) | ||
} | ||
|
||
for i in 3 ... 254 { | ||
viewModel.identifier = .init(repeating: "a", count: i) | ||
XCTAssertTrue(viewModel.canSubmit) | ||
} | ||
|
||
viewModel.identifier = .init(repeating: "a", count: 255) | ||
XCTAssertFalse(viewModel.canSubmit) | ||
} | ||
} |
Oops, something went wrong.