mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Volatile draft to restore the composer after an edit. (#2996)
This commit is contained in:
@@ -489,6 +489,70 @@ class ComposerToolbarViewModelTests: XCTestCase {
|
||||
await fulfillment(of: [loadReplyExpectation], timeout: 10)
|
||||
XCTAssertEqual(viewModel.state.composerMode, .default)
|
||||
}
|
||||
|
||||
func testSaveVolatileDraftWhenEditing() {
|
||||
viewModel.context.composerFormattingEnabled = false
|
||||
viewModel.context.plainComposerText = .init(string: "Hello world!")
|
||||
viewModel.process(roomAction: .setMode(mode: .edit(originalItemId: .random)))
|
||||
|
||||
let draft = draftServiceMock.saveVolatileDraftReceivedDraft
|
||||
XCTAssertNotNil(draft)
|
||||
XCTAssertEqual(draft?.plainText, "Hello world!")
|
||||
XCTAssertNil(draft?.htmlText)
|
||||
XCTAssertEqual(draft?.draftType, .newMessage)
|
||||
}
|
||||
|
||||
func testRestoreVolatileDraftWhenCancellingEdit() async {
|
||||
let expectation = expectation(description: "Wait for draft to be restored")
|
||||
draftServiceMock.loadVolatileDraftClosure = {
|
||||
defer { expectation.fulfill() }
|
||||
return .init(plainText: "Hello world",
|
||||
htmlText: nil,
|
||||
draftType: .newMessage)
|
||||
}
|
||||
|
||||
viewModel.process(viewAction: .cancelEdit)
|
||||
await fulfillment(of: [expectation])
|
||||
XCTAssertEqual(viewModel.context.plainComposerText, NSAttributedString(string: "Hello world"))
|
||||
}
|
||||
|
||||
func testRestoreVolatileDraftWhenClearing() async {
|
||||
let expectation1 = expectation(description: "Wait for draft to be restored")
|
||||
draftServiceMock.loadVolatileDraftClosure = {
|
||||
defer { expectation1.fulfill() }
|
||||
return .init(plainText: "Hello world",
|
||||
htmlText: nil,
|
||||
draftType: .newMessage)
|
||||
}
|
||||
|
||||
let expectation2 = expectation(description: "The draft should also be cleared after being loaded")
|
||||
draftServiceMock.clearVolatileDraftClosure = {
|
||||
expectation2.fulfill()
|
||||
}
|
||||
|
||||
viewModel.process(roomAction: .clear)
|
||||
await fulfillment(of: [expectation1, expectation2])
|
||||
XCTAssertEqual(viewModel.context.plainComposerText, NSAttributedString(string: "Hello world"))
|
||||
}
|
||||
|
||||
func testRestoreVolatileDraftDoubleClear() async {
|
||||
let expectation1 = expectation(description: "Wait for draft to be restored")
|
||||
draftServiceMock.loadVolatileDraftClosure = {
|
||||
defer { expectation1.fulfill() }
|
||||
return .init(plainText: "Hello world",
|
||||
htmlText: nil,
|
||||
draftType: .newMessage)
|
||||
}
|
||||
|
||||
let expectation2 = expectation(description: "The draft should also be cleared after being loaded")
|
||||
draftServiceMock.clearVolatileDraftClosure = {
|
||||
expectation2.fulfill()
|
||||
}
|
||||
|
||||
viewModel.process(roomAction: .clear)
|
||||
await fulfillment(of: [expectation1, expectation2])
|
||||
XCTAssertEqual(viewModel.context.plainComposerText, NSAttributedString(string: "Hello world"))
|
||||
}
|
||||
}
|
||||
|
||||
private extension MentionSuggestionItem {
|
||||
|
||||
Reference in New Issue
Block a user