Skip to content

Commit 9bf2ac4

Browse files
added more snapshot tests
1 parent d87929d commit 9bf2ac4

File tree

9 files changed

+158
-2
lines changed

9 files changed

+158
-2
lines changed

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@
225225
84C94D62275A5BB7007FE2B9 /* ChatChannelNamer_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D61275A5BB7007FE2B9 /* ChatChannelNamer_Tests.swift */; };
226226
84C94D66275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D65275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift */; };
227227
84C94D68275A6AFD007FE2B9 /* ChannelHeaderLoader_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C94D67275A6AFD007FE2B9 /* ChannelHeaderLoader_Tests.swift */; };
228+
84DEC8DB27609FA200172876 /* MoreChannelActionsView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DEC8DA27609FA200172876 /* MoreChannelActionsView_Tests.swift */; };
229+
84DEC8DD2760A10500172876 /* NoChannelsView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DEC8DC2760A10500172876 /* NoChannelsView_Tests.swift */; };
230+
84DEC8DF2760A1D100172876 /* MessageView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DEC8DE2760A1D100172876 /* MessageView_Tests.swift */; };
228231
84EDBC37274FE5CD0057218D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 84EDBC36274FE5CD0057218D /* Localizable.strings */; };
229232
/* End PBXBuildFile section */
230233

@@ -487,6 +490,9 @@
487490
84C94D61275A5BB7007FE2B9 /* ChatChannelNamer_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelNamer_Tests.swift; sourceTree = "<group>"; };
488491
84C94D65275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageActionsViewModel_Tests.swift; sourceTree = "<group>"; };
489492
84C94D67275A6AFD007FE2B9 /* ChannelHeaderLoader_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelHeaderLoader_Tests.swift; sourceTree = "<group>"; };
493+
84DEC8DA27609FA200172876 /* MoreChannelActionsView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreChannelActionsView_Tests.swift; sourceTree = "<group>"; };
494+
84DEC8DC2760A10500172876 /* NoChannelsView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoChannelsView_Tests.swift; sourceTree = "<group>"; };
495+
84DEC8DE2760A1D100172876 /* MessageView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageView_Tests.swift; sourceTree = "<group>"; };
490496
84EDBC36274FE5CD0057218D /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
491497
/* End PBXFileReference section */
492498

@@ -832,6 +838,8 @@
832838
84C94D67275A6AFD007FE2B9 /* ChannelHeaderLoader_Tests.swift */,
833839
84C94D412757C16D007FE2B9 /* ChatChannelListTestHelpers.swift */,
834840
848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */,
841+
84DEC8DA27609FA200172876 /* MoreChannelActionsView_Tests.swift */,
842+
84DEC8DC2760A10500172876 /* NoChannelsView_Tests.swift */,
835843
);
836844
path = ChatChannelList;
837845
sourceTree = "<group>";
@@ -1001,8 +1009,9 @@
10011009
84C94D5027591DE2007FE2B9 /* ChatMessageIDs_Tests.swift */,
10021010
84C94D57275A1B89007FE2B9 /* MessageTypeResolver_Tests.swift */,
10031011
84C94D65275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift */,
1004-
84C94D4E2758FE59007FE2B9 /* ChatChannelTestHelpers.swift */,
1012+
84DEC8DE2760A1D100172876 /* MessageView_Tests.swift */,
10051013
848399F127601231003075E4 /* ReactionsOverlayView_Tests.swift */,
1014+
84C94D4E2758FE59007FE2B9 /* ChatChannelTestHelpers.swift */,
10061015
);
10071016
path = ChatChannel;
10081017
sourceTree = "<group>";
@@ -1319,8 +1328,10 @@
13191328
848399EC275FB41B003075E4 /* ChatChannelListView_Tests.swift in Sources */,
13201329
84C94CE127578B92007FE2B9 /* MessageAttachmentPayload.swift in Sources */,
13211330
84C94D54275A1380007FE2B9 /* DateUtils_Tests.swift in Sources */,
1331+
84DEC8DB27609FA200172876 /* MoreChannelActionsView_Tests.swift in Sources */,
13221332
84C94CE527578B92007FE2B9 /* ChatUserSearchController_Mock.swift in Sources */,
13231333
84C94D56275A1AE1007FE2B9 /* StringExtensions_Tests.swift in Sources */,
1334+
84DEC8DD2760A10500172876 /* NoChannelsView_Tests.swift in Sources */,
13241335
84C94D1427578BF3007FE2B9 /* TemporaryData.swift in Sources */,
13251336
84C94D4F2758FE59007FE2B9 /* ChatChannelTestHelpers.swift in Sources */,
13261337
84C94CCC27578B92007FE2B9 /* ChatClientUpdater_Mock.swift in Sources */,
@@ -1366,6 +1377,7 @@
13661377
84C94CDD27578B92007FE2B9 /* MemberPayload.swift in Sources */,
13671378
84C94D1127578BF2007FE2B9 /* ChannelId.swift in Sources */,
13681379
84C94CD927578B92007FE2B9 /* ChatChannelMember_Mock.swift in Sources */,
1380+
84DEC8DF2760A1D100172876 /* MessageView_Tests.swift in Sources */,
13691381
84C94CDA27578B92007FE2B9 /* ChatUser_Mock.swift in Sources */,
13701382
84C94D2C275796F7007FE2B9 /* RequestRecorderURLProtocol.swift in Sources */,
13711383
84C94CD627578B92007FE2B9 /* AttachmentUploadingState_Mock.swift in Sources */,

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelTestHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ChatChannelTestHelpers {
3535
return channelController
3636
}
3737

