-
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.
- Loading branch information
Showing
8 changed files
with
135 additions
and
14 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
15 changes: 15 additions & 0 deletions
15
SWDestinyTrades/Classes/NewPerson/View/NewPersonViewType.swift
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 @@ | ||
// | ||
// NewPersonViewType.swift | ||
// SWDestinyTrades | ||
// | ||
// Created by Diogo Autilio on 29/02/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
protocol NewPersonViewType where Self: UIView { | ||
|
||
func retriveUserInput() -> (name: String, lastName: String) | ||
} |
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
22 changes: 22 additions & 0 deletions
22
SWDestinyTradesTests/Screens/NewPerson/Doubles/NewPersonViewSpy.swift
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,22 @@ | ||
// | ||
// NewPersonViewSpy.swift | ||
// SWDestinyTradesTests | ||
// | ||
// Created by Diogo Autilio on 29/02/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
@testable import SWDestinyTrades | ||
|
||
final class NewPersonViewSpy: UIView, NewPersonViewType { | ||
|
||
private(set) var didCallRetriveUserInputCount = 0 | ||
var userInput: (name: String, lastName: String) = ("", "") | ||
func retriveUserInput() -> (name: String, lastName: String) { | ||
didCallRetriveUserInputCount += 1 | ||
return userInput | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
SWDestinyTradesTests/Screens/NewPerson/Mirror/NewPersonView+Mirror.swift
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 @@ | ||
// | ||
// NewPersonView+Mirror.swift | ||
// SWDestinyTradesTests | ||
// | ||
// Created by Diogo Autilio on 29/02/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
@testable import SWDestinyTrades | ||
|
||
extension NewPersonView { | ||
|
||
var firstNameTextField: FloatingTextfield { | ||
Mirror.extract(variable: "firstNameTextField", from: self)! | ||
} | ||
|
||
var lastNameTextField: FloatingTextfield { | ||
Mirror.extract(variable: "lastNameTextField", from: self)! | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
SWDestinyTradesTests/Screens/NewPerson/View/NewPersonViewTests.swift
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,52 @@ | ||
// | ||
// NewPersonViewTests.swift | ||
// SWDestinyTradesTests | ||
// | ||
// Created by Diogo Autilio on 29/02/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import XCTest | ||
|
||
@testable import SWDestinyTrades | ||
|
||
final class NewPersonViewTests: XCTestCase { | ||
|
||
private var sut: NewPersonView! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
sut = NewPersonView(frame: .testDevice) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
super.tearDown() | ||
} | ||
|
||
func test_retriveUserInput() { | ||
sut.firstNameTextField.text = "Darth" | ||
sut.lastNameTextField.text = "Vader" | ||
|
||
let userInput = sut.retriveUserInput() | ||
|
||
XCTAssertEqual(userInput.name, "Darth") | ||
XCTAssertEqual(userInput.lastName, "Vader") | ||
} | ||
|
||
func test_textFieldShouldReturn() { | ||
// isFirstResponder needs a UIWindow to work properly | ||
let controller = UIViewController() | ||
let keyWindow = UIWindow(frame: .testDevice) | ||
controller.view = sut | ||
keyWindow.showTestWindow(controller: controller) | ||
|
||
XCTAssertFalse(sut.lastNameTextField.isFirstResponder) | ||
|
||
let result = sut.textFieldShouldReturn(sut.firstNameTextField) | ||
|
||
XCTAssertTrue(sut.lastNameTextField.isFirstResponder) | ||
XCTAssertTrue(result) | ||
} | ||
} |