From 672347e7526dbfa9fa89b02fe48eff3eb679cf89 Mon Sep 17 00:00:00 2001 From: Aleksandr Prianichnikov Date: Mon, 23 Oct 2017 14:17:53 +0300 Subject: [PATCH] Resolve errors after merge & improve tests - Improve tests for MessageInputBar - Remove useless tests --- MessageKit.xcodeproj/project.pbxproj | 20 +-- .../MessagesViewControllerTests.swift | 17 ++ .../MessagesDisplayDelegateTests.swift | 3 +- Tests/ViewsTests/InputBarItemTests.swift | 9 -- Tests/ViewsTests/MessageInputBarTests.swift | 151 +++++++++++------- 5 files changed, 118 insertions(+), 82 deletions(-) diff --git a/MessageKit.xcodeproj/project.pbxproj b/MessageKit.xcodeproj/project.pbxproj index 1258a835..91cb7a93 100644 --- a/MessageKit.xcodeproj/project.pbxproj +++ b/MessageKit.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 38C57C791F9AE3E50043CC03 /* SeparatorLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38C57C781F9AE3E50043CC03 /* SeparatorLine.swift */; }; + 38C57C7C1F9AE4890043CC03 /* InputStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38C57C7B1F9AE4870043CC03 /* InputStackView.swift */; }; 88916B2D1CF0DF2F00469F91 /* MessageKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88916B221CF0DF2F00469F91 /* MessageKit.framework */; }; 8962AC8A1F87AB7D0030B058 /* MessagesCollectionViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8962AC831F87AB230030B058 /* MessagesCollectionViewTests.swift */; }; 8962AC8B1F87AB7D0030B058 /* InputBarItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8962AC841F87AB230030B058 /* InputBarItemTests.swift */; }; @@ -24,12 +26,6 @@ 8962AC991F87AB860030B058 /* MessagesDisplayDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8962AC811F87AB230030B058 /* MessagesDisplayDelegateTests.swift */; }; 8962AC9A1F87ABB20030B058 /* MockMessagesDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8962AC7A1F87AB230030B058 /* MockMessagesDataSource.swift */; }; 8962AC9C1F87ABC60030B058 /* MockMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8962AC7B1F87AB230030B058 /* MockMessage.swift */; }; - 372F6AEF1F36C61000B57FBD /* AvatarViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372F6AEE1F36C61000B57FBD /* AvatarViewTests.swift */; }; - 376AD1861F4259270083072A /* MessagesDisplayDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 376AD1851F4259270083072A /* MessagesDisplayDataSourceTests.swift */; }; - 38C57C791F9AE3E50043CC03 /* SeparatorLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38C57C781F9AE3E50043CC03 /* SeparatorLine.swift */; }; - 38C57C7C1F9AE4890043CC03 /* InputStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38C57C7B1F9AE4870043CC03 /* InputStackView.swift */; }; - 88916B2D1CF0DF2F00469F91 /* MessageKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88916B221CF0DF2F00469F91 /* MessageKit.framework */; }; - 88916B451CF0DF5900469F91 /* MessageKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88916B431CF0DF5900469F91 /* MessageKitTests.swift */; }; B006FA021F99DE2100509C46 /* MessageIntermediateLayoutAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = B006FA011F99DE2100509C46 /* MessageIntermediateLayoutAttributes.swift */; }; B0C8D99B1F73076B000A86E4 /* MessageKitAssets.bundle in Resources */ = {isa = PBXBuildFile; fileRef = B0C8D99A1F73076B000A86E4 /* MessageKitAssets.bundle */; }; B7A03F181F86682C006AEF79 /* MessagesCollectionViewFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A03F161F86682C006AEF79 /* MessagesCollectionViewFlowLayout.swift */; }; @@ -92,6 +88,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 38C57C781F9AE3E50043CC03 /* SeparatorLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SeparatorLine.swift; sourceTree = ""; }; + 38C57C7B1F9AE4870043CC03 /* InputStackView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputStackView.swift; sourceTree = ""; }; 88916B221CF0DF2F00469F91 /* MessageKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MessageKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 88916B2C1CF0DF2F00469F91 /* MessageKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MessageKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 8962AC741F87AB230030B058 /* MessageKitDateFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageKitDateFormatterTests.swift; sourceTree = ""; }; @@ -111,14 +109,6 @@ 8962AC871F87AB230030B058 /* InputTextViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputTextViewTests.swift; sourceTree = ""; }; 8962AC881F87AB230030B058 /* MessageInputBarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageInputBarTests.swift; sourceTree = ""; }; 8962AC891F87AB230030B058 /* MessageDateHeaderViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageDateHeaderViewTests.swift; sourceTree = ""; }; - 372F6AEE1F36C61000B57FBD /* AvatarViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarViewTests.swift; sourceTree = ""; }; - 376AD1851F4259270083072A /* MessagesDisplayDataSourceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessagesDisplayDataSourceTests.swift; sourceTree = ""; }; - 38C57C781F9AE3E50043CC03 /* SeparatorLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SeparatorLine.swift; sourceTree = ""; }; - 38C57C7B1F9AE4870043CC03 /* InputStackView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputStackView.swift; sourceTree = ""; }; - 88916B221CF0DF2F00469F91 /* MessageKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MessageKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 88916B2C1CF0DF2F00469F91 /* MessageKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MessageKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 88916B421CF0DF5900469F91 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 88916B431CF0DF5900469F91 /* MessageKitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageKitTests.swift; sourceTree = ""; }; B006FA011F99DE2100509C46 /* MessageIntermediateLayoutAttributes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageIntermediateLayoutAttributes.swift; sourceTree = ""; }; B0C8D99A1F73076B000A86E4 /* MessageKitAssets.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = MessageKitAssets.bundle; sourceTree = ""; }; B7A03F161F86682C006AEF79 /* MessagesCollectionViewFlowLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessagesCollectionViewFlowLayout.swift; sourceTree = ""; }; @@ -273,8 +263,8 @@ 8962AC791F87AB230030B058 /* Mocks */ = { isa = PBXGroup; children = ( - 8962AC7A1F87AB230030B058 /* MockMessagesDataSource.swift */, 8962AC7B1F87AB230030B058 /* MockMessage.swift */, + 8962AC7A1F87AB230030B058 /* MockMessagesDataSource.swift */, ); path = Mocks; sourceTree = ""; diff --git a/Tests/ControllersTest/MessagesViewControllerTests.swift b/Tests/ControllersTest/MessagesViewControllerTests.swift index c9825539..c49d0978 100644 --- a/Tests/ControllersTest/MessagesViewControllerTests.swift +++ b/Tests/ControllersTest/MessagesViewControllerTests.swift @@ -29,6 +29,9 @@ import CoreLocation class MessagesViewControllerTests: XCTestCase { var sut: MessagesViewController! + // swiftlint:disable weak_delegate + private var layoutDelegate = MockLayoutDelegate() + // swiftlint:enable weak_delegate // MARK: - Overridden Methods @@ -36,6 +39,7 @@ class MessagesViewControllerTests: XCTestCase { super.setUp() sut = MessagesViewController() + sut.messagesCollectionView.messagesLayoutDelegate = layoutDelegate _ = sut.view sut.beginAppearanceTransition(true, animated: true) sut.endAppearanceTransition() @@ -239,3 +243,16 @@ class MessagesViewControllerTests: XCTestCase { } } + +private class MockLayoutDelegate: MessagesLayoutDelegate, LocationMessageLayoutDelegate, MediaMessageLayoutDelegate { + + // MARK: - LocationMessageLayoutDelegate + + func heightForLocation(message: MessageType, at indexPath: IndexPath, with maxWidth: CGFloat, in messagesCollectionView: MessagesCollectionView) -> CGFloat { + return 0.0 + } + + func heightForMedia(message: MessageType, at indexPath: IndexPath, with maxWidth: CGFloat, in messagesCollectionView: MessagesCollectionView) -> CGFloat { + return 10.0 + } +} diff --git a/Tests/ProtocolsTests/MessagesDisplayDelegateTests.swift b/Tests/ProtocolsTests/MessagesDisplayDelegateTests.swift index 27b55cd0..b783e3d8 100644 --- a/Tests/ProtocolsTests/MessagesDisplayDelegateTests.swift +++ b/Tests/ProtocolsTests/MessagesDisplayDelegateTests.swift @@ -237,7 +237,7 @@ class TextMessageDisplayDelegateTests: XCTestCase { } -private class MockMessagesViewController: MessagesViewController, MessagesDisplayDelegate, TextMessageDisplayDelegate { +private class MockMessagesViewController: MessagesViewController, MessagesDisplayDelegate, TextMessageDisplayDelegate, MessagesLayoutDelegate { var dataProvider: MockMessagesDataSource! @@ -246,6 +246,7 @@ private class MockMessagesViewController: MessagesViewController, MessagesDispla dataProvider = makeDataSource() messagesCollectionView.messagesDataSource = dataProvider + messagesCollectionView.messagesLayoutDelegate = self } private func makeDataSource() -> MockMessagesDataSource { diff --git a/Tests/ViewsTests/InputBarItemTests.swift b/Tests/ViewsTests/InputBarItemTests.swift index f9b0f78c..fbacfd08 100644 --- a/Tests/ViewsTests/InputBarItemTests.swift +++ b/Tests/ViewsTests/InputBarItemTests.swift @@ -48,15 +48,6 @@ class InputBarItemTests: XCTestCase { XCTAssertEqual(button.titleColor(for: .disabled), UIColor.lightGray) XCTAssertFalse(button.adjustsImageWhenHighlighted) } - - func testFlexibleSpace() { - XCTAssertEqual(InputBarButtonItem.flexibleSpace.size, .zero) - } - - func testFixedSpace() { - let item = InputBarButtonItem.fixedSpace(100) - XCTAssertEqual(item.size, .zero) - } func testImagePropertyDefaultNil() { XCTAssertNil(button.image) diff --git a/Tests/ViewsTests/MessageInputBarTests.swift b/Tests/ViewsTests/MessageInputBarTests.swift index 95b3c323..343b0c6b 100644 --- a/Tests/ViewsTests/MessageInputBarTests.swift +++ b/Tests/ViewsTests/MessageInputBarTests.swift @@ -1,18 +1,18 @@ /* MIT License - + Copyright (c) 2017 MessageKit - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,72 +26,109 @@ import XCTest @testable import MessageKit class MessageInputBarTests: XCTestCase { - - var inputBar: MessageInputBar! - + + var sut: MessageInputBar! + override func setUp() { super.setUp() - inputBar = MessageInputBar() + sut = MessageInputBar() } - + override func tearDown() { - inputBar = nil + sut = nil super.tearDown() } - - func testBlurEffect() { - XCTAssertFalse(inputBar.blurView.translatesAutoresizingMaskIntoConstraints) - XCTAssertTrue(inputBar.blurView.isHidden) + + func testBlurEffectTranslatesAutoresizingMaskIntoConstraints_IsFalseAfterInit() { + XCTAssertFalse(sut.blurView.translatesAutoresizingMaskIntoConstraints) + } + + func testBlurEffectIsHidden_IsTrueAfterInit() { + XCTAssertTrue(sut.blurView.isHidden) + } + + func testIsTranslucent_IsFalseForDefault() { + XCTAssertFalse(sut.isTranslucent) + } + + func testBlurViewIsHidden_IsFalseWhenIsTranslucentIsTrue() { + sut.isTranslucent = true + XCTAssertFalse(sut.blurView.isHidden) + } + + func testBackgroundColor_IsClearWhenIsTranslucentIsTrue() { + sut.isTranslucent = true + XCTAssertEqual(sut.backgroundColor, UIColor.clear) + } + + func testBlurViewIsHidden_IsTrueWhenIsTranslucentIsFalse() { + sut.isTranslucent = false + XCTAssertTrue(sut.blurView.isHidden) + } + + func testBackgroundColor_IsWhiteWhenIsTranslucentIsFalse() { + sut.isTranslucent = false + XCTAssertEqual(sut.backgroundColor, UIColor.white) + } + + func testSeparatorLine_IsNotNilAfterInit() { + XCTAssertNotNil(sut.separatorLine) + } + + func testLeftStackView_IsNotNilAfterInit() { + XCTAssertNotNil(sut.leftStackView) + } + + func testLeftStackViewAxis_IsHorizontalAfterInit() { + XCTAssertEqual(sut.leftStackView.axis, .horizontal) + } + + func testLeftStackViewSpacing_IsZeroAfterInit() { + XCTAssertEqual(sut.leftStackView.spacing, 0) } - func testIsTranslucent() { - inputBar.isTranslucent = false - XCTAssertTrue(inputBar.blurView.isHidden) - XCTAssertEqual(inputBar.backgroundColor, UIColor.white) - inputBar.isTranslucent = true - XCTAssertFalse(inputBar.blurView.isHidden) - XCTAssertEqual(inputBar.backgroundColor, UIColor.clear) + func testRightStackView_IsNotNilAfterInit() { + XCTAssertNotNil(sut.rightStackView) } - - func testSeparatorLine() { - XCTAssertEqual(inputBar.separatorLine.backgroundColor, UIColor.lightGray) - XCTAssertFalse(inputBar.separatorLine.translatesAutoresizingMaskIntoConstraints) + + func testRightStackViewAxis_IsHorizontalAfterInit() { + XCTAssertEqual(sut.rightStackView.axis, .horizontal) } - - func testLeftStackView() { - XCTAssertEqual(inputBar.leftStackView.axis, .horizontal) - XCTAssertEqual(inputBar.leftStackView.distribution, .fill) - XCTAssertEqual(inputBar.leftStackView.alignment, .fill) - XCTAssertEqual(inputBar.leftStackView.spacing, 15) - XCTAssertFalse(inputBar.leftStackView.translatesAutoresizingMaskIntoConstraints) + + func testRightStackViewSpacing_IsZeroAfterInit() { + XCTAssertEqual(sut.rightStackView.spacing, 0) } - - func testRightStackView() { - XCTAssertEqual(inputBar.rightStackView.axis, .horizontal) - XCTAssertEqual(inputBar.rightStackView.distribution, .fill) - XCTAssertEqual(inputBar.rightStackView.alignment, .fill) - XCTAssertEqual(inputBar.rightStackView.spacing, 15) - XCTAssertFalse(inputBar.rightStackView.translatesAutoresizingMaskIntoConstraints) + + func testBottomStackView_IsNotNilAfterInit() { + XCTAssertNotNil(sut.bottomStackView) } - - func testBottomStackView() { - XCTAssertEqual(inputBar.bottomStackView.axis, .horizontal) - XCTAssertEqual(inputBar.bottomStackView.distribution, .fill) - XCTAssertEqual(inputBar.bottomStackView.alignment, .fill) - XCTAssertEqual(inputBar.bottomStackView.spacing, 15) - XCTAssertFalse(inputBar.bottomStackView.translatesAutoresizingMaskIntoConstraints) + + func testBottomStackViewAxis_IsHorizontalAfterInit() { + XCTAssertEqual(sut.bottomStackView.axis, .horizontal) } - - func testInputTextView() { - XCTAssertFalse(inputBar.inputTextView.translatesAutoresizingMaskIntoConstraints) - XCTAssertEqual(inputBar.inputTextView.messageInputBar, inputBar) + + func testBottomStackViewSpacing_IsZeroAfterInit() { + XCTAssertEqual(sut.bottomStackView.spacing, 15) } - - func testSendButton() { - XCTAssertEqual(inputBar.sendButton.size, CGSize(width: 52, height: 28)) - XCTAssertEqual(inputBar.sendButton.title, "Send") - XCTAssertEqual(inputBar.sendButton.titleLabel?.font, UIFont.preferredFont(forTextStyle: .headline)) - XCTAssertFalse(inputBar.sendButton.isEnabled) + + func testInputTextViewMessageInputBar_IsSelf() { + XCTAssertEqual(sut.inputTextView.messageInputBar, sut) } - + + func testInputTextViewTranslatesAutoresizingMaskIntoConstraints_IsFalseAfterInit() { + XCTAssertFalse(sut.inputTextView.translatesAutoresizingMaskIntoConstraints) + } + + func testSendButtonTitle_IsSendAfterInit() { + XCTAssertEqual(sut.sendButton.title, "Send") + } + + func testSendButtonIsEnabled_IsFalseAfterInit() { + XCTAssertFalse(sut.sendButton.isEnabled) + } + + func testSendButtonFont_IsHeadlineAfterInit() { + XCTAssertEqual(sut.sendButton.titleLabel?.font, UIFont.preferredFont(forTextStyle: .headline)) + } + }