|
| 1 | +// |
| 2 | +// UITextField+ApplyStyleTests.swift |
| 3 | +// ApplyStyleKitTests |
| 4 | +// |
| 5 | +// Created by shindyu on 2019/04/08. |
| 6 | +// Copyright © 2019 shindyu. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import XCTest |
| 10 | + |
| 11 | +class UITextField_ApplyStyleTests: XCTestCase { |
| 12 | + var textField: UITextField! |
| 13 | + |
| 14 | + override func setUp() { |
| 15 | + textField = UITextField() |
| 16 | + } |
| 17 | + |
| 18 | + func test_text() { |
| 19 | + let text = "test" |
| 20 | + textField.applyStyle.text(text) |
| 21 | + |
| 22 | + XCTAssertEqual(textField.text, text) |
| 23 | + } |
| 24 | + |
| 25 | +// func test_attributedText() { |
| 26 | +// let attributedText: NSAttributedString? = nil |
| 27 | +// textField.applyStyle.attributedText(attributedText) |
| 28 | +// |
| 29 | +// XCTAssertEqual(textField.attributedText, attributedText) |
| 30 | +// } |
| 31 | + |
| 32 | + func test_textColor() { |
| 33 | + let textColor: UIColor = .blue |
| 34 | + textField.applyStyle.textColor(textColor) |
| 35 | + |
| 36 | + XCTAssertEqual(textField.textColor, textColor) |
| 37 | + } |
| 38 | + |
| 39 | + func test_font() { |
| 40 | + let font = UIFont.boldSystemFont(ofSize: 12) |
| 41 | + textField.applyStyle.font(font) |
| 42 | + |
| 43 | + XCTAssertEqual(textField.font, font) |
| 44 | + } |
| 45 | + |
| 46 | + func test_textAlignment() { |
| 47 | + let textAlignment: NSTextAlignment = .right |
| 48 | + textField.applyStyle.textAlignment(textAlignment) |
| 49 | + |
| 50 | + XCTAssertEqual(textField.textAlignment, textAlignment) |
| 51 | + } |
| 52 | + |
| 53 | + func test_borderStyle() { |
| 54 | + let borderStyle: UITextField.BorderStyle = .bezel |
| 55 | + textField.applyStyle.borderStyle(borderStyle) |
| 56 | + |
| 57 | + XCTAssertEqual(textField.borderStyle, borderStyle) |
| 58 | + } |
| 59 | + |
| 60 | +// func test_defaultTextAttributes() { |
| 61 | +// let defaultTextAttributes: [NSAttributedString.Key: Any] = [.strokeColor: UIColor.red] |
| 62 | +// |
| 63 | +// textField.applyStyle.defaultTextAttributes(defaultTextAttributes) |
| 64 | +// |
| 65 | +// XCTAssertEqual(textField.defaultTextAttributes, defaultTextAttributes) |
| 66 | +// } |
| 67 | + |
| 68 | + func test_placeholder() { |
| 69 | + let placeholder = "placeholder" |
| 70 | + textField.applyStyle.placeholder(placeholder) |
| 71 | + |
| 72 | + XCTAssertEqual(textField.placeholder, placeholder) |
| 73 | + } |
| 74 | + |
| 75 | + func test_attributedPlaceholder() { |
| 76 | + let attributedPlaceholder = NSAttributedString(string: "attributedPlaceholder") |
| 77 | + textField.applyStyle.attributedPlaceholder(attributedPlaceholder) |
| 78 | + |
| 79 | + XCTAssertEqual(textField.attributedPlaceholder, attributedPlaceholder) |
| 80 | + } |
| 81 | + |
| 82 | + func test_clearsOnBeginEditing() { |
| 83 | + let clearsOnBeginEditing = true |
| 84 | + textField.applyStyle.clearsOnBeginEditing(clearsOnBeginEditing) |
| 85 | + |
| 86 | + XCTAssertEqual(textField.clearsOnBeginEditing, clearsOnBeginEditing) |
| 87 | + } |
| 88 | + |
| 89 | + func test_adjustsFontSizeToFitWidth() { |
| 90 | + let adjustsFontSizeToFitWidth = true |
| 91 | + textField.applyStyle.adjustsFontSizeToFitWidth(adjustsFontSizeToFitWidth) |
| 92 | + |
| 93 | + XCTAssertEqual(textField.adjustsFontSizeToFitWidth, adjustsFontSizeToFitWidth) |
| 94 | + } |
| 95 | + |
| 96 | + func test_minimumFontSize() { |
| 97 | + let minimumFontSize: CGFloat = 2.0 |
| 98 | + textField.applyStyle.minimumFontSize(minimumFontSize) |
| 99 | + |
| 100 | + XCTAssertEqual(textField.minimumFontSize, minimumFontSize) |
| 101 | + } |
| 102 | + |
| 103 | + func test_delegate() { |
| 104 | + let delegate = self |
| 105 | + textField.applyStyle.delegate(delegate) |
| 106 | + |
| 107 | + XCTAssertEqual(textField.delegate as! NSObject, delegate) |
| 108 | + } |
| 109 | + |
| 110 | + func test_background() { |
| 111 | + let image: UIImage = .createEmptyImage() |
| 112 | + textField.applyStyle.background(image) |
| 113 | + |
| 114 | + XCTAssertEqual(textField.background, image) |
| 115 | + } |
| 116 | + |
| 117 | + func test_disabledBackground() { |
| 118 | + let image: UIImage = .createEmptyImage() |
| 119 | + textField.applyStyle.disabledBackground(image) |
| 120 | + |
| 121 | + XCTAssertEqual(textField.disabledBackground, image) |
| 122 | + } |
| 123 | + |
| 124 | + func test_allowsEditingTextAttributes() { |
| 125 | + let allowsEditingTextAttributes = true |
| 126 | + textField.applyStyle.allowsEditingTextAttributes(allowsEditingTextAttributes) |
| 127 | + |
| 128 | + XCTAssertEqual(textField.allowsEditingTextAttributes, allowsEditingTextAttributes) |
| 129 | + } |
| 130 | + |
| 131 | +// func test_typingAttributes() { |
| 132 | +// let typingAttributes: [NSAttributedString.Key: Any]? = [.strokeColor: UIColor.red] |
| 133 | +// textField.applyStyle.typingAttributes(typingAttributes) |
| 134 | +// |
| 135 | +// XCTAssertEqual(textField.typingAttributes, typingAttributes) |
| 136 | +// } |
| 137 | + |
| 138 | + func test_clearButtonMode() { |
| 139 | + let clearButtonMode: UITextField.ViewMode = .unlessEditing |
| 140 | + textField.applyStyle.clearButtonMode(clearButtonMode) |
| 141 | + |
| 142 | + XCTAssertEqual(textField.clearButtonMode, clearButtonMode) |
| 143 | + } |
| 144 | + |
| 145 | + func test_leftView() { |
| 146 | + let view = UIView() |
| 147 | + textField.applyStyle.leftView(view) |
| 148 | + |
| 149 | + XCTAssertEqual(textField.leftView, view) |
| 150 | + } |
| 151 | + |
| 152 | + func test_leftViewMode() { |
| 153 | + let leftViewMode: UITextField.ViewMode = .unlessEditing |
| 154 | + textField.applyStyle.leftViewMode(leftViewMode) |
| 155 | + |
| 156 | + XCTAssertEqual(textField.leftViewMode, leftViewMode) |
| 157 | + } |
| 158 | + |
| 159 | + func test_rightView() { |
| 160 | + let view = UIView() |
| 161 | + textField.applyStyle.rightView(view) |
| 162 | + |
| 163 | + XCTAssertEqual(textField.rightView, view) |
| 164 | + } |
| 165 | + |
| 166 | + func test_rightViewMode() { |
| 167 | + let rightViewMode: UITextField.ViewMode = .unlessEditing |
| 168 | + textField.applyStyle.rightViewMode(rightViewMode) |
| 169 | + |
| 170 | + XCTAssertEqual(textField.rightViewMode, rightViewMode) |
| 171 | + } |
| 172 | + |
| 173 | + func test_inputView() { |
| 174 | + let view = UIView() |
| 175 | + textField.applyStyle.inputView(view) |
| 176 | + |
| 177 | + XCTAssertEqual(textField.inputView, view) |
| 178 | + } |
| 179 | + |
| 180 | + func test_inputAccessoryView() { |
| 181 | + let view = UIView() |
| 182 | + textField.applyStyle.inputAccessoryView(view) |
| 183 | + |
| 184 | + XCTAssertEqual(textField.inputAccessoryView, view) |
| 185 | + } |
| 186 | + |
| 187 | + func test_clearsOnInsertion() { |
| 188 | + let clearsOnInsertion = true |
| 189 | + textField.applyStyle.clearsOnInsertion(clearsOnInsertion) |
| 190 | + |
| 191 | + XCTAssertEqual(textField.clearsOnInsertion, clearsOnInsertion) |
| 192 | + } |
| 193 | +} |
| 194 | + |
| 195 | +extension UITextField_ApplyStyleTests: UITextFieldDelegate { |
| 196 | + |
| 197 | +} |
0 commit comments