From ecf503a309fab72a08842047ff33d08c8f7237d8 Mon Sep 17 00:00:00 2001 From: Bruno Muniz Azevedo Filho Date: Wed, 18 Oct 2023 01:03:14 -0300 Subject: [PATCH] Fix unit tests --- Sources/Forms/FormInputItem.swift | 4 +-- Sources/Forms/FormSpacingItem.swift | 4 +-- Sources/Forms/FormTextItem.swift | 4 +-- Tests/FormsTests/FormInputItemTests.swift | 39 ++++++++++++++++++++--- Tests/FormsTests/FormTextItemTests.swift | 8 +++-- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Sources/Forms/FormInputItem.swift b/Sources/Forms/FormInputItem.swift index 2e0ecbf..8708040 100644 --- a/Sources/Forms/FormInputItem.swift +++ b/Sources/Forms/FormInputItem.swift @@ -125,9 +125,7 @@ open class FormInputItem: UIView, FormInputType { textField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged) } - required public init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } + required public init?(coder: NSCoder) { nil } private func setupViews() { addSubview(stackView) diff --git a/Sources/Forms/FormSpacingItem.swift b/Sources/Forms/FormSpacingItem.swift index 432610f..d966546 100644 --- a/Sources/Forms/FormSpacingItem.swift +++ b/Sources/Forms/FormSpacingItem.swift @@ -27,7 +27,5 @@ open class FormSpacingItem: UIView, FormItem { } } - required public init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } + required public init?(coder: NSCoder) { nil } } diff --git a/Sources/Forms/FormTextItem.swift b/Sources/Forms/FormTextItem.swift index bd8a8f9..6dfc295 100644 --- a/Sources/Forms/FormTextItem.swift +++ b/Sources/Forms/FormTextItem.swift @@ -75,9 +75,7 @@ open class FormTextItem: UIView, FormItem { setupAccessibility() } - required public init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } + required public init?(coder: NSCoder) { nil } private func setupViews() { addSubview(textLabel) diff --git a/Tests/FormsTests/FormInputItemTests.swift b/Tests/FormsTests/FormInputItemTests.swift index 6c63d0a..1a23166 100644 --- a/Tests/FormsTests/FormInputItemTests.swift +++ b/Tests/FormsTests/FormInputItemTests.swift @@ -7,10 +7,22 @@ final class FormInputItemTests: XCTestCase { let placeholder = "Placeholder" let initialText = "Initial Text" let item = FormInputItem( - title: title, - initialText: initialText, - placeholder: placeholder, - spacingAfter: 20 + configuration: .init( + title: title, + titleAttributes: [:], + initialText: initialText, + placeholder: placeholder, + isSecure: false, + autocorrectionType: .no, + autocapitalizationType: .none, + font: .boldSystemFont(ofSize: 10), + textColor: .blue, + cornerRadius: 10, + borderWidth: 2.0, + borderColor: .black, + spacingAfter: 20, + didChange: nil + ) ) XCTAssertEqual( @@ -32,7 +44,24 @@ final class FormInputItemTests: XCTestCase { } func testConstraintsAreActive() { - let item = FormInputItem() + let item = FormInputItem( + configuration: .init( + title: nil, + titleAttributes: [:], + initialText: nil, + placeholder: nil, + isSecure: false, + autocorrectionType: .default, + autocapitalizationType: .allCharacters, + font: .boldSystemFont(ofSize: 1), + textColor: .black, + cornerRadius: 1, + borderWidth: 1, + borderColor: .black, + spacingAfter: 1, + didChange: nil + ) + ) item.layoutIfNeeded() // Force layout so constraints are activated. for constraint in item.constraints { diff --git a/Tests/FormsTests/FormTextItemTests.swift b/Tests/FormsTests/FormTextItemTests.swift index 667d6db..c182208 100644 --- a/Tests/FormsTests/FormTextItemTests.swift +++ b/Tests/FormsTests/FormTextItemTests.swift @@ -10,9 +10,11 @@ final class FormTextItemTests: XCTestCase { .foregroundColor: UIColor.red ] let item = FormTextItem( - text: text, - attributes: attributes, - spacingAfter: spacing + configuration: .init( + text: text, + attributes: attributes, + spacingAfter: spacing + ) ) XCTAssertEqual( item.spacingAfter, spacing,