Skip to content

Commit

Permalink
add test case for check return of audio message cell
Browse files Browse the repository at this point in the history
  • Loading branch information
moldovaniosif committed Oct 4, 2018
1 parent 9ebcd8c commit 09907c1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Tests/ControllersTest/MessagesViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ class MessagesViewControllerTests: XCTestCase {
XCTAssertTrue(cell is LocationMessageCell)
}

func testCellForItemWithAudioData_returnsAudioMessageCell() {
let messagesDataSource = MockMessagesDataSource()
sut.messagesCollectionView.messagesDataSource = messagesDataSource
messagesDataSource.messages.append(MockMessage(audioURL: URL.init(fileURLWithPath: ""),
sender: messagesDataSource.senders[0],
messageId: "test_id"))

sut.messagesCollectionView.reloadData()

let cell = sut.messagesCollectionView.dataSource?.collectionView(sut.messagesCollectionView,
cellForItemAt: IndexPath(item: 0, section: 0))

XCTAssertNotNil(cell)
XCTAssertTrue(cell is AudioMessageCell)
}

// MARK: - Assistants

private func makeMessages(for senders: [Sender]) -> [MessageType] {
Expand Down
23 changes: 23 additions & 0 deletions Tests/Mocks/MockMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import Foundation
import CoreLocation
import AVFoundation
@testable import MessageKit

struct MockLocationItem: LocationItem {
Expand Down Expand Up @@ -53,6 +54,23 @@ struct MockMediaItem: MediaItem {

}

private struct MockAudiotem: AudioItem {

var url: URL
var size: CGSize
var duration: Float

init(url: URL) {
self.url = url
self.size = CGSize(width: 160, height: 35)
// compute duration
let audioAsset = AVURLAsset.init(url: url)
self.duration = Float(CMTimeGetSeconds(audioAsset.duration))
}

}


struct MockMessage: MessageType {

var messageId: String
Expand Down Expand Up @@ -94,4 +112,9 @@ struct MockMessage: MessageType {
self.init(kind: .emoji(emoji), sender: sender, messageId: messageId)
}

init(audioURL: URL, sender: Sender, messageId: String) {
let audioItem = MockAudiotem(url: audioURL)
self.init(kind: .audio(audioItem), sender: sender, messageId: messageId)
}

}

0 comments on commit 09907c1

Please sign in to comment.