-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
accd20f
commit 47a8578
Showing
10 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
StreamChatSwiftUITests/Tests/ChatThreadList/ChatThreadListItemView_Tests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// | ||
// Copyright © 2024 Stream.io Inc. All rights reserved. | ||
// | ||
|
||
import SnapshotTesting | ||
@testable import StreamChat | ||
@testable import StreamChatSwiftUI | ||
@testable import StreamChatTestTools | ||
import StreamSwiftTestHelpers | ||
import XCTest | ||
|
||
final class ChatThreadListItemView_Tests: StreamChatTestCase { | ||
var mockThread: ChatThread! | ||
|
||
var mockYoda = ChatUser.mock(id: .unique, name: "Yoda", imageURL: nil) | ||
var currentUser: ChatUser! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
let circleImage = UIImage.circleImage | ||
streamChat?.utils.channelHeaderLoader.placeholder1 = circleImage | ||
streamChat?.utils.channelHeaderLoader.placeholder2 = circleImage | ||
streamChat?.utils.channelHeaderLoader.placeholder3 = circleImage | ||
streamChat?.utils.channelHeaderLoader.placeholder4 = circleImage | ||
|
||
currentUser = ChatUser.mock(id: StreamChatTestCase.currentUserId, name: "Vader", imageURL: nil) | ||
|
||
mockThread = .mock( | ||
parentMessage: .mock(text: "Parent Message", author: mockYoda), | ||
channel: .mock(cid: .unique, name: "Star Wars Channel"), | ||
createdBy: currentUser, | ||
replyCount: 3, | ||
participantCount: 2, | ||
threadParticipants: [ | ||
.mock(user: mockYoda), | ||
.mock(user: currentUser) | ||
], | ||
lastMessageAt: .unique, | ||
createdAt: .unique, | ||
updatedAt: .unique, | ||
title: nil, | ||
latestReplies: [ | ||
.mock(text: "First Message", author: mockYoda), | ||
.mock(text: "Second Message", author: currentUser), | ||
.mock(text: "Third Message", author: mockYoda) | ||
], | ||
reads: [], | ||
extraData: [:] | ||
) | ||
} | ||
|
||
func test_threadListItem_default() throws { | ||
let view = ChatThreadListItem(thread: mockThread) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision)) | ||
} | ||
|
||
func test_threadListItem_withUnreads() throws { | ||
let thread = mockThread | ||
.with(reads: [.mock(user: currentUser, lastReadAt: .unique, unreadMessagesCount: 4)]) | ||
|
||
let view = ChatThreadListItem(thread: thread) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision)) | ||
} | ||
|
||
func test_threadListItem_withTitle() throws { | ||
let thread = mockThread | ||
.with(title: "Thread title") | ||
|
||
let view = ChatThreadListItem(thread: thread) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision)) | ||
} | ||
|
||
func test_threadListItem_withParentMessageDeleted() throws { | ||
let thread = mockThread | ||
.with(parentMessage: .mock(text: "Parent Message", deletedAt: .unique)) | ||
|
||
let view = ChatThreadListItem(thread: thread) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision)) | ||
} | ||
|
||
func test_threadListItem_withLastReplyDeleted() throws { | ||
let thread = mockThread | ||
.with(latestReplies: [ | ||
.mock(text: "First Message", author: mockYoda), | ||
.mock(text: "Second Message", author: currentUser), | ||
.mock(text: "Third Message", author: mockYoda, deletedAt: .unique) | ||
]) | ||
|
||
let view = ChatThreadListItem(thread: thread) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision)) | ||
} | ||
|
||
func test_threadListItem_whenAttachments() throws { | ||
let thread = mockThread | ||
.with( | ||
parentMessage: .mock(text: "", attachments: [.dummy(type: .giphy)]), | ||
latestReplies: [ | ||
.mock(text: "", author: mockYoda, attachments: [.dummy(type: .audio)]) | ||
] | ||
) | ||
|
||
let view = ChatThreadListItem(thread: thread) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision)) | ||
} | ||
|
||
func test_threadListItem_whenAttachmentIsPoll() throws { | ||
let thread = mockThread | ||
.with( | ||
parentMessage: .mock(text: "", poll: .mock(name: "Who is better?")), | ||
latestReplies: [ | ||
.mock(text: "", author: mockYoda, poll: .mock(name: "Who is worse?")) | ||
] | ||
) | ||
|
||
let view = ChatThreadListItem(thread: thread) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision)) | ||
} | ||
} |
Binary file added
BIN
+39.4 KB
...st/__Snapshots__/ChatThreadListItemView_Tests/test_threadListItem_default.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+50.9 KB
...s__/ChatThreadListItemView_Tests/test_threadListItem_whenAttachmentIsPoll.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38.8 KB
...pshots__/ChatThreadListItemView_Tests/test_threadListItem_whenAttachments.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38.4 KB
...s__/ChatThreadListItemView_Tests/test_threadListItem_withLastReplyDeleted.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.2 KB
...ChatThreadListItemView_Tests/test_threadListItem_withParentMessageDeleted.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+37.7 KB
.../__Snapshots__/ChatThreadListItemView_Tests/test_threadListItem_withTitle.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.6 KB
..._Snapshots__/ChatThreadListItemView_Tests/test_threadListItem_withUnreads.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.