forked from badoo/Chatto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f7daf5
commit 8d3b23c
Showing
12 changed files
with
607 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
64 changes: 64 additions & 0 deletions
64
ChattoAdditions/Tests/Chat Items/BaseMessage/CompoundMessagePresenterTests.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015-present Badoo Trading Limited. | ||
// | ||
// 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 | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
@testable import ChattoAdditions | ||
import XCTest | ||
|
||
@available(iOS 11, *) | ||
final class CompoundMessagePresenterTests: XCTestCase { | ||
|
||
func test_WhenPresenterIsUpdatedWithTheSameMessage_ThenUpdateContentNotCalled_AndUpdateExistingContentPresentersNotCalled() { | ||
let message = TestHelpers.makeMessage(withId: "123") | ||
let sameMessage = message | ||
let presenter = TestHelpers.makeTestableCompoundMessagePresenter(with: message) | ||
|
||
presenter.update(with: sameMessage) | ||
|
||
XCTAssertEqual(0, presenter.invokedUpdateContentCount) | ||
XCTAssertEqual(0, presenter.invokedUpdateExistingContentPresentersCount) | ||
} | ||
|
||
func test_WhenPresenterIsUpdatedWithMessageWithAnotherContent_ThenUpdateContentCalled_ButUpdateExistingContentPresentersNotCalled() { | ||
let date = Date() | ||
let anotherDate = date.addingTimeInterval(1) | ||
let message = TestHelpers.makeMessage(withId: "123", date: date) | ||
let sameMessageWithAnotherId = TestHelpers.makeMessage(withId: "123", date: anotherDate) | ||
let presenter = TestHelpers.makeTestableCompoundMessagePresenter(with: message) | ||
|
||
presenter.update(with: sameMessageWithAnotherId) | ||
|
||
XCTAssertEqual(1, presenter.invokedUpdateContentCount) | ||
XCTAssertEqual(0, presenter.invokedUpdateExistingContentPresentersCount) | ||
} | ||
|
||
func test_WhenPresenterIsUpdatedWithSameMessageWithAnotherId_ThenUpdateContentNotCalled_ButUpdateExistingContentPresentersCalled() { | ||
let message = TestHelpers.makeMessage(withId: "123") | ||
let sameMessageWithAnotherId = message.makeSameMessage(butAnotherId: "456") | ||
let presenter = TestHelpers.makeTestableCompoundMessagePresenter(with: message) | ||
|
||
presenter.update(with: sameMessageWithAnotherId) | ||
|
||
XCTAssertEqual(0, presenter.invokedUpdateContentCount) | ||
XCTAssertEqual(1, presenter.invokedUpdateExistingContentPresentersCount) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
ChattoAdditions/Tests/Chat Items/BaseMessage/DefaultMessageContentPresenterTests.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015-present Badoo Trading Limited. | ||
// | ||
// 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 | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
@testable import ChattoAdditions | ||
import XCTest | ||
|
||
final class DefaultMessageContentPresenterTests: XCTestCase { | ||
|
||
func test_WhenPresenterIsUpdatedWithTheSameMessageWithAnotherId_ThenOnMessageUpdateClosureIsCalled_AndItIsCalledWithUpdatedMessage() { | ||
let message = TestHelpers.makeMessage(withId: "123") | ||
let sameMessageWithAnotherId = message.makeSameMessage(butAnotherId: "456") | ||
var isOnMessageUpdateCallsCount = 0 | ||
var newMessageOnUpdate: MessageModel! | ||
let presenter = TestHelpers.makeDefaultMessageContentPresenter(with: message, onMessageUpdate: { newMessage in | ||
isOnMessageUpdateCallsCount += 1 | ||
newMessageOnUpdate = newMessage | ||
}) | ||
|
||
presenter.updateMessage(sameMessageWithAnotherId) | ||
|
||
XCTAssertEqual(1, isOnMessageUpdateCallsCount) | ||
XCTAssertEqual(sameMessageWithAnotherId.uid, newMessageOnUpdate!.uid) | ||
} | ||
} |
Oops, something went wrong.