Last active
January 17, 2018 20:16
-
-
Save Serchinastico/badfbea475c0c39ae121e19e1d6e9fca to your computer and use it in GitHub Desktop.
View controller sobre el que haremos las pruebas de las acciones con KIF
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
// --------------------------------------------- // | |
// -------------- VIEW CONTROLLER -------------- // | |
// --------------------------------------------- // | |
import UIKit | |
class SuperHeroControlsViewController: UIViewController { | |
var textField: UITextField! | |
var slider: UISlider! | |
var button: UIButton! | |
var `switch`: UISwitch! | |
var stepper: UIStepper! | |
var datePicker: UIDatePicker! | |
var stepperLabel: UILabel! | |
override func viewDidLoad() { | |
textField = UITextField() | |
textField.borderStyle = .roundedRect | |
textField.accessibilityLabel = "Text Field" | |
textField.translatesAutoresizingMaskIntoConstraints = false | |
button = UIButton() | |
button.setTitle("Button", for: .normal) | |
button.accessibilityLabel = "Button" | |
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(onButtonDidPress)) | |
button.addGestureRecognizer(tapGestureRecognizer) | |
button.translatesAutoresizingMaskIntoConstraints = false | |
slider = UISlider() | |
slider.accessibilityLabel = "Slider" | |
slider.maximumValue = 100 | |
slider.minimumValue = 0 | |
slider.value = 50 | |
slider.translatesAutoresizingMaskIntoConstraints = false | |
`switch` = UISwitch() | |
`switch`.accessibilityLabel = "Switch" | |
`switch`.translatesAutoresizingMaskIntoConstraints = false | |
stepper = UIStepper() | |
stepper.accessibilityLabel = "Stepper" | |
stepper.translatesAutoresizingMaskIntoConstraints = false | |
stepper.addTarget(self, action: #selector(onStepperValueChanged), for: .valueChanged) | |
stepperLabel = UILabel() | |
stepperLabel.text = "0" | |
stepperLabel.textColor = .white | |
stepperLabel.font = UIFont.systemFont(ofSize: 20) | |
stepperLabel.translatesAutoresizingMaskIntoConstraints = false | |
datePicker = UIDatePicker() | |
datePicker.accessibilityLabel = "Date Picker" | |
datePicker.setValue(UIColor.white, forKey: "textColor") | |
datePicker.datePickerMode = .date | |
datePicker.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(textField) | |
view.addSubview(button) | |
view.addSubview(slider) | |
view.addSubview(`switch`) | |
view.addSubview(stepper) | |
view.addSubview(stepperLabel) | |
view.addSubview(datePicker) | |
textField.topAnchor.constraint(equalTo: view.topAnchor, constant: 20).isActive = true | |
textField.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20).isActive = true | |
textField.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -20).isActive = true | |
textField.heightAnchor.constraint(equalToConstant: 38).isActive = true | |
slider.topAnchor.constraint(equalTo: textField.bottomAnchor, constant: 20).isActive = true | |
slider.leftAnchor.constraint(equalTo: textField.leftAnchor, constant: 20).isActive = true | |
slider.rightAnchor.constraint(equalTo: textField.rightAnchor, constant: -20).isActive = true | |
button.topAnchor.constraint(equalTo: slider.bottomAnchor).isActive = true | |
button.leftAnchor.constraint(equalTo: textField.leftAnchor).isActive = true | |
button.rightAnchor.constraint(equalTo: textField.rightAnchor).isActive = true | |
`switch`.topAnchor.constraint(equalTo: button.bottomAnchor, constant: 20).isActive = true | |
`switch`.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20).isActive = true | |
stepper.topAnchor.constraint(equalTo: `switch`.bottomAnchor, constant: 20).isActive = true | |
stepper.leftAnchor.constraint(equalTo: textField.leftAnchor).isActive = true | |
stepperLabel.topAnchor.constraint(equalTo: stepper.topAnchor).isActive = true | |
stepperLabel.rightAnchor.constraint(equalTo: textField.rightAnchor).isActive = true | |
datePicker.topAnchor.constraint(equalTo: stepper.bottomAnchor, constant: 20).isActive = true | |
view.setNeedsLayout() | |
} | |
func onButtonDidPress() { | |
textField.text = "Button Pressed!" | |
datePicker.setValue(UIColor.green, forKey: "textColor") | |
} | |
func onStepperValueChanged() { | |
stepperLabel.text = String(stepper.value) | |
} | |
} | |
// --------------------------------------------- // | |
// -------------------- TEST ------------------- // | |
// --------------------------------------------- // | |
import Foundation | |
import KIF | |
import Nimble | |
import UIKit | |
@testable import KataSuperHeroes | |
class SuperHeroesControlsViewControllerTests: AcceptanceTestCase { | |
func testShowsEmptyCaseIfThereAreNoSuperHeroes() { | |
openSuperHeroesViewController() | |
tester().tapView(withAccessibilityLabel: "Button") | |
tester().setValue(0, forSliderWithAccessibilityLabel: "Slider") | |
for _ in (0..<10) { | |
tester().tapStepper(withAccessibilityLabel: "Stepper", increment: .increment) | |
} | |
tester().selectDatePickerValue(["August", "18", "1988"]) | |
tester().clearTextFromView(withAccessibilityLabel: "Text Field") | |
tester().enterText("Hello World!", intoViewWithAccessibilityLabel: "Text Field") | |
} | |
fileprivate func openSuperHeroesViewController() { | |
let superHeroesViewController = ServiceLocator().provideSuperHeroesControlsViewController() | |
let rootViewController = UINavigationController() | |
rootViewController.viewControllers = [superHeroesViewController] | |
present(viewController: rootViewController) | |
tester().waitForAnimationsToFinish() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment