Skip to content

Commit 37c7743

Browse files
added tests for reactions overlay
1 parent 034f9c7 commit 37c7743

File tree

6 files changed

+80
-6
lines changed

6 files changed

+80
-6
lines changed

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
848399EA275FB3E9003075E4 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 848399E9275FB3E9003075E4 /* SnapshotTesting */; };
136136
848399EC275FB41B003075E4 /* ChatChannelListView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */; };
137137
848399EE275FBC84003075E4 /* ChatChannelView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848399ED275FBC84003075E4 /* ChatChannelView_Tests.swift */; };
138+
848399F227601231003075E4 /* ReactionsOverlayView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848399F127601231003075E4 /* ReactionsOverlayView_Tests.swift */; };
138139
84A75FBB274EA29B00225CE8 /* GiphyAttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A75FBA274EA29B00225CE8 /* GiphyAttachmentView.swift */; };
139140
84AD8425274E2C380098C3C4 /* ChatChannelScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AD8424274E2C380098C3C4 /* ChatChannelScreen.swift */; };
140141
84B288CD274C544B00DD090B /* CreateGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B288CC274C544B00DD090B /* CreateGroupView.swift */; };
@@ -396,6 +397,7 @@
396397
8465FDDC2747A14700AF091E /* CustomComposerAttachmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomComposerAttachmentView.swift; sourceTree = "<group>"; };
397398
848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelListView_Tests.swift; sourceTree = "<group>"; };
398399
848399ED275FBC84003075E4 /* ChatChannelView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelView_Tests.swift; sourceTree = "<group>"; };
400+
848399F127601231003075E4 /* ReactionsOverlayView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionsOverlayView_Tests.swift; sourceTree = "<group>"; };
399401
84A75FBA274EA29B00225CE8 /* GiphyAttachmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GiphyAttachmentView.swift; sourceTree = "<group>"; };
400402
84AD8424274E2C380098C3C4 /* ChatChannelScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelScreen.swift; sourceTree = "<group>"; };
401403
84B288CC274C544B00DD090B /* CreateGroupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateGroupView.swift; sourceTree = "<group>"; };
@@ -1003,6 +1005,7 @@
10031005
84C94D65275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift */,
10041006
848399ED275FBC84003075E4 /* ChatChannelView_Tests.swift */,
10051007
84C94D4E2758FE59007FE2B9 /* ChatChannelTestHelpers.swift */,
1008+
848399F127601231003075E4 /* ReactionsOverlayView_Tests.swift */,
10061009
);
10071010
path = ChatChannel;
10081011
sourceTree = "<group>";
@@ -1324,6 +1327,7 @@
13241327
84C94D1427578BF3007FE2B9 /* TemporaryData.swift in Sources */,
13251328
84C94D4F2758FE59007FE2B9 /* ChatChannelTestHelpers.swift in Sources */,
13261329
84C94CCC27578B92007FE2B9 /* ChatClientUpdater_Mock.swift in Sources */,
1330+
848399F227601231003075E4 /* ReactionsOverlayView_Tests.swift in Sources */,
13271331
84C94D0B27578BF2007FE2B9 /* QueueAwareDelegate.swift in Sources */,
13281332
84C94CE427578B92007FE2B9 /* ChatChannelController_Mock.swift in Sources */,
13291333
84C94D58275A1B89007FE2B9 /* MessageTypeResolver_Tests.swift in Sources */,

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelView_Tests.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ class ChatChannelView_Tests: XCTestCase {
3838
)
3939

4040
// When
41-
let view = ChatChannelScreen(chatChannelController: controller)
42-
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
41+
let view = VerticallyCenteredView {
42+
ChatChannelScreen(chatChannelController: controller)
43+
}
44+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
4345

4446
// Then
4547
assertSnapshot(matching: view, as: .image)
@@ -54,10 +56,12 @@ class ChatChannelView_Tests: XCTestCase {
5456
)
5557

5658
// When
57-
let view = ChatChannelView(
58-
viewFactory: DefaultViewFactory.shared,
59-
channelController: controller
60-
)
59+
let view = VerticallyCenteredView {
60+
ChatChannelView(
61+
viewFactory: DefaultViewFactory.shared,
62+
channelController: controller
63+
)
64+
}
6165
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
6266

6367
// Then
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 SwiftUI
9+
import XCTest
10+
11+
class ReactionsOverlayView_Tests: XCTestCase {
12+
13+
private var chatClient: ChatClient = {
14+
let client = ChatClient.mock()
15+
client.currentUserId = .unique
16+
return client
17+
}()
18+
19+
private let testMessage = ChatMessage.mock(
20+
id: "test",
21+
cid: .unique,
22+
text: "This is a test message 1",
23+
author: .mock(id: "test", name: "martin")
24+
)
25+
26+
private var streamChat: StreamChat?
27+
28+
override func setUp() {
29+
super.setUp()
30+
streamChat = StreamChat(chatClient: chatClient)
31+
}
32+
33+
func test_reactionsOverlayView_snapshot() {
34+
// Given
35+
let view = VerticallyCenteredView {
36+
ReactionsOverlayView(
37+
factory: DefaultViewFactory.shared,
38+
currentSnapshot: UIImage(systemName: "checkmark")!,
39+
messageDisplayInfo: MessageDisplayInfo(
40+
message: .mock(id: .unique, cid: .unique, text: "test", author: .mock(id: .unique)),
41+
frame: CGRect(x: 20, y: 20, width: 200, height: 100),
42+
contentWidth: 200,
43+
isFirst: true
44+
),
45+
onBackgroundTap: {}
46+
)
47+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
48+
}
49+
50+
// Then
51+
assertSnapshot(matching: view, as: .image)
52+
}
53+
}
54+
55+
struct VerticallyCenteredView<Content: View>: View {
56+
57+
var content: () -> Content
58+
59+
var body: some View {
60+
VStack {
61+
Spacer()
62+
content()
63+
Spacer()
64+
}
65+
}
66+
}
-13 Bytes
Loading
-13 Bytes
Loading
Loading

0 commit comments

Comments
 (0)