Skip to content

Commit 4865c87

Browse files
added snapshot tests for channel list and chat channel views
1 parent 4b60db4 commit 4865c87

File tree

11 files changed

+184
-0
lines changed

11 files changed

+184
-0
lines changed

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@
132132
8465FDD72746A95800AF091E /* Appearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8465FD692746A95700AF091E /* Appearance.swift */; };
133133
8465FDD82746AA2700AF091E /* StreamChatSwiftUI.h in Headers */ = {isa = PBXBuildFile; fileRef = 8465FD602746A95700AF091E /* StreamChatSwiftUI.h */; settings = {ATTRIBUTES = (Public, ); }; };
134134
8465FDDD2747A14700AF091E /* CustomComposerAttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8465FDDC2747A14700AF091E /* CustomComposerAttachmentView.swift */; };
135+
848399E8275FB3BE003075E4 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 848399E7275FB3BE003075E4 /* SnapshotTesting */; };
136+
848399EA275FB3E9003075E4 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 848399E9275FB3E9003075E4 /* SnapshotTesting */; };
137+
848399EC275FB41B003075E4 /* ChatChannelListView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */; };
138+
848399EE275FBC84003075E4 /* ChatChannelView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848399ED275FBC84003075E4 /* ChatChannelView_Tests.swift */; };
135139
84A75FBB274EA29B00225CE8 /* GiphyAttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A75FBA274EA29B00225CE8 /* GiphyAttachmentView.swift */; };
136140
84AD8425274E2C380098C3C4 /* ChatChannelScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AD8424274E2C380098C3C4 /* ChatChannelScreen.swift */; };
137141
84B288CD274C544B00DD090B /* CreateGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B288CC274C544B00DD090B /* CreateGroupView.swift */; };
@@ -391,6 +395,8 @@
391395
8465FD682746A95700AF091E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
392396
8465FD692746A95700AF091E /* Appearance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Appearance.swift; sourceTree = "<group>"; };
393397
8465FDDC2747A14700AF091E /* CustomComposerAttachmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomComposerAttachmentView.swift; sourceTree = "<group>"; };
398+
848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelListView_Tests.swift; sourceTree = "<group>"; };
399+
848399ED275FBC84003075E4 /* ChatChannelView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelView_Tests.swift; sourceTree = "<group>"; };
394400
84A75FBA274EA29B00225CE8 /* GiphyAttachmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GiphyAttachmentView.swift; sourceTree = "<group>"; };
395401
84AD8424274E2C380098C3C4 /* ChatChannelScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelScreen.swift; sourceTree = "<group>"; };
396402
84B288CC274C544B00DD090B /* CreateGroupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateGroupView.swift; sourceTree = "<group>"; };
@@ -490,6 +496,7 @@
490496
isa = PBXFrameworksBuildPhase;
491497
buildActionMask = 2147483647;
492498
files = (
499+
848399E8275FB3BE003075E4 /* SnapshotTesting in Frameworks */,
493500
8465FCB427468A8D00AF091E /* StreamChat in Frameworks */,
494501
8465FCB727468B0600AF091E /* NukeUI in Frameworks */,
495502
);
@@ -500,6 +507,7 @@
500507
buildActionMask = 2147483647;
501508
files = (
502509
8465FBBE2746873A00AF091E /* StreamChatSwiftUI.framework in Frameworks */,
510+
848399EA275FB3E9003075E4 /* SnapshotTesting in Frameworks */,
503511
);
504512
runOnlyForDeploymentPostprocessing = 0;
505513
};
@@ -825,6 +833,7 @@
825833
84C94D432757C704007FE2B9 /* MoreChannelActionsViewModel_Tests.swift */,
826834
84C94D67275A6AFD007FE2B9 /* ChannelHeaderLoader_Tests.swift */,
827835
84C94D412757C16D007FE2B9 /* ChatChannelListTestHelpers.swift */,
836+
848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */,
828837
);
829838
path = ChatChannelList;
830839
sourceTree = "<group>";
@@ -994,6 +1003,7 @@
9941003
84C94D5027591DE2007FE2B9 /* ChatMessageIDs_Tests.swift */,
9951004
84C94D57275A1B89007FE2B9 /* MessageTypeResolver_Tests.swift */,
9961005
84C94D65275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift */,
1006+
848399ED275FBC84003075E4 /* ChatChannelView_Tests.swift */,
9971007
84C94D4E2758FE59007FE2B9 /* ChatChannelTestHelpers.swift */,
9981008
);
9991009
path = ChatChannel;
@@ -1045,6 +1055,7 @@
10451055
packageProductDependencies = (
10461056
8465FCB327468A8D00AF091E /* StreamChat */,
10471057
8465FCB627468B0600AF091E /* NukeUI */,
1058+
848399E7275FB3BE003075E4 /* SnapshotTesting */,
10481059
);
10491060
productName = StreamChatSwiftUI;
10501061
productReference = 8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */;
@@ -1065,6 +1076,9 @@
10651076
844AE869275EB8CF003225E5 /* PBXTargetDependency */,
10661077
);
10671078
name = StreamChatSwiftUITests;
1079+
packageProductDependencies = (
1080+
848399E9275FB3E9003075E4 /* SnapshotTesting */,
1081+
);
10681082
productName = StreamChatSwiftUITests;
10691083
productReference = 8465FBBD2746873A00AF091E /* StreamChatSwiftUITests.xctest */;
10701084
productType = "com.apple.product-type.bundle.unit-test";
@@ -1123,6 +1137,7 @@
11231137
packageReferences = (
11241138
8465FCB227468A8D00AF091E /* XCRemoteSwiftPackageReference "stream-chat-swift" */,
11251139
8465FCB527468B0600AF091E /* XCRemoteSwiftPackageReference "NukeUI" */,
1140+
848399E6275FB3BE003075E4 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */,
11261141
);
11271142
productRefGroup = 8465FBB62746873A00AF091E /* Products */;
11281143
projectDirPath = "";
@@ -1304,6 +1319,7 @@
13041319
isa = PBXSourcesBuildPhase;
13051320
buildActionMask = 2147483647;
13061321
files = (
1322+
848399EC275FB41B003075E4 /* ChatChannelListView_Tests.swift in Sources */,
13071323
84C94CE127578B92007FE2B9 /* MessageAttachmentPayload.swift in Sources */,
13081324
84C94D54275A1380007FE2B9 /* DateUtils_Tests.swift in Sources */,
13091325
84C94CE527578B92007FE2B9 /* ChatUserSearchController_Mock.swift in Sources */,
@@ -1353,6 +1369,7 @@
13531369
84C94D1127578BF2007FE2B9 /* ChannelId.swift in Sources */,
13541370
84C94CD927578B92007FE2B9 /* ChatChannelMember_Mock.swift in Sources */,
13551371
84C94CDA27578B92007FE2B9 /* ChatUser_Mock.swift in Sources */,
1372+
848399EE275FBC84003075E4 /* ChatChannelView_Tests.swift in Sources */,
13561373
84C94D2C275796F7007FE2B9 /* RequestRecorderURLProtocol.swift in Sources */,
13571374
84C94CD627578B92007FE2B9 /* AttachmentUploadingState_Mock.swift in Sources */,
13581375
84C94D20275792EA007FE2B9 /* MockBackgroundTaskScheduler.swift in Sources */,
@@ -1817,6 +1834,14 @@
18171834
minimumVersion = 0.7.0;
18181835
};
18191836
};
1837+
848399E6275FB3BE003075E4 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */ = {
1838+
isa = XCRemoteSwiftPackageReference;
1839+
repositoryURL = "https://github.com/pointfreeco/swift-snapshot-testing.git";
1840+
requirement = {
1841+
kind = upToNextMajorVersion;
1842+
minimumVersion = 1.8.2;
1843+
};
1844+
};
18201845
/* End XCRemoteSwiftPackageReference section */
18211846

