Files
element-x-ios/UnitTests/Sources/TimelineItemMenuActionProviderTests.swift
T
Ghazi Tozri b4a36ad465 hide the forward action on live location shares (#6091)
Live location shares have no message event content, so forwarding always failed silently. Exclude them from `isForwardable` matching polls logic
2026-09-01 16:23:20 +03:00

89 lines
3.2 KiB
Swift

//
// Copyright 2026 Element Creations Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
@testable import ElementX
import Testing
struct TimelineItemMenuActionProviderTests {
@Test
func liveLocationShareIsNotForwardable() throws {
let item = makeLiveLocationItem(isLive: true)
let actions = try #require(makeActions(for: item))
let hasForward = actions.actions.contains(where: \.isForward)
#expect(!hasForward)
}
@Test
func endedLiveLocationShareIsNotForwardable() throws {
let item = makeLiveLocationItem(isLive: false)
let actions = try #require(makeActions(for: item))
let hasForward = actions.actions.contains(where: \.isForward)
#expect(!hasForward)
}
@Test
func pollIsNotForwardable() throws {
let item = PollRoomTimelineItem.mock(poll: .emptyDisclosed)
let actions = try #require(makeActions(for: item))
let hasForward = actions.actions.contains(where: \.isForward)
#expect(!hasForward)
}
@Test
func textMessageIsForwardable() throws {
let item = TextRoomTimelineItem(id: .randomEvent,
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
sender: .init(id: "@alice:matrix.org"),
content: .init(body: "Hello"))
let actions = try #require(makeActions(for: item))
let hasForward = actions.actions.contains(where: \.isForward)
#expect(hasForward)
}
// MARK: - Helpers
private func makeLiveLocationItem(isLive: Bool) -> LiveLocationRoomTimelineItem {
.init(id: .randomEvent,
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
sender: .init(id: "@alice:matrix.org"),
content: .init(isLive: isLive, timeoutDate: .mock, lastGeoURI: nil))
}
private func makeActions(for item: RoomTimelineItemProtocol) -> TimelineItemMenuActions? {
TimelineItemMenuActionProvider(timelineItem: item,
canCurrentUserSendMessage: true,
canCurrentUserRedactSelf: true,
canCurrentUserRedactOthers: false,
canCurrentUserPin: true,
pinnedEventIDs: [],
isViewSourceEnabled: true,
areThreadsEnabled: true,
timelineKind: .live,
emojiProvider: EmojiProvider(appSettings: .volatile()))
.makeActions()
}
}
private extension TimelineItemMenuAction {
var isForward: Bool {
if case .forward = self {
return true
}
return false
}
}