diff --git a/StreamChatSwiftUITests/Infrastructure/Shared/StreamChatModel.xcdatamodeld/StreamChatModel.xcdatamodel/contents b/StreamChatSwiftUITests/Infrastructure/Shared/StreamChatModel.xcdatamodeld/StreamChatModel.xcdatamodel/contents index 3d988576..aca907f8 100644 --- a/StreamChatSwiftUITests/Infrastructure/Shared/StreamChatModel.xcdatamodeld/StreamChatModel.xcdatamodel/contents +++ b/StreamChatSwiftUITests/Infrastructure/Shared/StreamChatModel.xcdatamodeld/StreamChatModel.xcdatamodel/contents @@ -1,9 +1,11 @@ - + + + @@ -20,6 +22,7 @@ + @@ -36,10 +39,12 @@ + + @@ -132,6 +137,7 @@ + @@ -139,6 +145,7 @@ + @@ -323,10 +330,10 @@ - + - + @@ -345,7 +352,7 @@ - + @@ -372,9 +379,16 @@ + + + + + + + @@ -434,7 +448,7 @@ - + diff --git a/StreamChatSwiftUITests/Tests/ChatChannelList/ChatChannelListViewModel_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannelList/ChatChannelListViewModel_Tests.swift index 3f6fde34..194d4fe8 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannelList/ChatChannelListViewModel_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannelList/ChatChannelListViewModel_Tests.swift @@ -4,6 +4,7 @@ @testable import StreamChat @testable import StreamChatSwiftUI +@testable import StreamChatTestTools import XCTest class ChatChannelListViewModel_Tests: StreamChatTestCase { @@ -270,6 +271,59 @@ class ChatChannelListViewModel_Tests: StreamChatTestCase { // Then XCTAssert(viewModel.hideTabBar == true) } + + func test_channelListVM_deeplinkToExistingChannel() throws { + // Given + let channels = (0..<3).map { ChatChannel.mock(cid: ChannelId(type: .messaging, id: "\($0)")) } + let channelListController = makeChannelListController(channels: channels) + let selectedId = channels[1].cid + let viewModel = ChatChannelListViewModel( + channelListController: channelListController, + selectedChannelId: selectedId.rawValue + ) + + // Then + let expectation = XCTestExpectation(description: "SelectedChannel") + let cancellable = viewModel.$selectedChannel + .filter { $0?.channel.cid == selectedId } + .sink { _ in + expectation.fulfill() + } + // Resume synchronize() + chatClient.mockAPIClient.test_simulateResponse(.success(ChannelListPayload(channels: []))) + wait(for: [expectation], timeout: defaultTimeout) + cancellable.cancel() + } + + func test_channelListVM_deeplinkToIncomingChannel() { + // Given + let channels = (0..<3).map { ChatChannel.mock(cid: ChannelId(type: .messaging, id: "\($0)")) } + let channelListController = makeChannelListController(channels: channels) + let selectedId = ChannelId(type: .messaging, id: "3") + let viewModel = ChatChannelListViewModel( + channelListController: channelListController, + selectedChannelId: selectedId.rawValue + ) + + // When + let expectation = XCTestExpectation(description: "SelectedChannel") + let cancellable = viewModel.$selectedChannel + .filter { $0?.channel.cid == selectedId } + .sink { _ in + expectation.fulfill() + } + let insertedChannel = ChatChannel.mock(cid: selectedId) + channelListController.simulate( + channels: channels + [insertedChannel], + changes: [.insert(insertedChannel, index: IndexPath(item: 0, section: 0))] + ) + // Resume synchronize() + chatClient.mockAPIClient.test_simulateResponse(.success(ChannelListPayload(channels: []))) + + // Then + wait(for: [expectation], timeout: defaultTimeout) + cancellable.cancel() + } // MARK: - private