18221847
/* Begin XCSwiftPackageProductDependency section */
@@ -1835,6 +1860,16 @@
18351860
package = 8465FCB227468A8D00AF091E /* XCRemoteSwiftPackageReference "stream-chat-swift" */;
18361861
productName = StreamChat;
18371862
};
1863+
848399E7275FB3BE003075E4 /* SnapshotTesting */ = {
1864+
isa = XCSwiftPackageProductDependency;
1865+
package = 848399E6275FB3BE003075E4 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */;
1866+
productName = SnapshotTesting;
1867+
};
1868+
848399E9275FB3E9003075E4 /* SnapshotTesting */ = {
1869+
isa = XCSwiftPackageProductDependency;
1870+
package = 848399E6275FB3BE003075E4 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */;
1871+
productName = SnapshotTesting;
1872+
};
18381873
/* End XCSwiftPackageProductDependency section */
18391874

18401875
/* Begin XCVersionGroup section */

StreamChatSwiftUI.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StreamChatSwiftUITests/Infrastructure/TestTools/Controllers/ChatChannelListController_Mock.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class ChatChannelListController_Mock: ChatChannelListController {
2727
override public func loadNextChannels(limit: Int?, completion: ((Error?) -> Void)?) {
2828
loadNextChannelsIsCalled = true
2929
}
30+
31+
override public func synchronize(_ completion: ((Error?) -> Void)? = nil) {
32+
completion?(nil)
33+
}
3034
}
3135

