Skip to content

Commit

Permalink
Fix flakey test.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Sep 19, 2024
1 parent c6c82a4 commit c89bda3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions ElementX/Sources/Screens/Timeline/TimelineViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
return
}
await self?.updatePinnedEventIDs()
await self?.updatePermissions()
}
}
.store(in: &cancellables)
Expand Down
14 changes: 10 additions & 4 deletions UnitTests/Sources/TimelineViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,13 @@ class TimelineViewModelTests: XCTestCase {

func testPinnedEvents() async throws {
ServiceLocator.shared.settings.pinningEnabled = true

// Note: We need to start the test with a non-default value so we know the view model has finished the Task.
let roomProxyMock = JoinedRoomProxyMock(.init(name: "",
pinnedEventIDs: .init(["test1"])))
let actionsSubject = PassthroughSubject<JoinedRoomProxyAction, Never>()
roomProxyMock.underlyingActionsPublisher = actionsSubject.eraseToAnyPublisher()

let viewModel = TimelineViewModel(roomProxy: roomProxyMock,
timelineController: MockRoomTimelineController(),
mediaProvider: MockMediaProvider(),
Expand All @@ -409,9 +412,12 @@ class TimelineViewModelTests: XCTestCase {

func testCanUserPinEvents() async throws {
ServiceLocator.shared.settings.pinningEnabled = true
let roomProxyMock = JoinedRoomProxyMock(.init(name: "", canUserPin: false))

// Note: We need to start the test with the non-default value so we know the view model has finished the Task.
let roomProxyMock = JoinedRoomProxyMock(.init(name: "", canUserPin: true))
let actionsSubject = PassthroughSubject<JoinedRoomProxyAction, Never>()
roomProxyMock.underlyingActionsPublisher = actionsSubject.eraseToAnyPublisher()

let viewModel = TimelineViewModel(roomProxy: roomProxyMock,
timelineController: MockRoomTimelineController(),
mediaProvider: MockMediaProvider(),
Expand All @@ -423,13 +429,13 @@ class TimelineViewModelTests: XCTestCase {
analyticsService: ServiceLocator.shared.analytics)

var deferred = deferFulfillment(viewModel.context.$viewState) { value in
!value.canCurrentUserPin
value.canCurrentUserPin
}
try await deferred.fulfill()

roomProxyMock.canUserPinOrUnpinUserIDReturnValue = .success(true)
roomProxyMock.canUserPinOrUnpinUserIDReturnValue = .success(false)
deferred = deferFulfillment(viewModel.context.$viewState) { value in
value.canCurrentUserPin
!value.canCurrentUserPin
}
actionsSubject.send(.roomInfoUpdate)
try await deferred.fulfill()
Expand Down

0 comments on commit c89bda3

Please sign in to comment.