-
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.
Add message preview with attachments in channel list
- Loading branch information
1 parent
5c84fb1
commit de3a3f0
Showing
12 changed files
with
284 additions
and
3 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
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
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
225 changes: 225 additions & 0 deletions
225
StreamChatSwiftUITests/Tests/ChatChannelList/ChatChannelListItemView_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,225 @@ | ||
// | ||
// Copyright © 2023 Stream.io Inc. All rights reserved. | ||
// | ||
|
||
import SnapshotTesting | ||
@testable import StreamChat | ||
@testable import StreamChatSwiftUI | ||
@testable import StreamChatTestTools | ||
import XCTest | ||
|
||
final class ChatChannelListItemView_Tests: StreamChatTestCase { | ||
|
||
func test_channelListItem_audioMessage() throws { | ||
// Given | ||
let message = try mockAudioMessage(text: "Audio", isSentByCurrentUser: true) | ||
let channel = ChatChannel.mock(cid: .unique, latestMessages: [message]) | ||
|
||
// When | ||
let view = ChatChannelListItem( | ||
channel: channel, | ||
channelName: "Test", | ||
avatar: .circleImage, | ||
onlineIndicatorShown: true, | ||
onItemTap: { _ in } | ||
) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
// Then | ||
assertSnapshot(matching: view, as: .image(perceptualPrecision: snapshotPrecision)) | ||
} | ||
|
||
func test_channelListItem_imageMessage() throws { | ||
// Given | ||
let message = try mockImageMessage(text: "Image", isSentByCurrentUser: true) | ||
let channel = ChatChannel.mock(cid: .unique, latestMessages: [message]) | ||
|
||
// When | ||
let view = ChatChannelListItem( | ||
channel: channel, | ||
channelName: "Test", | ||
avatar: .circleImage, | ||
onlineIndicatorShown: true, | ||
onItemTap: { _ in } | ||
) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
// Then | ||
assertSnapshot(matching: view, as: .image(perceptualPrecision: snapshotPrecision)) | ||
} | ||
|
||
func test_channelListItem_videoMessage() throws { | ||
// Given | ||
let message = try mockVideoMessage(text: "Video", isSentByCurrentUser: true) | ||
let channel = ChatChannel.mock(cid: .unique, latestMessages: [message]) | ||
|
||
// When | ||
let view = ChatChannelListItem( | ||
channel: channel, | ||
channelName: "Test", | ||
avatar: .circleImage, | ||
onlineIndicatorShown: true, | ||
onItemTap: { _ in } | ||
) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
// Then | ||
assertSnapshot(matching: view, as: .image(perceptualPrecision: snapshotPrecision)) | ||
} | ||
|
||
func test_channelListItem_fileMessage() throws { | ||
// Given | ||
let message = try mockFileMessage(title: "Filename", text: "File", isSentByCurrentUser: true) | ||
let channel = ChatChannel.mock(cid: .unique, latestMessages: [message]) | ||
|
||
// When | ||
let view = ChatChannelListItem( | ||
channel: channel, | ||
channelName: "Test", | ||
avatar: .circleImage, | ||
onlineIndicatorShown: true, | ||
onItemTap: { _ in } | ||
) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
// Then | ||
assertSnapshot(matching: view, as: .image(perceptualPrecision: snapshotPrecision)) | ||
} | ||
|
||
func test_channelListItem_giphyMessage() throws { | ||
// Given | ||
let message = try mockGiphyMessage(text: "Giphy", isSentByCurrentUser: true) | ||
let channel = ChatChannel.mock(cid: .unique, latestMessages: [message]) | ||
|
||
// When | ||
let view = ChatChannelListItem( | ||
channel: channel, | ||
channelName: "Test", | ||
avatar: .circleImage, | ||
onlineIndicatorShown: true, | ||
onItemTap: { _ in } | ||
) | ||
.frame(width: defaultScreenSize.width) | ||
|
||
// Then | ||
assertSnapshot(matching: view, as: .image(perceptualPrecision: snapshotPrecision)) | ||
} | ||
|
||
//MARK: - private | ||
|
||
private func mockAudioMessage(text: String, isSentByCurrentUser: Bool) throws -> ChatMessage { | ||
.mock( | ||
id: .unique, | ||
cid: .unique, | ||
text: text, | ||
type: .regular, | ||
author: .mock(id: "user", name: "User"), | ||
createdAt: Date(timeIntervalSince1970: 100), | ||
attachments: [ | ||
.dummy( | ||
type: .audio, | ||
payload: try JSONEncoder().encode(AudioAttachmentPayload( | ||
title: "Some Audio", | ||
audioRemoteURL: URL(string: "url")!, | ||
file: .init(type: .mp3, size: 123, mimeType: nil), | ||
extraData: nil | ||
)) | ||
) | ||
], | ||
localState: nil, | ||
isSentByCurrentUser: isSentByCurrentUser | ||
) | ||
} | ||
|
||
private func mockImageMessage(text: String, isSentByCurrentUser: Bool) throws -> ChatMessage { | ||
.mock( | ||
id: .unique, | ||
cid: .unique, | ||
text: text, | ||
type: .regular, | ||
author: .mock(id: "user", name: "User"), | ||
createdAt: Date(timeIntervalSince1970: 100), | ||
attachments: [ | ||
.dummy( | ||
type: .image, | ||
payload: try JSONEncoder().encode(ImageAttachmentPayload( | ||
title: "Test", | ||
imageRemoteURL: URL(string: "Url")! | ||
)) | ||
) | ||
], | ||
localState: nil, | ||
isSentByCurrentUser: isSentByCurrentUser | ||
) | ||
} | ||
|
||
private func mockVideoMessage(text: String, isSentByCurrentUser: Bool) throws -> ChatMessage { | ||
.mock( | ||
id: .unique, | ||
cid: .unique, | ||
text: text, | ||
type: .regular, | ||
author: .mock(id: "user", name: "User"), | ||
createdAt: Date(timeIntervalSince1970: 100), | ||
attachments: [ | ||
.dummy( | ||
type: .video, | ||
payload: try JSONEncoder().encode(VideoAttachmentPayload( | ||
title: "Test", | ||
videoRemoteURL: URL(string: "Url")!, | ||
file: .init(type: .mp4, size: 123, mimeType: nil), | ||
extraData: nil | ||
)) | ||
) | ||
], | ||
localState: nil, | ||
isSentByCurrentUser: isSentByCurrentUser | ||
) | ||
} | ||
|
||
private func mockFileMessage(title: String?, text: String, isSentByCurrentUser: Bool) throws -> ChatMessage { | ||
.mock( | ||
id: .unique, | ||
cid: .unique, | ||
text: text, | ||
type: .regular, | ||
author: .mock(id: "user", name: "User"), | ||
createdAt: Date(timeIntervalSince1970: 100), | ||
attachments: [ | ||
.dummy( | ||
type: .file, | ||
payload: try JSONEncoder().encode(FileAttachmentPayload( | ||
title: title, | ||
assetRemoteURL: URL(string: "Url")!, | ||
file: .init(type: .pdf, size: 123, mimeType: nil), | ||
extraData: nil | ||
)) | ||
) | ||
], | ||
localState: nil, | ||
isSentByCurrentUser: isSentByCurrentUser | ||
) | ||
} | ||
|
||
private func mockGiphyMessage(text: String, isSentByCurrentUser: Bool) throws -> ChatMessage { | ||
.mock( | ||
id: .unique, | ||
cid: .unique, | ||
text: text, | ||
type: .regular, | ||
author: .mock(id: "user", name: "User"), | ||
createdAt: Date(timeIntervalSince1970: 100), | ||
attachments: [ | ||
.dummy( | ||
type: .giphy, | ||
payload: try JSONEncoder().encode(GiphyAttachmentPayload( | ||
title: "Test", | ||
previewURL: URL(string: "Url")! | ||
)) | ||
) | ||
], | ||
localState: nil, | ||
isSentByCurrentUser: isSentByCurrentUser | ||
) | ||
} | ||
} |
Binary file added
BIN
+19.1 KB
...apshots__/ChatChannelListItemView_Tests/test_channelListItem_audioMessage.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
+18.7 KB
...napshots__/ChatChannelListItemView_Tests/test_channelListItem_fileMessage.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
+16.9 KB
...apshots__/ChatChannelListItemView_Tests/test_channelListItem_giphyMessage.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
+20.6 KB
...apshots__/ChatChannelListItemView_Tests/test_channelListItem_imageMessage.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
+21 KB
...apshots__/ChatChannelListItemView_Tests/test_channelListItem_videoMessage.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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