Skip to content

Commit 12a7b0a

Browse files
added tests for the quoted message view
1 parent 00698ef commit 12a7b0a

File tree

6 files changed

+81
-0
lines changed

6 files changed

+81
-0
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/QuotedMessageView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import NukeUI
77
import StreamChat
88
import SwiftUI
99

10+
/// Container showing the quoted message view with the user avatar.
1011
struct QuotedMessageViewContainer: View {
1112

1213
private let avatarSize: CGFloat = 24
@@ -49,6 +50,7 @@ struct QuotedMessageViewContainer: View {
4950
}
5051
}
5152

53+
/// View for the quoted message.
5254
struct QuotedMessageView: View {
5355

5456
@Injected(\.images) private var images

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
842383E02767394200888CFC /* ChatChannelDataSource_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842383DF2767394200888CFC /* ChatChannelDataSource_Tests.swift */; };
1111
842383E427678A4D00888CFC /* QuotedMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842383E327678A4D00888CFC /* QuotedMessageView.swift */; };
12+
842F0BB8276B3518002C400C /* QuotedMessageView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842F0BB7276B3518002C400C /* QuotedMessageView_Tests.swift */; };
1213
84335014274BAB15007A1B81 /* ViewFactoryExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335013274BAB15007A1B81 /* ViewFactoryExamples.swift */; };
1314
84335016274BABF3007A1B81 /* NewChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335015274BABF3007A1B81 /* NewChatView.swift */; };
1415
84335018274BAD4B007A1B81 /* NewChatViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335017274BAD4B007A1B81 /* NewChatViewModel.swift */; };
@@ -281,6 +282,7 @@
281282
842383DF2767394200888CFC /* ChatChannelDataSource_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelDataSource_Tests.swift; sourceTree = "<group>"; };
282283
842383E327678A4D00888CFC /* QuotedMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuotedMessageView.swift; sourceTree = "<group>"; };
283284
842E979C275E0AD000A52E7B /* StreamChatSwiftUI.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = StreamChatSwiftUI.xctestplan; sourceTree = "<group>"; };
285+
842F0BB7276B3518002C400C /* QuotedMessageView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuotedMessageView_Tests.swift; sourceTree = "<group>"; };
284286
84335013274BAB15007A1B81 /* ViewFactoryExamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewFactoryExamples.swift; sourceTree = "<group>"; };
285287
84335015274BABF3007A1B81 /* NewChatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewChatView.swift; sourceTree = "<group>"; };
286288
84335017274BAD4B007A1B81 /* NewChatViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewChatViewModel.swift; sourceTree = "<group>"; };
@@ -1032,6 +1034,7 @@
10321034
84DEC8DE2760A1D100172876 /* MessageView_Tests.swift */,
10331035
848399F127601231003075E4 /* ReactionsOverlayView_Tests.swift */,
10341036
842383DF2767394200888CFC /* ChatChannelDataSource_Tests.swift */,
1037+
842F0BB7276B3518002C400C /* QuotedMessageView_Tests.swift */,
10351038
84C94D4E2758FE59007FE2B9 /* ChatChannelTestHelpers.swift */,
10361039
);
10371040
path = ChatChannel;
@@ -1388,6 +1391,7 @@
13881391
84C94D1727578BF3007FE2B9 /* XCTAssertEqual+Difference.swift in Sources */,
13891392
84C94CE327578B92007FE2B9 /* XCTestCase+Dummy.swift in Sources */,
13901393
84C94D0D27578BF2007FE2B9 /* AssertResult.swift in Sources */,
1394+
842F0BB8276B3518002C400C /* QuotedMessageView_Tests.swift in Sources */,
13911395
84C94D1E2757929C007FE2B9 /* APIClient_Mock.swift in Sources */,
13921396
84C94CE927578B93007FE2B9 /* ChatClient_Mock.swift in Sources */,
13931397
84C94D2627579511007FE2B9 /* CDNClient_Mock.swift in Sources */,

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelViewModel_Tests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,23 @@ class ChatChannelViewModel_Tests: XCTestCase {
181181
XCTAssert(isMessageThread == true)
182182
}
183183

184+
func test_chatChannelVM_messageActionExecuted() {
185+
// Given
186+
let channelController = makeChannelController()
187+
let viewModel = ChatChannelViewModel(channelController: channelController)
188+
let messageActionInfo = MessageActionInfo(
189+
message: viewModel.messages[0],
190+
identifier: "inlineReply"
191+
)
192+
193+
// When
194+
viewModel.messageActionExecuted(messageActionInfo)
195+
196+
// Then
197+
XCTAssert(viewModel.quotedMessage != nil)
198+
XCTAssert(viewModel.quotedMessage == viewModel.messages[0])
199+
}
200+
184201
// MARK: - private
185202

186203
private func makeChannelController(
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 QuotedMessageView_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_quotedMessageViewContainer_snapshot() {
34+
// Given
35+
let view = QuotedMessageViewContainer(
36+
quotedMessage: testMessage,
37+
fillAvailableSpace: true,
38+
scrolledId: .constant(nil)
39+
)
40+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
41+
42+
// Then
43+
assertSnapshot(matching: view, as: .image)
44+
}
45+
46+
func test_quotedMessageView_snapshot() {
47+
// Given
48+
let view = QuotedMessageView(
49+
quotedMessage: testMessage,
50+
fillAvailableSpace: true,
51+
forceLeftToRight: true
52+
)
53+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height)
54+
55+
// Then
56+
assertSnapshot(matching: view, as: .image)
57+
}
58+
}
Loading
Loading

0 commit comments

Comments
 (0)