38-
static let testURL = URL(string: "https://example.com")!
38+
static let testURL = URL(string: "https://vignette.wikia.nocookie.net/starwars/images/2/20/LukeTLJ.jpg")!
3939

4040
static var imageAttachments: [AnyChatMessageAttachment] = {
4141
let attachmentFile = AttachmentFile(type: .png, size: 0, mimeType: "image/png")
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 SwiftUI
9+
import XCTest
10+
11+
class MessageView_Tests: XCTestCase {
12+
13+
private var chatClient: ChatClient = {
14+
let client = ChatClient.mock()
15+
client.currentUserId = .unique
16+
return client
17+
}()
18+
19+
private var streamChat: StreamChat?
20+
21+
override func setUp() {
22+
super.setUp()
23+
streamChat = StreamChat(chatClient: chatClient)
24+
}
25+
26+
func test_messageViewText_snapshot() {
27+
// Given
28+
let textMessage = ChatMessage.mock(
29+
id: .unique,
30+
cid: .unique,
31+
text: "test message",
32+
author: .mock(id: .unique)
33+
)
34+
35+
// When
36+
let view = MessageView(
37+
factory: DefaultViewFactory.shared,
38+
message: textMessage,
39+
contentWidth: defaultScreenSize.width,
40+
isFirst: true
41+
)
42+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
43+
44+
// Then
45+
assertSnapshot(matching: view, as: .image)
46+
}
47+
48+
func test_messageViewImage_snapshot() {
49+
// Given
50+
let imageMessage = ChatMessage.mock(
51+
id: .unique,
52+
cid: .unique,
53+
text: "test message",
54+
author: .mock(id: .unique),
55+
attachments: ChatChannelTestHelpers.imageAttachments
56+
)
57+
58+
// When
59+
let view = MessageView(
60+
factory: DefaultViewFactory.shared,
61+
message: imageMessage,
62+
contentWidth: defaultScreenSize.width,
63+
isFirst: true
64+
)
65+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
66+
67+
// Then
68+
assertSnapshot(matching: view, as: .image)
69+
}
70+
}
59.3 KB
Loading
52 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 MoreChannelActionsView_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_moreChannelActionsView_snapshot() {
26+
// Given
27+
let channel: ChatChannel = .mockDMChannel(name: "test")
28+
let actions = ChannelAction.defaultActions(
29+
for: channel,
30+
chatClient: chatClient,
31+
onDismiss: {},
32+
onError: { _ in }
33+
)
34+
35+
// When
36+
let view = MoreChannelActionsView(channel: channel, channelActions: actions, onDismiss: {})
37+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
38+
39+
// Then
40+
assertSnapshot(matching: view, as: .image)
41+
}
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 NoChannelsView_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_noChannelsView_snapshot() {
26+
// Given
27+
let view = NoChannelsView()
28+
29+
// Then
30+
assertSnapshot(matching: view, as: .image)
31+
}
32+
}
Loading
27.9 KB
Loading

0 commit comments

Comments
 (0)