forked from ParisiLabs/wire-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageMessageCellTests.swift
114 lines (89 loc) · 4.05 KB
/
ImageMessageCellTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Wire
// Copyright (C) 2016 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
import XCTest
@testable import Wire
class ImageMessageCellTests: ZMSnapshotTestCase {
var sut: ImageMessageCell! = nil
override func setUp() {
super.setUp()
snapshotBackgroundColor = .whiteColor()
sut = ImageMessageCell(style: .Default, reuseIdentifier: name!)
}
func testThatItRendersImageMessagePlaceholderWhenNoImageIsSet() {
verify(view: sut.prepareForSnapshot(CGSize(width: 450, height: 600)))
}
func testThatItRendersImageMessagePlaceholderWhenNoImageIsSet_LandscapeImage() {
verify(view: sut.prepareForSnapshot(CGSize(width: 650, height: 200)))
}
func testThatItRendersImageMessagePlaceholderWhenNoImageIsSet_SmallImage() {
verify(view: sut.prepareForSnapshot(CGSize(width: 200, height: 200)))
}
func testThatItRendersImageMessageWhenImageIsSet() {
let image = imageInTestBundleNamed("unsplash_matterhorn.jpg")
let cell = sut.prepareForSnapshot(image.size, image: image)
NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 1))
verify(view: cell)
}
func testThatItRendersImageMessageWhenImageIsSet_SmallImage() {
let image = imageInTestBundleNamed("unsplash_small.jpg")
let cell = sut.prepareForSnapshot(image.size, image: image)
NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 1))
verify(view: cell)
}
func testThatItRendersImageMessageWithResendButton() {
let image = imageInTestBundleNamed("unsplash_matterhorn.jpg")
let cell = sut.prepareForSnapshot(image.size, image: image, failedToSend: true)
NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 1))
verify(view: cell)
}
func testThatItRendersImageMessageWithResendButton_SmallImage() {
let image = imageInTestBundleNamed("unsplash_small.jpg")
let cell = sut.prepareForSnapshot(image.size, image: image, failedToSend: true)
NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 1))
verify(view: cell)
}
}
private extension ImageMessageCell {
func prepareForSnapshot(imageSize: CGSize, image: UIImage? = nil, failedToSend: Bool = false) -> ImageMessageCell {
let layoutProperties = ConversationCellLayoutProperties()
layoutProperties.showSender = true
layoutProperties.showBurstTimestamp = false
layoutProperties.showUnreadMarker = false
let message = MockMessageFactory.imageMessage()
message.deliveryState = failedToSend ? .FailedToSend : .Delivered
let imageMessageData = message.imageMessageData as! MockImageMessageData
imageMessageData.mockOriginalSize = imageSize
if let imageData = image?.data() {
imageMessageData.mockImageData = imageData
imageMessageData.mockImageDataIdentifier = NSUUID().UUIDString
}
prepareForReuse()
configureForMessage(message, layoutProperties: layoutProperties)
layoutIfNeeded()
let size = systemLayoutSizeFittingSize(
CGSize(width: 320, height: 0),
withHorizontalFittingPriority: UILayoutPriorityRequired,
verticalFittingPriority: UILayoutPriorityFittingSizeLevel
)
bounds = CGRectMake(0.0, 0.0, size.width, size.height)
layer.speed = 0
setNeedsLayout()
layoutIfNeeded()
return self
}
}