blob: 4d7771d6550bbe7c1822d61db89ccd7ce654382e [file]
/*
Copyright 2016-present the Material Components for iOS authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// swiftlint:disable function_body_length
// swiftlint:disable type_body_length
import XCTest
import MaterialComponents.MaterialTextFields
class MultilineTextFieldLegacyTests: XCTestCase {
func testSerializationLegacy() {
let textField = MDCMultilineTextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.text = "Lorem ipsum dolor sit amet, consectetuer adipiscing"
let controller = MDCTextInputControllerLegacyDefault(textInput: textField)
XCTAssertNotNil(controller.textInput)
let leadingText = "Serialized Helper Test"
controller.helperText = leadingText
controller.characterCountMax = 40
let serializedInput = NSKeyedArchiver.archivedData(withRootObject: textField)
XCTAssertNotNil(serializedInput)
let unserializedInput =
NSKeyedUnarchiver.unarchiveObject(with: serializedInput) as? MDCMultilineTextField
XCTAssertNotNil(unserializedInput)
XCTAssertEqual(textField.translatesAutoresizingMaskIntoConstraints,
unserializedInput?.translatesAutoresizingMaskIntoConstraints)
XCTAssertEqual(textField.text,
unserializedInput?.text)
XCTAssertEqual(textField.leadingUnderlineLabel.text,
unserializedInput?.leadingUnderlineLabel.text)
XCTAssertEqual(textField.trailingUnderlineLabel.text, "51 / 40")
XCTAssertEqual(textField.trailingUnderlineLabel.text,
unserializedInput?.trailingUnderlineLabel.text)
}
}