This file contains hidden or 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
extension Binding { | |
func onChange(_ handler: @escaping (Value) -> Void) -> Binding<Value> { | |
return Binding( | |
get: { self.wrappedValue }, | |
set: { selection in | |
self.wrappedValue = selection | |
handler(selection) | |
}) | |
} | |
} |
This file contains hidden or 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
class ContentViewModel: ObservableObject { | |
@Published var selectedSegment = Gender.male.rawValue { | |
didSet { | |
characters = selectedSegment == Gender.male.rawValue ? males : females | |
} | |
} | |
@Published var characters = males | |
This file contains hidden or 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
enum Gender: Int { | |
case male | |
case female | |
} | |
struct Character: Identifiable { | |
var id: Int | |
var name: String | |
} |
This file contains hidden or 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
import Combine | |
import Alamofire | |
class LoginHandler: APIHandler { | |
@Published var woofResponse: WoofResponse? | |
@Published var isLoading = false | |
func getRandomDog() { | |
isLoading = true |
This file contains hidden or 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
private var isLoadingPublisher: AnyPublisher<Bool, Never> { | |
loginHandler.$isLoading | |
.receive(on: RunLoop.main) | |
.map { $0 } | |
.eraseToAnyPublisher() | |
} | |
private var isAuthenticatedPublisher: AnyPublisher<String, Never> { | |
loginHandler.$woofResponse | |
.receive(on: RunLoop.main) |
This file contains hidden or 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
var body: some View { | |
NavigationView { | |
LoadingView(isShowing: .constant(viewModel.isLoading)) { | |
VStack(alignment: .leading) { | |
self.titleView | |
self.placeHolderTextView | |
self.passwordTextView | |
self.loginButton | |
Spacer() | |
Spacer() |
This file contains hidden or 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
override func viewDidLoad() { | |
super.viewDidLoad() | |
people.bind(to: tableView.rx.items(cellIdentifier: "PersonCell")) { row, model, cell in | |
cell.textLabel?.text = "\(model.name) from \(model.title)" | |
}.disposed(by: disposeBag) | |
} |
This file contains hidden or 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
fileprivate let people: BehaviorRelay<[Person]> = BehaviorRelay(value: [ | |
Person(name: "Spiderman", title: "Marvel"), | |
Person(name: "Batman", title: "DC"), | |
Person(name: "Mickey", title: "Disnet") | |
]) | |
let disposeBag = DisposeBag() |
This file contains hidden or 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
import 'package:flutter_test/flutter_test.dart'; | |
import 'package:tryunittesting/TextValidator.dart'; | |
void main() { | |
group('Given user is at Login Page', () { | |
test( | |
'and user keys in username, username should be at least 8 characters long', | |
() { | |
expect(TextValidator().validateUsername('test'), false); | |
expect(TextValidator().validateUsername('testtest'), true); |
This file contains hidden or 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
class TextValidator { | |
bool validateUsername(String username) { | |
return false; | |
} | |
bool validatePassword(String password) { | |
return false; | |
} | |
} |