3236
public extension ChatChannelListController_Mock {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import SnapshotTesting
6+
@testable import StreamChat
7+
@testable import StreamChatSwiftUI
8+
import XCTest
9+
10+
class ChatChannelView_Tests: XCTestCase {
11+
12+
private var chatClient: ChatClient = {
13+
let client = ChatClient.mock()
14+
client.currentUserId = .unique
15+
return client
16+
}()
17+
18+
private let testMessage = ChatMessage.mock(
19+
id: "test",
20+
cid: .unique,
21+
text: "This is a test message",
22+
author: .mock(id: "test", name: "martin")
23+
)
24+
25+
private var streamChat: StreamChat?
26+
27+
override func setUp() {
28+
super.setUp()
29+
streamChat = StreamChat(chatClient: chatClient)
30+
}
31+
32+
func test_chatChannelScreen_snapshot() {
33+
// Given
34+
let messages = [testMessage]
35+
let controller = ChatChannelTestHelpers.makeChannelController(
36+
chatClient: chatClient,
37+
messages: messages
38+
)
39+
40+
// When
41+
let view = ChatChannelScreen(chatChannelController: controller)
42+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
43+
44+
// Then
45+
assertSnapshot(matching: view, as: .image)
46+
}
47+
48+
func test_chatChannelView_snapshot() {
49+
// Given
50+
let messages = [testMessage]
51+
let controller = ChatChannelTestHelpers.makeChannelController(
52+
chatClient: chatClient,
53+
messages: messages
54+
)
55+
56+
// When
57+
let view = ChatChannelView(
58+
viewFactory: DefaultViewFactory.shared,
59+
channelController: controller
60+
)
61+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
62+
63+
// Then
64+
assertSnapshot(matching: view, as: .image)
65+
}
66+
}
73.2 KB
Loading
73.2 KB
Loading
Loading

StreamChatSwiftUITests/Tests/ChatChannelList/ChatChannelListTestHelpers.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
@testable import StreamChat
66
@testable import StreamChatSwiftUI
7+
import UIKit
8+
9+
/// The default view controller size. Simulates an iPhone in portrait mode.
10+
let defaultScreenSize = CGSize(width: 360, height: 700)
711

812
extension ChannelAlertType: Equatable {
913

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import SnapshotTesting
6+
@testable import StreamChat
7+
@testable import StreamChatSwiftUI
8+
import XCTest
9+
10+
class ChatChannelListView_Tests: XCTestCase {
11+
12+
private var chatClient: ChatClient = {
13+
let client = ChatClient.mock()
14+
client.currentUserId = .unique
15+
return client
16+
}()
17+
18+
private var streamChat: StreamChat?
19+
20+
override func setUp() {
21+
super.setUp()
22+
streamChat = StreamChat(chatClient: chatClient)
23+
}
24+
25+
func test_chatChannelScreen_snapshot() {
26+
// Given
27+
let controller = makeChannelListController()
28+
29+
// When
30+
let view = ChatChannelListScreen(channelListController: controller)
31+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
32+
33+
// Then
34+
assertSnapshot(matching: view, as: .image)
35+
}
36+
37+
func test_chatChannelListView_snapshot() {
38+
// Given
39+
let controller = makeChannelListController()
40+
41+
// When
42+
let view = ChatChannelListView(
43+
viewFactory: DefaultViewFactory.shared,
44+
channelListController: controller
45+
)
46+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
47+
48+
// Then
49+
assertSnapshot(matching: view, as: .image)
50+
}
51+
52+
private func makeChannelListController() -> ChatChannelListController_Mock {
53+
let channelListController = ChatChannelListController_Mock.mock()
54+
channelListController.simulateInitial(channels: mockChannels(), state: .initialized)
55+
return channelListController
56+
}
57+
58+
private func mockChannels() -> [ChatChannel] {
59+
var channels = [ChatChannel]()
60+
for i in 0..<15 {
61+
let channel = ChatChannel.mockDMChannel(name: "test \(i)")
62+
channels.append(channel)
63+
}
64+
return channels
65+
}
66+
}
Loading

0 commit comments

Comments
 (0)