mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Hook up the actions in the media details sheet. (#3607)
This commit is contained in:
@@ -16,12 +16,14 @@ class TimelineMediaPreviewViewModelTests: XCTestCase {
|
||||
var viewModel: TimelineMediaPreviewViewModel!
|
||||
var context: TimelineMediaPreviewViewModel.Context { viewModel.context }
|
||||
var mediaProvider: MediaProviderMock!
|
||||
var timelineController: MockRoomTimelineController!
|
||||
|
||||
func testLoadingItem() async throws {
|
||||
func testLoadingItem() async {
|
||||
// Given a fresh view model.
|
||||
setupViewModel()
|
||||
XCTAssertFalse(mediaProvider.loadFileFromSourceFilenameCalled)
|
||||
XCTAssertEqual(context.viewState.currentItem, context.viewState.previewItems[0])
|
||||
XCTAssertNotNil(context.viewState.currentItemActions)
|
||||
|
||||
// When the preview controller sets the current item.
|
||||
await viewModel.updateCurrentItem(context.viewState.previewItems[0])
|
||||
@@ -29,6 +31,42 @@ class TimelineMediaPreviewViewModelTests: XCTestCase {
|
||||
// Then the view model should load the item and update its view state.
|
||||
XCTAssertTrue(mediaProvider.loadFileFromSourceFilenameCalled)
|
||||
XCTAssertEqual(context.viewState.currentItem, context.viewState.previewItems[0])
|
||||
XCTAssertNotNil(context.viewState.currentItemActions)
|
||||
}
|
||||
|
||||
func testViewInRoomTimeline() async throws {
|
||||
// Given a view model with a loaded item.
|
||||
await testLoadingItem()
|
||||
|
||||
// When choosing to view the current item in the timeline.
|
||||
let currentItemID = context.viewState.currentItem.id
|
||||
let deferred = deferFulfillment(viewModel.actions) { $0 == .viewInRoomTimeline(currentItemID) }
|
||||
context.send(viewAction: .menuAction(.viewInRoomTimeline))
|
||||
|
||||
// Then the action should be sent upwards to make this happen.
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
func testRedactConfirmation() async throws {
|
||||
// Given a view model with a loaded item.
|
||||
await testLoadingItem()
|
||||
XCTAssertFalse(context.isPresentingRedactConfirmation)
|
||||
XCTAssertFalse(timelineController.redactCalled)
|
||||
|
||||
// When choosing to redact the current item.
|
||||
context.send(viewAction: .menuAction(.redact))
|
||||
|
||||
// Then the confirmation sheet should be presented.
|
||||
XCTAssertTrue(context.isPresentingRedactConfirmation)
|
||||
XCTAssertFalse(timelineController.redactCalled)
|
||||
|
||||
// When confirming the redaction.
|
||||
let deferred = deferFulfillment(viewModel.actions) { $0 == .dismiss }
|
||||
context.send(viewAction: .redactConfirmation)
|
||||
|
||||
// Then the item should be redacted and the view should be dismissed.
|
||||
try await deferred.fulfill()
|
||||
XCTAssertTrue(timelineController.redactCalled)
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
@@ -46,9 +84,13 @@ class TimelineMediaPreviewViewModelTests: XCTestCase {
|
||||
imageInfo: .mockImage,
|
||||
thumbnailInfo: .mockThumbnail))
|
||||
|
||||
timelineController = MockRoomTimelineController(timelineKind: .media(.mediaFilesScreen))
|
||||
timelineController.timelineItems = [item]
|
||||
|
||||
mediaProvider = MediaProviderMock(configuration: .init())
|
||||
viewModel = TimelineMediaPreviewViewModel(initialItem: item,
|
||||
timelineViewModel: TimelineViewModel.mock,
|
||||
timelineViewModel: TimelineViewModel.mock(timelineKind: .media(.mediaFilesScreen),
|
||||
timelineController: timelineController),
|
||||
mediaProvider: mediaProvider,
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user