@@ -65,19 +65,103 @@ class EditRoomAddressScreenViewModelTests: XCTestCase {
65
65
try await deferred. fulfill ( )
66
66
}
67
67
68
- func testCorrectMethodsCalledOnSave ( ) async throws {
68
+ func testCorrectMethodsCalledOnSaveWhenNoAliasExists ( ) async throws {
69
69
let clientProxy = ClientProxyMock ( . init( userIDServerName: " matrix.org " ) )
70
70
clientProxy. isAliasAvailableReturnValue = . success( true )
71
-
72
71
let roomProxy = JoinedRoomProxyMock ( . init( name: " Room Name " ) )
73
- roomProxy. publishRoomAliasInRoomDirectoryReturnValue = . success( true )
74
- roomProxy. updateCanonicalAliasAltAliasesReturnValue = . success( ( ) )
75
- roomProxy. removeRoomAliasFromRoomDirectoryReturnValue = . success( true )
76
72
77
73
viewModel = EditRoomAddressScreenViewModel ( roomProxy: roomProxy,
78
74
clientProxy: clientProxy,
79
75
userIndicatorController: UserIndicatorControllerMock ( ) )
80
76
77
+ XCTAssertNil ( roomProxy. infoPublisher. value. canonicalAlias)
78
+ XCTAssertEqual ( viewModel. context. viewState. bindings. desiredAliasLocalPart, " room-name " )
79
+
80
+ let publishingExpectation = expectation ( description: " Wait for publishing " )
81
+ roomProxy. publishRoomAliasInRoomDirectoryClosure = { roomAlias in
82
+ defer { publishingExpectation. fulfill ( ) }
83
+ XCTAssertEqual ( roomAlias, " #room-name:matrix.org " )
84
+ return . success( true )
85
+ }
86
+
87
+ let updateAliasExpectation = expectation ( description: " Wait for alias update " )
88
+ roomProxy. updateCanonicalAliasAltAliasesClosure = { roomAlias, altAliases in
89
+ defer { updateAliasExpectation. fulfill ( ) }
90
+ XCTAssertEqual ( altAliases, [ ] )
91
+ XCTAssertEqual ( roomAlias, " #room-name:matrix.org " )
92
+ return . success( ( ) )
93
+ }
94
+
95
+ context. send ( viewAction: . save)
96
+ await fulfillment ( of: [ publishingExpectation, updateAliasExpectation] , timeout: 1.0 )
97
+ XCTAssertFalse ( roomProxy. removeRoomAliasFromRoomDirectoryCalled)
98
+ }
99
+
100
+ func testCorrectMethodsCalledOnSaveWhenAliasOnSameHomeserverExists( ) async throws {
101
+ let clientProxy = ClientProxyMock ( . init( userIDServerName: " matrix.org " ) )
102
+ clientProxy. isAliasAvailableReturnValue = . success( true )
103
+ let roomProxy = JoinedRoomProxyMock ( . init( name: " Room Name " , canonicalAlias: " #old-room-name:matrix.org " ) )
104
+
105
+ viewModel = EditRoomAddressScreenViewModel ( roomProxy: roomProxy,
106
+ clientProxy: clientProxy,
107
+ userIndicatorController: UserIndicatorControllerMock ( ) )
108
+
109
+ context. desiredAliasLocalPart = " room-name "
110
+
111
+ let publishingExpectation = expectation ( description: " Wait for publishing " )
112
+ roomProxy. publishRoomAliasInRoomDirectoryClosure = { roomAlias in
113
+ defer { publishingExpectation. fulfill ( ) }
114
+ XCTAssertEqual ( roomAlias, " #room-name:matrix.org " )
115
+ return . success( true )
116
+ }
117
+
118
+ let updateAliasExpectation = expectation ( description: " Wait for alias update " )
119
+ roomProxy. updateCanonicalAliasAltAliasesClosure = { roomAlias, altAliases in
120
+ defer { updateAliasExpectation. fulfill ( ) }
121
+ XCTAssertEqual ( altAliases, [ ] )
122
+ XCTAssertEqual ( roomAlias, " #room-name:matrix.org " )
123
+ return . success( ( ) )
124
+ }
125
+
126
+ let removeAliasExpectation = expectation ( description: " Wait for alias removal " )
127
+ roomProxy. removeRoomAliasFromRoomDirectoryClosure = { roomAlias in
128
+ defer { removeAliasExpectation. fulfill ( ) }
129
+ XCTAssertEqual ( roomAlias, " #old-room-name:matrix.org " )
130
+ return . success( true )
131
+ }
132
+
133
+ context. send ( viewAction: . save)
134
+ await fulfillment ( of: [ publishingExpectation, updateAliasExpectation, removeAliasExpectation] , timeout: 1.0 )
135
+ }
136
+
137
+ func testCorrectMethodsCalledOnSaveWhenAliasOnOtherHomeserverExists( ) async throws {
138
+ let clientProxy = ClientProxyMock ( . init( userIDServerName: " matrix.org " ) )
139
+ clientProxy. isAliasAvailableReturnValue = . success( true )
140
+ let roomProxy = JoinedRoomProxyMock ( . init( name: " Room Name " , canonicalAlias: " #old-room-name:element.io " ) )
141
+
142
+ viewModel = EditRoomAddressScreenViewModel ( roomProxy: roomProxy,
143
+ clientProxy: clientProxy,
144
+ userIndicatorController: UserIndicatorControllerMock ( ) )
145
+
146
+ context. desiredAliasLocalPart = " room-name "
147
+
148
+ let publishingExpectation = expectation ( description: " Wait for publishing " )
149
+ roomProxy. publishRoomAliasInRoomDirectoryClosure = { roomAlias in
150
+ defer { publishingExpectation. fulfill ( ) }
151
+ XCTAssertEqual ( roomAlias, " #room-name:matrix.org " )
152
+ return . success( true )
153
+ }
154
+
155
+ let updateAliasExpectation = expectation ( description: " Wait for alias update " )
156
+ roomProxy. updateCanonicalAliasAltAliasesClosure = { roomAlias, altAliases in
157
+ defer { updateAliasExpectation. fulfill ( ) }
158
+ XCTAssertEqual ( altAliases, [ " #room-name:matrix.org " ] )
159
+ XCTAssertEqual ( roomAlias, " #old-room-name:element.io " )
160
+ return . success( ( ) )
161
+ }
162
+
81
163
context. send ( viewAction: . save)
164
+ await fulfillment ( of: [ publishingExpectation, updateAliasExpectation] , timeout: 1.0 )
165
+ XCTAssertFalse ( roomProxy. removeRoomAliasFromRoomDirectoryCalled)
82
166
}
83
167
}
0 commit comments