mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Generate mocks for all SDK classes and introduce a simple TimelineItemFactory test to try them out
This commit is contained in:
parent
c51593476c
commit
53fc5df55b
@ -68,6 +68,7 @@
|
|||||||
0C88044649BAEE6C49BFC43A /* SecureBackupControllerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C21A715237F2B6D6E80998C /* SecureBackupControllerProtocol.swift */; };
|
0C88044649BAEE6C49BFC43A /* SecureBackupControllerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C21A715237F2B6D6E80998C /* SecureBackupControllerProtocol.swift */; };
|
||||||
0C932A5158C1D0604DFC5750 /* ComposerToolbarViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA29952595B804DA221A0C1D /* ComposerToolbarViewModelTests.swift */; };
|
0C932A5158C1D0604DFC5750 /* ComposerToolbarViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA29952595B804DA221A0C1D /* ComposerToolbarViewModelTests.swift */; };
|
||||||
0CF81807BE5FBFC9E2BBCECF /* PollFormScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3368395F06AA180138E185B6 /* PollFormScreenUITests.swift */; };
|
0CF81807BE5FBFC9E2BBCECF /* PollFormScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3368395F06AA180138E185B6 /* PollFormScreenUITests.swift */; };
|
||||||
|
0D4EB2ABAA5FE8CB10FDBCB8 /* TimelineItemFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AA3AF94A06D319BB37E52DA /* TimelineItemFactoryTests.swift */; };
|
||||||
0DC815CA24E1BD7F408F37D3 /* CollapsibleTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C4EA55DA62F9D0F984A2AE /* CollapsibleTimelineItem.swift */; };
|
0DC815CA24E1BD7F408F37D3 /* CollapsibleTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C4EA55DA62F9D0F984A2AE /* CollapsibleTimelineItem.swift */; };
|
||||||
0DCDF49AB95F75BFC8B1879C /* SwipeToReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49E45C3DC740D3AB9A47FD32 /* SwipeToReplyView.swift */; };
|
0DCDF49AB95F75BFC8B1879C /* SwipeToReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49E45C3DC740D3AB9A47FD32 /* SwipeToReplyView.swift */; };
|
||||||
0E08BB72B2258652CF501A8B /* Prefire in Frameworks */ = {isa = PBXBuildFile; productRef = 9B68DE8678BF67D4612BCC16 /* Prefire */; };
|
0E08BB72B2258652CF501A8B /* Prefire in Frameworks */ = {isa = PBXBuildFile; productRef = 9B68DE8678BF67D4612BCC16 /* Prefire */; };
|
||||||
@ -340,7 +341,6 @@
|
|||||||
5139F4BD5A5DF6F8D11A9BDE /* NotificationPermissionsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46D0BA44B1838E65B507B277 /* NotificationPermissionsScreen.swift */; };
|
5139F4BD5A5DF6F8D11A9BDE /* NotificationPermissionsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46D0BA44B1838E65B507B277 /* NotificationPermissionsScreen.swift */; };
|
||||||
518C93DC6516D3D018DE065F /* UNNotificationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49E751D7EDB6043238111D90 /* UNNotificationRequest.swift */; };
|
518C93DC6516D3D018DE065F /* UNNotificationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49E751D7EDB6043238111D90 /* UNNotificationRequest.swift */; };
|
||||||
51B3B19FA5F91B455C807BA7 /* RoomPollsHistoryScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E964AF2DFEB31E2B799999F /* RoomPollsHistoryScreenModels.swift */; };
|
51B3B19FA5F91B455C807BA7 /* RoomPollsHistoryScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E964AF2DFEB31E2B799999F /* RoomPollsHistoryScreenModels.swift */; };
|
||||||
520EEDAFBC778AB0B41F2F53 /* ClientMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADE6170EFE6A161B0A68AB61 /* ClientMock.swift */; };
|
|
||||||
523C6800ED85D5810CF18C19 /* OIDCAccountSettingsPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D737F4672021D0A7D218CD /* OIDCAccountSettingsPresenter.swift */; };
|
523C6800ED85D5810CF18C19 /* OIDCAccountSettingsPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D737F4672021D0A7D218CD /* OIDCAccountSettingsPresenter.swift */; };
|
||||||
52473A4D7B1FBD4CD1E770C8 /* MatrixEntityRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1A853D605C2146B0DC028 /* MatrixEntityRegex.swift */; };
|
52473A4D7B1FBD4CD1E770C8 /* MatrixEntityRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1A853D605C2146B0DC028 /* MatrixEntityRegex.swift */; };
|
||||||
5375902175B2FEA2949D7D74 /* LoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDDDDD9FE1A699D23A5E096 /* LoginScreen.swift */; };
|
5375902175B2FEA2949D7D74 /* LoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDDDDD9FE1A699D23A5E096 /* LoginScreen.swift */; };
|
||||||
@ -1733,6 +1733,7 @@
|
|||||||
9A22A05E472533ED3C5A31B3 /* NavigationModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationModule.swift; sourceTree = "<group>"; };
|
9A22A05E472533ED3C5A31B3 /* NavigationModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationModule.swift; sourceTree = "<group>"; };
|
||||||
9A2AC7BE17C05CF7D2A22338 /* landscape_test_video.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = landscape_test_video.mov; sourceTree = "<group>"; };
|
9A2AC7BE17C05CF7D2A22338 /* landscape_test_video.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = landscape_test_video.mov; sourceTree = "<group>"; };
|
||||||
9A68BCE6438873D2661D93D0 /* BugReportServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BugReportServiceProtocol.swift; sourceTree = "<group>"; };
|
9A68BCE6438873D2661D93D0 /* BugReportServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BugReportServiceProtocol.swift; sourceTree = "<group>"; };
|
||||||
|
9AA3AF94A06D319BB37E52DA /* TimelineItemFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItemFactoryTests.swift; sourceTree = "<group>"; };
|
||||||
9B06663F7858E45882E63471 /* StaticLocationScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticLocationScreen.swift; sourceTree = "<group>"; };
|
9B06663F7858E45882E63471 /* StaticLocationScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticLocationScreen.swift; sourceTree = "<group>"; };
|
||||||
9B663BE498BB39EADC24025D /* SettingsScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScreenModels.swift; sourceTree = "<group>"; };
|
9B663BE498BB39EADC24025D /* SettingsScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScreenModels.swift; sourceTree = "<group>"; };
|
||||||
9B67DF223EEB8DCAF178A1D4 /* AnalyticsPromptScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsPromptScreenCoordinator.swift; sourceTree = "<group>"; };
|
9B67DF223EEB8DCAF178A1D4 /* AnalyticsPromptScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsPromptScreenCoordinator.swift; sourceTree = "<group>"; };
|
||||||
@ -1807,7 +1808,6 @@
|
|||||||
AD9AD6AE5FC868962F090740 /* CallScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallScreenViewModelProtocol.swift; sourceTree = "<group>"; };
|
AD9AD6AE5FC868962F090740 /* CallScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallScreenViewModelProtocol.swift; sourceTree = "<group>"; };
|
||||||
AD9CB3B9DFA353AB2B7CD9F8 /* NotificationSettingsEditScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSettingsEditScreenCoordinator.swift; sourceTree = "<group>"; };
|
AD9CB3B9DFA353AB2B7CD9F8 /* NotificationSettingsEditScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSettingsEditScreenCoordinator.swift; sourceTree = "<group>"; };
|
||||||
ADCB8A232D3A8FB3E16A7303 /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/Localizable.strings; sourceTree = "<group>"; };
|
ADCB8A232D3A8FB3E16A7303 /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||||
ADE6170EFE6A161B0A68AB61 /* ClientMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientMock.swift; sourceTree = "<group>"; };
|
|
||||||
AE203026B9AD3DB412439866 /* MediaUploadingPreprocessorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaUploadingPreprocessorTests.swift; sourceTree = "<group>"; };
|
AE203026B9AD3DB412439866 /* MediaUploadingPreprocessorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaUploadingPreprocessorTests.swift; sourceTree = "<group>"; };
|
||||||
AE40D4A5DD857AC16EED945A /* URLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSession.swift; sourceTree = "<group>"; };
|
AE40D4A5DD857AC16EED945A /* URLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSession.swift; sourceTree = "<group>"; };
|
||||||
AE52983FAFB4E0998C00EE8A /* CancellableTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancellableTask.swift; sourceTree = "<group>"; };
|
AE52983FAFB4E0998C00EE8A /* CancellableTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancellableTask.swift; sourceTree = "<group>"; };
|
||||||
@ -2680,7 +2680,6 @@
|
|||||||
AAD01F7FC2BBAC7351948595 /* UserProfile+Mock.swift */,
|
AAD01F7FC2BBAC7351948595 /* UserProfile+Mock.swift */,
|
||||||
F4469F6AE311BDC439B3A5EC /* UserSessionMock.swift */,
|
F4469F6AE311BDC439B3A5EC /* UserSessionMock.swift */,
|
||||||
B23135B06B044CB811139D2F /* Generated */,
|
B23135B06B044CB811139D2F /* Generated */,
|
||||||
E5E545F92D01588360A9BAC5 /* SDK */,
|
|
||||||
);
|
);
|
||||||
path = Mocks;
|
path = Mocks;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -3594,6 +3593,7 @@
|
|||||||
C833673B334A0651AB46F30B /* StaticLocationScreenViewModelTests.swift */,
|
C833673B334A0651AB46F30B /* StaticLocationScreenViewModelTests.swift */,
|
||||||
2CEBCB9676FCD1D0F13188DD /* StringTests.swift */,
|
2CEBCB9676FCD1D0F13188DD /* StringTests.swift */,
|
||||||
2AB2C848BB9A7A9B618B7B89 /* TextBasedRoomTimelineTests.swift */,
|
2AB2C848BB9A7A9B618B7B89 /* TextBasedRoomTimelineTests.swift */,
|
||||||
|
9AA3AF94A06D319BB37E52DA /* TimelineItemFactoryTests.swift */,
|
||||||
1734A445A58ED855B977A0A8 /* TracingConfigurationTests.swift */,
|
1734A445A58ED855B977A0A8 /* TracingConfigurationTests.swift */,
|
||||||
76310030C831D4610A705603 /* URLComponentsTests.swift */,
|
76310030C831D4610A705603 /* URLComponentsTests.swift */,
|
||||||
EB3B237387B8288A5A938F1B /* UserAgentBuilderTests.swift */,
|
EB3B237387B8288A5A938F1B /* UserAgentBuilderTests.swift */,
|
||||||
@ -4913,14 +4913,6 @@
|
|||||||
path = Screens;
|
path = Screens;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
E5E545F92D01588360A9BAC5 /* SDK */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
ADE6170EFE6A161B0A68AB61 /* ClientMock.swift */,
|
|
||||||
);
|
|
||||||
path = SDK;
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
E600AACDF87CDBCE32683236 /* Resources */ = {
|
E600AACDF87CDBCE32683236 /* Resources */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@ -5797,6 +5789,7 @@
|
|||||||
1FEC0A4EC6E6DF693C16B32A /* StringTests.swift in Sources */,
|
1FEC0A4EC6E6DF693C16B32A /* StringTests.swift in Sources */,
|
||||||
E75CE800B3E64D0F7F8E228D /* TemplateScreenViewModelTests.swift in Sources */,
|
E75CE800B3E64D0F7F8E228D /* TemplateScreenViewModelTests.swift in Sources */,
|
||||||
3A7DD0D13B0FB8876D69D829 /* TextBasedRoomTimelineTests.swift in Sources */,
|
3A7DD0D13B0FB8876D69D829 /* TextBasedRoomTimelineTests.swift in Sources */,
|
||||||
|
0D4EB2ABAA5FE8CB10FDBCB8 /* TimelineItemFactoryTests.swift in Sources */,
|
||||||
282A5F3375DDC774AE09B0C3 /* TracingConfigurationTests.swift in Sources */,
|
282A5F3375DDC774AE09B0C3 /* TracingConfigurationTests.swift in Sources */,
|
||||||
8E650379587C31D7912ED67B /* UNNotification+Creator.swift in Sources */,
|
8E650379587C31D7912ED67B /* UNNotification+Creator.swift in Sources */,
|
||||||
AF33B9044498211C3D82F1E1 /* UNTextInputNotificationResponse+Creator.swift in Sources */,
|
AF33B9044498211C3D82F1E1 /* UNTextInputNotificationResponse+Creator.swift in Sources */,
|
||||||
@ -5956,7 +5949,6 @@
|
|||||||
BB6BF528BC7F5B87E08C4F18 /* CameraPicker.swift in Sources */,
|
BB6BF528BC7F5B87E08C4F18 /* CameraPicker.swift in Sources */,
|
||||||
E14E469CD97550D0FC58F3CA /* CancellableTask.swift in Sources */,
|
E14E469CD97550D0FC58F3CA /* CancellableTask.swift in Sources */,
|
||||||
6A0E7551E0D1793245F34CDD /* ClientError.swift in Sources */,
|
6A0E7551E0D1793245F34CDD /* ClientError.swift in Sources */,
|
||||||
520EEDAFBC778AB0B41F2F53 /* ClientMock.swift in Sources */,
|
|
||||||
1950A80CD198BED283DFC2CE /* ClientProxy.swift in Sources */,
|
1950A80CD198BED283DFC2CE /* ClientProxy.swift in Sources */,
|
||||||
DDFBDEE1DC32BDD5488F898C /* ClientProxyMock.swift in Sources */,
|
DDFBDEE1DC32BDD5488F898C /* ClientProxyMock.swift in Sources */,
|
||||||
24BDDD09A90B8BFE3793F3AA /* ClientProxyProtocol.swift in Sources */,
|
24BDDD09A90B8BFE3793F3AA /* ClientProxyProtocol.swift in Sources */,
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright 2023 New Vector Ltd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import MatrixRustSDK
|
|
||||||
|
|
||||||
// sourcery: AutoMockable
|
|
||||||
protocol SDKClientProtocol: ClientProtocol { }
|
|
246
Tools/Sourcery/SDKAutoMockable.stencil
Normal file
246
Tools/Sourcery/SDKAutoMockable.stencil
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
// swiftlint:disable all
|
||||||
|
{% for import in argument.autoMockableImports %}
|
||||||
|
import {{ import }}
|
||||||
|
{% endfor %}
|
||||||
|
{% for import in argument.autoMockableTestableImports %}
|
||||||
|
@testable import {{ import }}
|
||||||
|
{% endfor %}
|
||||||
|
{% macro swiftifyMethodName name %}{{ name | replace:"(","_" | replace:")","" | replace:":","_" | replace:"`","" | snakeToCamelCase | lowerFirstWord }}{% endmacro %}
|
||||||
|
{% macro accessLevel level %}{% if level != 'internal' %}{{ level }} {% endif %}{% endmacro %}
|
||||||
|
{% macro staticSpecifier method %}{% if method.isStatic and not method.isInitializer %}static {% endif %}{% endmacro %}
|
||||||
|
{% macro methodThrowableErrorDeclaration method %}
|
||||||
|
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call swiftifyMethodName method.selectorName %}ThrowableError: Error?
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro methodThrowableErrorUsage method %}
|
||||||
|
if let error = {% call swiftifyMethodName method.selectorName %}ThrowableError {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro methodReceivedParameters method %}
|
||||||
|
{% set hasNonEscapingClosures %}
|
||||||
|
{%- for param in method.parameters where param.isClosure and not param.typeAttributes.escaping %}
|
||||||
|
{{ true }}
|
||||||
|
{% endfor -%}
|
||||||
|
{% endset %}
|
||||||
|
{% if method.parameters.count == 1 and not hasNonEscapingClosures %}
|
||||||
|
{% call swiftifyMethodName method.selectorName %}Received{% for param in method.parameters %}{{ param.name | replace:"`","" | upperFirstLetter }} = {{ param.name | replace:"`","" }}{% endfor %}
|
||||||
|
{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append({% for param in method.parameters %}{{ param.name }}){% endfor %}
|
||||||
|
{% else %}
|
||||||
|
{% if not method.parameters.count == 0 and not hasNonEscapingClosures %}
|
||||||
|
{% call swiftifyMethodName method.selectorName %}ReceivedArguments = ({% for param in method.parameters %}{{ param.name | replace:"`","" }}: {{ param.name | replace:"`","" }}{% if not forloop.last%}, {% endif %}{% endfor %})
|
||||||
|
{% call swiftifyMethodName method.selectorName %}ReceivedInvocations.append(({% for param in method.parameters %}{{ param.name | replace:"`","" }}: {{ param.name | replace:"`","" }}{% if not forloop.last%}, {% endif %}{% endfor %}))
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro methodClosureName method %}{% call swiftifyMethodName method.selectorName %}Closure{% endmacro %}
|
||||||
|
{% macro closureReturnTypeName method %}{% if method.isOptionalReturnType %}{{ method.unwrappedReturnTypeName }}?{% else %}{{ method.returnTypeName }}{% endif %}{% endmacro %}
|
||||||
|
{% macro methodClosureDeclaration method %}
|
||||||
|
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call methodClosureName method %}: (({% for param in method.parameters %}{{ param.typeName }}{% if not forloop.last %}, {% endif %}{% endfor %}) {% if method.isAsync %}async {% endif %}{% if method.throws %}throws {% endif %}-> {% if method.isInitializer %}Void{% else %}{% call closureReturnTypeName method %}{% endif %})?
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro methodClosureCallParameters method %}{% for param in method.parameters %}{{ param.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %}
|
||||||
|
{% macro mockMethod method %}
|
||||||
|
|
||||||
|
//MARK: - {{ method.shortName }}
|
||||||
|
|
||||||
|
{% if method.throws %}
|
||||||
|
{% call methodThrowableErrorDeclaration method %}
|
||||||
|
{% endif %}
|
||||||
|
{% if not method.isInitializer %}
|
||||||
|
var {% call swiftifyMethodName method.selectorName %}UnderlyingCallsCount = 0
|
||||||
|
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call swiftifyMethodName method.selectorName %}CallsCount: Int {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return {% call swiftifyMethodName method.selectorName %}UnderlyingCallsCount
|
||||||
|
} else {
|
||||||
|
var returnValue: Int? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = {% call swiftifyMethodName method.selectorName %}UnderlyingCallsCount
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
{% call swiftifyMethodName method.selectorName %}UnderlyingCallsCount = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
{% call swiftifyMethodName method.selectorName %}UnderlyingCallsCount = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call swiftifyMethodName method.selectorName %}Called: Bool {
|
||||||
|
return {% call swiftifyMethodName method.selectorName %}CallsCount > 0
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
{% set hasNonEscapingClosures %}
|
||||||
|
{%- for param in method.parameters where param.isClosure and not param.typeAttributes.escaping %}
|
||||||
|
{{ true }}
|
||||||
|
{% endfor -%}
|
||||||
|
{% endset %}
|
||||||
|
{% if method.parameters.count == 1 and not hasNonEscapingClosures %}
|
||||||
|
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call swiftifyMethodName method.selectorName %}Received{% for param in method.parameters %}{{ param.name| replace:"`","" | upperFirstLetter }}: {{ '(' if param.isClosure }}{{ param.typeName.unwrappedTypeName }}{{ ')' if param.isClosure }}?{% endfor %}
|
||||||
|
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call swiftifyMethodName method.selectorName %}ReceivedInvocations{% for param in method.parameters %}: [{{ '(' if param.isClosure }}{{ param.typeName.unwrappedTypeName }}{{ ')' if param.isClosure }}{%if param.typeName.isOptional%}?{%endif%}]{% endfor %} = []
|
||||||
|
{% elif not method.parameters.count == 0 and not hasNonEscapingClosures %}
|
||||||
|
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call swiftifyMethodName method.selectorName %}ReceivedArguments: ({% for param in method.parameters %}{{ param.name }}: {{ param.unwrappedTypeName if param.typeAttributes.escaping else param.typeName }}{{ ', ' if not forloop.last }}{% endfor %})?
|
||||||
|
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call swiftifyMethodName method.selectorName %}ReceivedInvocations: [({% for param in method.parameters %}{{ param.name }}: {{ param.unwrappedTypeName if param.typeAttributes.escaping else param.typeName }}{{ ', ' if not forloop.last }}{% endfor %})] = []
|
||||||
|
{% endif %}
|
||||||
|
{% if not method.returnTypeName.isVoid and not method.isInitializer %}
|
||||||
|
|
||||||
|
var {% call swiftifyMethodName method.selectorName %}UnderlyingReturnValue: {{ '(' if method.returnTypeName.isClosure and not method.isOptionalReturnType }}{{ method.returnTypeName }}{{ ')' if method.returnTypeName.isClosure and not method.isOptionalReturnType }}{{ '!' if not method.isOptionalReturnType }}
|
||||||
|
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call swiftifyMethodName method.selectorName %}ReturnValue: {{ '(' if method.returnTypeName.isClosure and not method.isOptionalReturnType }}{{ method.returnTypeName }}{{ ')' if method.returnTypeName.isClosure and not method.isOptionalReturnType }}{{ '!' if not method.isOptionalReturnType }} {
|
||||||
|
get {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
return {% call swiftifyMethodName method.selectorName %}UnderlyingReturnValue
|
||||||
|
} else {
|
||||||
|
var returnValue: {{ method.returnTypeName }}? = nil
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
returnValue = {% call swiftifyMethodName method.selectorName %}UnderlyingReturnValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
{% call swiftifyMethodName method.selectorName %}UnderlyingReturnValue = newValue
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
{% call swiftifyMethodName method.selectorName %}UnderlyingReturnValue = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
{% call methodClosureDeclaration method %}
|
||||||
|
|
||||||
|
{% if method.isInitializer %}
|
||||||
|
{% else %}
|
||||||
|
{% for name, attribute in method.attributes %}
|
||||||
|
{% for value in attribute %}
|
||||||
|
{{ value }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
{% call accessLevel method.accessLevel %}override {% call staticSpecifier method %}func {{ method.name }}{{ ' async' if method.isAsync }}{{ ' throws' if method.throws }}{% if not method.returnTypeName.isVoid %} -> {{ method.returnTypeName }}{% endif %} {
|
||||||
|
{% if method.throws %}
|
||||||
|
{% call methodThrowableErrorUsage method %}
|
||||||
|
{% endif %}
|
||||||
|
{% call swiftifyMethodName method.selectorName %}CallsCount += 1
|
||||||
|
{% call methodReceivedParameters method %}
|
||||||
|
{% if method.returnTypeName.isVoid %}
|
||||||
|
{% if method.throws %}try {% endif %}{% if method.isAsync %}await {% endif %}{% call methodClosureName method %}?({% call methodClosureCallParameters method %})
|
||||||
|
{% else %}
|
||||||
|
if let {% call methodClosureName method %} = {% call methodClosureName method %} {
|
||||||
|
return {{ 'try ' if method.throws }}{{ 'await ' if method.isAsync }}{% call methodClosureName method %}({% call methodClosureCallParameters method %})
|
||||||
|
} else {
|
||||||
|
return {% call swiftifyMethodName method.selectorName %}ReturnValue
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro resetMethod method %}
|
||||||
|
{# for type method which are mocked, a way to reset the invocation, argument, etc #}
|
||||||
|
{% if method.isStatic and not method.isInitializer and method.accessLevel == "open" %} //MARK: - {{ method.shortName }}
|
||||||
|
{% if not method.isInitializer %}
|
||||||
|
{% call swiftifyMethodName method.selectorName %}CallsCount = 0
|
||||||
|
{% endif %}
|
||||||
|
{% if method.parameters.count == 1 %}
|
||||||
|
{% call swiftifyMethodName method.selectorName %}Received{% for param in method.parameters %}{{ param.name|upperFirstLetter }}{% endfor %} = nil
|
||||||
|
{% call swiftifyMethodName method.selectorName %}ReceivedInvocations = []
|
||||||
|
{% elif not method.parameters.count == 0 %}
|
||||||
|
{% call swiftifyMethodName method.selectorName %}ReceivedArguments = nil
|
||||||
|
{% call swiftifyMethodName method.selectorName %}ReceivedInvocations = []
|
||||||
|
{% endif %}
|
||||||
|
{% call methodClosureName method %} = nil
|
||||||
|
{% if method.throws %}
|
||||||
|
{% call swiftifyMethodName method.selectorName %}ThrowableError = nil
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro mockOptionalVariable variable %}
|
||||||
|
{% if variable.name == 'delegate' %}weak {% endif %}{% call accessLevel variable.readAccess %}var {% call mockedVariableName variable %}: {{ variable.typeName }}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro mockNonOptionalArrayOrDictionaryVariable variable %}
|
||||||
|
{% call accessLevel variable.readAccess %}var {% call mockedVariableName variable %}: {{ variable.typeName }} = {% if variable.isArray %}[]{% elif variable.isDictionary %}[:]{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro mockNonOptionalVariable variable %}
|
||||||
|
{% call accessLevel variable.readAccess %}var {% call mockedVariableName variable %}: {{ variable.typeName }} {
|
||||||
|
get { return {% call underlyingMockedVariableName variable %} }
|
||||||
|
set(value) { {% call underlyingMockedVariableName variable %} = value }
|
||||||
|
}
|
||||||
|
{% set wrappedTypeName %}{% if variable.typeName.isProtocolComposition %}({{ variable.typeName }}){% else %}{{ variable.typeName }}{% endif %}{% endset %}
|
||||||
|
{% call accessLevel variable.readAccess %}var {% call underlyingMockedVariableName variable %}: {{ wrappedTypeName }}!
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro variableThrowableErrorDeclaration variable %}
|
||||||
|
{% call accessLevel variable.readAccess %}var {% call mockedVariableName variable %}ThrowableError: Error?
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro variableThrowableErrorUsage variable %}
|
||||||
|
if let error = {% call mockedVariableName variable %}ThrowableError {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro variableClosureDeclaration variable %}
|
||||||
|
{% call accessLevel variable.readAccess %}var {% call variableClosureName variable %}: (() {% if variable.isAsync %}async {% endif %}{% if variable.throws %}throws {% endif %}-> {{ variable.typeName }})?
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro variableClosureName variable %}{% call mockedVariableName variable %}Closure{% endmacro %}
|
||||||
|
{% macro mockAsyncOrThrowingVariable variable %}
|
||||||
|
{% call accessLevel variable.readAccess %}var {% call mockedVariableName variable %}CallsCount = 0
|
||||||
|
{% call accessLevel variable.readAccess %}var {% call mockedVariableName variable %}Called: Bool {
|
||||||
|
return {% call mockedVariableName variable %}CallsCount > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
{% call accessLevel variable.readAccess %}var {% call mockedVariableName variable %}: {{ variable.typeName }} {
|
||||||
|
get {% if variable.isAsync %}async {% endif %}{% if variable.throws %}throws {% endif %}{
|
||||||
|
{% if variable.throws %}
|
||||||
|
{% call variableThrowableErrorUsage variable %}
|
||||||
|
{% endif %}
|
||||||
|
{% call mockedVariableName variable %}CallsCount += 1
|
||||||
|
if let {% call variableClosureName variable %} = {% call variableClosureName variable %} {
|
||||||
|
return {{ 'try ' if variable.throws }}{{ 'await ' if variable.isAsync }}{% call variableClosureName variable %}()
|
||||||
|
} else {
|
||||||
|
return {% call underlyingMockedVariableName variable %}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{% call accessLevel variable.readAccess %}var {% call underlyingMockedVariableName variable %}: {{ variable.typeName }}{{ '!' if not variable.isOptional }}
|
||||||
|
{% if variable.throws %}
|
||||||
|
{% call variableThrowableErrorDeclaration variable %}
|
||||||
|
{% endif %}
|
||||||
|
{% call variableClosureDeclaration method %}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro underlyingMockedVariableName variable %}underlying{{ variable.name|upperFirstLetter }}{% endmacro %}
|
||||||
|
{% macro mockedVariableName variable %}{{ variable.name }}{% endmacro %}
|
||||||
|
{% for type in types.classes %}{% if type.name != "AutoMockable" %}{% if type.accessLevel == "open" %}
|
||||||
|
{% call accessLevel type.accessLevel %}class {{ type.name | replace:"Protocol","" }}SDKMock: MatrixRustSDK.{{ type.name }} {
|
||||||
|
{% if type.accessLevel == "open" %}
|
||||||
|
init() {
|
||||||
|
super.init(noPointer: .init())
|
||||||
|
}
|
||||||
|
|
||||||
|
public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
||||||
|
fatalError("init(unsafeFromRawPointer:) has not been implemented")
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for variable in type.allVariables|!definedInExtension %}
|
||||||
|
{% if variable.isAsync or variable.throws %}{% call mockAsyncOrThrowingVariable variable %}{% elif variable.isOptional %}{% call mockOptionalVariable variable %}{% elif variable.isArray or variable.isDictionary %}{% call mockNonOptionalArrayOrDictionaryVariable variable %}{% else %}{% call mockNonOptionalVariable variable %}{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if type.allMethods|static|count != 0 and type.allMethods|initializer|count != type.allMethods|static|count %}
|
||||||
|
static func reset()
|
||||||
|
{
|
||||||
|
{% for method in type.allMethods|static %}
|
||||||
|
{% call resetMethod method %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
{% for method in type.allMethods|!definedInExtension %}
|
||||||
|
{% if not method.isDeinitializer and method.accessLevel == "open" %}
|
||||||
|
{% call mockMethod method %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endif %}{% endif %}{% endfor %}
|
||||||
|
// swiftlint:enable all
|
@ -27,7 +27,7 @@ struct GenerateSDKMocks: ParsableCommand {
|
|||||||
|
|
||||||
/// Generates the SDK mocks using Sourcery.
|
/// Generates the SDK mocks using Sourcery.
|
||||||
func generateSDKMocks(ffiPath: String) throws {
|
func generateSDKMocks(ffiPath: String) throws {
|
||||||
try Zsh.run(command: "sourcery --sources \(ffiPath) --sources ElementX/Sources/Mocks/SDK --templates Tools/Sourcery --output ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift --args autoMockableImports=\"Foundation\",autoMockableImports=\"MatrixRustSDK\"")
|
try Zsh.run(command: "sourcery --sources \(ffiPath) --templates Tools/Sourcery/SDKAutoMockable.stencil --output ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift --args autoMockableImports=\"Foundation\",autoMockableImports=\"MatrixRustSDK\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Downloads the specified version of the `matrix_sdk_ffi.swift` file and returns the path to the downloaded file.
|
/// Downloads the specified version of the `matrix_sdk_ffi.swift` file and returns the path to the downloaded file.
|
||||||
|
@ -20,7 +20,7 @@ import XCTest
|
|||||||
|
|
||||||
final class MediaLoaderTests: XCTestCase {
|
final class MediaLoaderTests: XCTestCase {
|
||||||
func testMediaRequestCoalescing() async {
|
func testMediaRequestCoalescing() async {
|
||||||
let mediaLoadingClient = SDKClientMock()
|
let mediaLoadingClient = ClientSDKMock()
|
||||||
mediaLoadingClient.getMediaContentMediaSourceReturnValue = Data()
|
mediaLoadingClient.getMediaContentMediaSourceReturnValue = Data()
|
||||||
let mediaLoader = MediaLoader(client: mediaLoadingClient)
|
let mediaLoader = MediaLoader(client: mediaLoadingClient)
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ final class MediaLoaderTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testMediaThumbnailRequestCoalescing() async {
|
func testMediaThumbnailRequestCoalescing() async {
|
||||||
let mediaLoadingClient = SDKClientMock()
|
let mediaLoadingClient = ClientSDKMock()
|
||||||
mediaLoadingClient.getMediaThumbnailMediaSourceWidthHeightReturnValue = Data()
|
mediaLoadingClient.getMediaThumbnailMediaSourceWidthHeightReturnValue = Data()
|
||||||
let mediaLoader = MediaLoader(client: mediaLoadingClient)
|
let mediaLoader = MediaLoader(client: mediaLoadingClient)
|
||||||
|
|
||||||
|
59
UnitTests/Sources/TimelineItemFactoryTests.swift
Normal file
59
UnitTests/Sources/TimelineItemFactoryTests.swift
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2024 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
@testable import ElementX
|
||||||
|
import XCTest
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
class TimelineItemFactoryTests: XCTestCase {
|
||||||
|
func testCallInvite() async {
|
||||||
|
let ownUserID = "@alice:matrix.org"
|
||||||
|
let senderUserID = "@bob:matrix.org"
|
||||||
|
|
||||||
|
let factory = RoomTimelineItemFactory(userID: ownUserID,
|
||||||
|
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
|
||||||
|
stateEventStringBuilder: RoomStateEventStringBuilder(userID: ownUserID))
|
||||||
|
|
||||||
|
let eventTimelineItem = EventTimelineItemSDKMock()
|
||||||
|
eventTimelineItem.isOwnReturnValue = true
|
||||||
|
eventTimelineItem.timestampReturnValue = 0
|
||||||
|
eventTimelineItem.isEditableReturnValue = false
|
||||||
|
eventTimelineItem.canBeRepliedToReturnValue = false
|
||||||
|
eventTimelineItem.senderReturnValue = senderUserID
|
||||||
|
eventTimelineItem.senderProfileReturnValue = .pending
|
||||||
|
|
||||||
|
let timelineItemContent = TimelineItemContentSDKMock()
|
||||||
|
timelineItemContent.kindReturnValue = .callInvite
|
||||||
|
eventTimelineItem.contentReturnValue = timelineItemContent
|
||||||
|
|
||||||
|
let eventTimelineItemProxy = EventTimelineItemProxy(item: eventTimelineItem, id: "0")
|
||||||
|
|
||||||
|
let item = factory.buildTimelineItem(for: eventTimelineItemProxy, isDM: false)
|
||||||
|
|
||||||
|
guard let item = item as? CallInviteRoomTimelineItem else {
|
||||||
|
XCTFail("Incorrect item type")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertEqual(item.isReactable, false)
|
||||||
|
XCTAssertEqual(item.canBeRepliedTo, false)
|
||||||
|
XCTAssertEqual(item.isEditable, false)
|
||||||
|
XCTAssertEqual(item.sender, TimelineItemSender(id: senderUserID))
|
||||||
|
XCTAssertEqual(item.properties.isEdited, false)
|
||||||
|
XCTAssertEqual(item.properties.reactions, [])
|
||||||
|
XCTAssertEqual(item.properties.deliveryStatus, nil)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user