Skip to content

Commit

Permalink
Add new development assets and use in mocks/previews. (#3581)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave authored Dec 3, 2024
1 parent c566c64 commit 4966083
Show file tree
Hide file tree
Showing 194 changed files with 501 additions and 492 deletions.
3 changes: 3 additions & 0 deletions DevelopmentAssets/Media/preview_avatar_room.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions DevelopmentAssets/Media/preview_avatar_user.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions DevelopmentAssets/Media/preview_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions DevelopmentAssets/Media/preview_video.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions ElementX/Sources/Mocks/MediaProviderMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,26 @@ extension MediaProviderMock {
return nil
}

// At some stage it would be nice to return different images, but for now they can be the same.
if mediaSource?.url == .mockMXCImage || mediaSource?.url == .mockMXCAvatar {
return Asset.Images.appLogo.image
if mediaSource?.url == .mockMXCImage {
if let url = Bundle.main.url(forResource: "preview_image", withExtension: "jpg"),
let data = try? Data(contentsOf: url) {
return UIImage(data: data)
}
} else if mediaSource?.url == .mockMXCVideo {
if let url = Bundle.main.url(forResource: "preview_video", withExtension: "jpg"),
let data = try? Data(contentsOf: url) {
return UIImage(data: data)
}
} else if mediaSource?.url == .mockMXCAvatar {
if let url = Bundle.main.url(forResource: "preview_avatar_room", withExtension: "jpg"),
let data = try? Data(contentsOf: url) {
return UIImage(data: data)
}
} else if mediaSource?.url == .mockMXCUserAvatar {
if let url = Bundle.main.url(forResource: "preview_avatar_user", withExtension: "jpg"),
let data = try? Data(contentsOf: url) {
return UIImage(data: data)
}
}

return UIImage(systemName: "photo")
Expand Down
6 changes: 3 additions & 3 deletions ElementX/Sources/Mocks/RoomMemberProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ extension RoomMemberProxyMock {
static var mockMe: RoomMemberProxyMock {
RoomMemberProxyMock(with: .init(userID: "@me:matrix.org",
displayName: "Me",
avatarURL: .mockMXCAvatar,
avatarURL: .mockMXCUserAvatar,
membership: .join))
}

static var mockMeAdmin: RoomMemberProxyMock {
RoomMemberProxyMock(with: .init(userID: "@me:matrix.org",
displayName: "Me",
avatarURL: .mockMXCAvatar,
avatarURL: .mockMXCUserAvatar,
membership: .join,
powerLevel: 100,
role: .administrator))
Expand Down Expand Up @@ -83,7 +83,7 @@ extension RoomMemberProxyMock {
static var mockDan: RoomMemberProxyMock {
RoomMemberProxyMock(with: .init(userID: "@dan:matrix.org",
displayName: "Dan",
avatarURL: .mockMXCAvatar,
avatarURL: .mockMXCUserAvatar,
membership: .join))
}

Expand Down
3 changes: 2 additions & 1 deletion ElementX/Sources/Other/Extensions/URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ extension URL: @retroactive ExpressibleByStringLiteral {

// MARK: Mocks

static var mockMXCAudio: URL { "mxc://matrix.org/1234567890FiLe" }
static var mockMXCAudio: URL { "mxc://matrix.org/1234567890AuDiO" }
static var mockMXCFile: URL { "mxc://matrix.org/1234567890FiLe" }
static var mockMXCImage: URL { "mxc://matrix.org/1234567890ImAgE" }
static var mockMXCVideo: URL { "mxc://matrix.org/1234567890ViDeO" }
static var mockMXCAvatar: URL { "mxc://matrix.org/1234567890AvAtAr" }
static var mockMXCUserAvatar: URL { "mxc://matrix.org/1234567890AvAtArUsEr" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private extension HomeScreenRoom {
let inviter = RoomMemberProxyMock()
inviter.displayName = "Luca"
inviter.userID = "@jack:somewhi.nl"
inviter.avatarURL = avatarURL
inviter.avatarURL = avatarURL.map { _ in .mockMXCUserAvatar }

let summary = RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "@someone:somewhere.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ struct RoomMembersListMemberCell_Previews: PreviewProvider, TestablePreview {
.mockAdmin,
.mockModerator,
.init(with: .init(userID: "@nodisplayname:matrix.org", membership: .join)),
.init(with: .init(userID: "@avatar:matrix.org", displayName: "Avatar", avatarURL: .mockMXCAvatar, membership: .join))
.init(with: .init(userID: "@avatar:matrix.org", displayName: "Avatar", avatarURL: .mockMXCUserAvatar, membership: .join))
]

static let bannedMembers: [RoomMemberProxyMock] = [
.init(with: .init(userID: "@nodisplayname:matrix.org", membership: .ban)),
.init(with: .init(userID: "@fake:matrix.org", displayName: "President", membership: .ban)),
.init(with: .init(userID: "@badavatar:matrix.org", avatarURL: .mockMXCAvatar, membership: .ban))
.init(with: .init(userID: "@badavatar:matrix.org", avatarURL: .mockMXCUserAvatar, membership: .ban))
]

static let viewModel = RoomMembersListScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Some room",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct CompletionSuggestion_Previews: PreviewProvider, TestablePreview {
VStack(spacing: 8) {
CompletionSuggestionView(mediaProvider: MediaProviderMock(configuration: .init()),
items: [.user(item: MentionSuggestionItem(id: "@user_mention_1:matrix.org", displayName: "User 1", avatarURL: nil, range: .init())),
.user(item: MentionSuggestionItem(id: "@user_mention_2:matrix.org", displayName: "User 2", avatarURL: .mockMXCAvatar, range: .init()))]) { _ in }
.user(item: MentionSuggestionItem(id: "@user_mention_2:matrix.org", displayName: "User 2", avatarURL: .mockMXCUserAvatar, range: .init()))]) { _ in }
}
VStack(spacing: 8) {
CompletionSuggestionView(mediaProvider: MediaProviderMock(configuration: .init()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ struct ComposerToolbar_Previews: PreviewProvider, TestablePreview {
analyticsService: ServiceLocator.shared.analytics,
composerDraftService: ComposerDraftServiceMock())
static let suggestions: [SuggestionItem] = [.user(item: MentionSuggestionItem(id: "@user_mention_1:matrix.org", displayName: "User 1", avatarURL: nil, range: .init())),
.user(item: MentionSuggestionItem(id: "@user_mention_2:matrix.org", displayName: "User 2", avatarURL: .mockMXCAvatar, range: .init()))]
.user(item: MentionSuggestionItem(id: "@user_mention_2:matrix.org", displayName: "User 2", avatarURL: .mockMXCUserAvatar, range: .init()))]

static var previews: some View {
ComposerToolbar.mock(focused: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct MentionSuggestionItemView_Previews: PreviewProvider, TestablePreview {
static let mockMediaProvider = MediaProviderMock(configuration: .init())

static var previews: some View {
MentionSuggestionItemView(mediaProvider: mockMediaProvider, item: .init(id: "test", displayName: "Test", avatarURL: .mockMXCAvatar, range: .init()))
MentionSuggestionItemView(mediaProvider: mockMediaProvider, item: .init(id: "test", displayName: "Test", avatarURL: .mockMXCUserAvatar, range: .init()))
MentionSuggestionItemView(mediaProvider: mockMediaProvider, item: .init(id: "test2", displayName: nil, avatarURL: nil, range: .init()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ struct MessageComposer_Previews: PreviewProvider, TestablePreview {
eventContent: .message(.video(.init(filename: "never.mov",
caption: "Video: Through the never",
videoInfo: .mockVideo,
thumbnailInfo: .mockThumbnail)))),
thumbnailInfo: .mockVideoThumbnail)))),
.loading(eventID: "")
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct ReadReceiptCell_Previews: PreviewProvider, TestablePreview {
ReadReceiptCell(readReceipt: .init(userID: "@test:matrix.org",
formattedTimestamp: "10:00"),
memberState: .init(displayName: "Test",
avatarURL: .mockMXCAvatar),
avatarURL: .mockMXCUserAvatar),
mediaProvider: MediaProviderMock(configuration: .init()))
.previewDisplayName("With Image")
ReadReceiptCell(readReceipt: .init(userID: "@test:matrix.org",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ struct TimelineReplyView_Previews: PreviewProvider, TestablePreview {
eventContent: .message(.video(.init(filename: "video.mp4",
caption: "Some video",
videoInfo: .mockVideo,
thumbnailInfo: .mockThumbnail))))),
thumbnailInfo: .mockVideoThumbnail))))),
TimelineReplyView(placement: .timeline,
timelineItemReplyDetails: .loaded(sender: .init(id: "", displayName: "Alice"),
eventID: "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,27 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
static var previews: some View {
mockTimeline
.previewDisplayName("Mock Timeline")
.previewLayout(.fixed(width: 390, height: 900))
.padding(.bottom, 20)
mockTimeline
.environment(\.layoutDirection, .rightToLeft)
.previewDisplayName("Mock Timeline RTL")
.previewLayout(.fixed(width: 390, height: 900))
.padding(.bottom, 20)
replies
.previewDisplayName("Replies")
threads
.previewDisplayName("Thread decorator")
.snapshotPreferences(delay: 1)
.previewLayout(.fixed(width: 390, height: 1700))
.padding(.bottom, 20)
encryptionAuthenticity
.previewDisplayName("Encryption Indicators")
pinned
.previewDisplayName("Pinned messages")
.snapshotPreferences(delay: 1)
.previewLayout(.fixed(width: 390, height: 1150))
.padding(.bottom, 20)
}

static var mockTimeline: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,61 +74,38 @@ struct ImageRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static let viewModel = TimelineViewModel.mock

static var previews: some View {
body
.environmentObject(viewModel.context)
.environment(\.timelineContext, viewModel.context)
ScrollView {
VStack(spacing: 20.0) {
ImageRoomTimelineView(timelineItem: makeTimelineItem())
ImageRoomTimelineView(timelineItem: makeTimelineItem(isEdited: true))

// Blur hashed item?

ImageRoomTimelineView(timelineItem: makeTimelineItem(caption: "This is a great image 😎"))
ImageRoomTimelineView(timelineItem: makeTimelineItem(caption: "This is a great image with a really long multiline caption.",
isEdited: true))
}
}
.environmentObject(viewModel.context)
.environment(\.timelineContext, viewModel.context)
.previewLayout(.fixed(width: 390, height: 1200))
.padding(.bottom, 20)
}

static var body: some View {
VStack(spacing: 20.0) {
ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
isThreaded: false,
sender: .init(id: "Bob"),
content: .init(filename: "image.jpg",
imageInfo: .mockImage,
thumbnailInfo: nil)))

ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
isThreaded: false,
sender: .init(id: "Bob"),
content: .init(filename: "other.png",
imageInfo: .mockImage,
thumbnailInfo: nil)))

ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
isThreaded: false,
sender: .init(id: "Bob"),
content: .init(filename: "Blurhashed.jpg",
imageInfo: .mockImage,
thumbnailInfo: nil,
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW",
contentType: .gif)))

ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
isThreaded: false,
sender: .init(id: "Bob"),
content: .init(filename: "Blurhashed.jpg",
caption: "This is a great image 😎",
imageInfo: .mockImage,
thumbnailInfo: .mockThumbnail,
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW",
contentType: .gif)))
}
private static func makeTimelineItem(caption: String? = nil, isEdited: Bool = false) -> ImageRoomTimelineItem {
ImageRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
isThreaded: false,
sender: .init(id: "Bob"),
content: .init(filename: "image.jpg",
caption: caption,
imageInfo: .mockImage,
thumbnailInfo: .mockThumbnail,
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW",
contentType: .jpeg),
properties: .init(isEdited: isEdited))
}
}
Loading

0 comments on commit 4966083

Please sign in to comment.