Closed moubry closed 2 years ago
Hi @moubry!
We have this internal because we don't want developers to think they can create a chat message or chat user model with the initializer. This can open up for bad usage of the SDK. Either way, we understand that this can be a problem for testing and for mocking data. We will discuss this internally and will get back to you as soon as possible.
Best, Nuno
Btw @moubry, keep in mind you can use our StreamChatTestTools
dependency that includes mocks for those models. This is useful for testing, but for previews, it could be a little bit tricky since it doesn't make sense for your app to depend on a testing framework. Unless your previews belong to a different target, which I guess is not ideal right?
We actually already have a separate target in Xcode for running SwiftUI Previews to work around an unrelated issue with another package, so I’ll try StreamChatTestTools to see if that works.
Awesome 👍 @moubry, Let me know how that goes.
Hi @moubry!
I'm converting this one to a discussion to see if there are future requests for this.
Best, Nuno
This is a nice to have.
What are you trying to achieve?
I would like to create a SwiftUI Preview for my custom message view, to test what my message view looks like in a variety of different scenarios — with and without attachments, mentions, varying user info, varying text lengths, etc.
If possible, how can you achieve this currently?
I can do this by re-creating ChatMessage in the form of a custom proxy struct (
ChatMessageForView
) that only contains the properties that I need in order for my views to work, but this is kind of a pain, and I lose out on SwiftUI features that require passing-in a real ChatMessage like.messageBubble(for:)
.What would be the better way?
I would like if the
init
forChatMessage
were marked aspublic
instead ofinternal
so that I can create fake chat messages for the purpose of testing my SwiftUI views.This would make it possible for me to re-use SwiftUI view features like
.messageBubble(for:)
in my custom views, so that my custom message views match the style of the StreamSwiftUI default style ones, without needing to duplicate style.GetStream Environment
GetStream Chat version:
4.20.0
GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: 15.6 Swift version: latest Xcode version: Version 14.0 beta 4 (14A5284g)