import XCTest @testable import LChatCore // 🤖 The two keyboard message verbs' targets (issue #392): ⌘R replies to the // latest message, ⌘T reacts to the latest one that ISN'T yours. Web twin: // chat.js's `latest(othersOnly)` behind its cmd/ctrl-R and -T handlers. final class LatestMessageHotkeyTests: XCTestCase { typealias Message = ChatFeedModel.Message private func message(_ id: Int64, _ text: String, mine: Bool, action: Bool = false, pending: Bool = false) -> Message { var m = Message(id: id, name: mine ? "Me" : "Alice", text: text, mine: mine, at: 1_700_000_000 + id, action: action, edited: false) m.pending = pending return m } func testReplyTargetsTheNewestMessageEvenWhenItsYours() { let list = [ message(1, "Morning", mine: false), message(2, "Morning!", mine: true), ] // The issue's wording: "even if it's from you". XCTAssertEqual(ChatFeedModel.latestReplyTarget(in: list)?.id, 2) } func testReplySkipsActionLinesAndOptimisticCopies() { let list = [ message(1, "Real message", mine: false), message(2, "added the To-do app", mine: true, action: true), message(3, "not acknowledged yet", mine: true, pending: true), ] // An action line has no bubble to quote, and a pending copy's id is a // synthetic one the server has never seen. XCTAssertEqual(ChatFeedModel.latestReplyTarget(in: list)?.id, 1) } func testReplyTargetIsNilWithNothingToReplyTo() { XCTAssertNil(ChatFeedModel.latestReplyTarget(in: [])) XCTAssertNil(ChatFeedModel.latestReplyTarget(in: [ message(1, "set the group photo", mine: false, action: true), ])) } func testReactionTargetsTheNewestMessageThatIsntYours() { let list = [ message(1, "Morning", mine: false), message(2, "Standup in five", mine: false), message(3, "On my way", mine: true), ] XCTAssertEqual(ChatFeedModel.latestReactionTarget(in: list)?.id, 2) } func testReactionTargetIsNilWhenEveryMessageIsYours() { let list = [ message(1, "Anyone about?", mine: true), message(2, "Never mind", mine: true), ] XCTAssertNil(ChatFeedModel.latestReactionTarget(in: list)) } }