Swift Testing for Unit Tests PART 1 (#5119)

* migrated a lot of unit tests to Swift Testing and added a new implementation for deferred fulfillment

more tests migration

Cleaned the code manually to establish some good patterns

more code improvements

some more code improvements

removed empty tests

update project

* more pr suggestions and cleanups

* removed the TestSetup pattern

* fixing claude not reusing tests

* pr suggestion + added indent rule to swiftformat so that we can prevent AIs to change that
This commit is contained in:
Mauro
2026-02-19 16:20:47 +01:00
committed by GitHub
parent fc03e05697
commit 7982aef855
118 changed files with 4630 additions and 4129 deletions
@@ -7,10 +7,13 @@
//
@testable import ElementX
import XCTest
import Foundation
import Testing
final class TextBasedRoomTimelineTests: XCTestCase {
func testTextRoomTimelineItemWhitespaceEnd() {
@Suite
struct TextBasedRoomTimelineTests {
@Test
func textRoomTimelineItemWhitespaceEnd() {
let timestamp = Calendar.current.startOfDay(for: .now).addingTimeInterval(60 * 60) // 1:00 am
let timelineItem = TextRoomTimelineItem(id: .randomEvent,
timestamp: timestamp,
@@ -19,10 +22,11 @@ final class TextBasedRoomTimelineTests: XCTestCase {
canBeRepliedTo: true,
sender: .init(id: UUID().uuidString),
content: .init(body: "Test"))
XCTAssertEqual(timelineItem.additionalWhitespaces(), timestamp.formattedTime().count + 1)
#expect(timelineItem.additionalWhitespaces() == timestamp.formattedTime().count + 1)
}
func testTextRoomTimelineItemWhitespaceEndLonger() {
@Test
func textRoomTimelineItemWhitespaceEndLonger() {
let timestamp = Calendar.current.startOfDay(for: .now).addingTimeInterval(-60) // 11:59 pm
let timelineItem = TextRoomTimelineItem(id: .randomEvent,
timestamp: timestamp,
@@ -31,10 +35,11 @@ final class TextBasedRoomTimelineTests: XCTestCase {
canBeRepliedTo: true,
sender: .init(id: UUID().uuidString),
content: .init(body: "Test"))
XCTAssertEqual(timelineItem.additionalWhitespaces(), timestamp.formattedTime().count + 1)
#expect(timelineItem.additionalWhitespaces() == timestamp.formattedTime().count + 1)
}
func testTextRoomTimelineItemWhitespaceEndWithEdit() {
@Test
func textRoomTimelineItemWhitespaceEndWithEdit() {
let timestamp = Date.mock
var timelineItem = TextRoomTimelineItem(id: .randomEvent,
timestamp: timestamp,
@@ -45,10 +50,11 @@ final class TextBasedRoomTimelineTests: XCTestCase {
content: .init(body: "Test"))
timelineItem.properties.isEdited = true
let editedCount = L10n.commonEditedSuffix.count
XCTAssertEqual(timelineItem.additionalWhitespaces(), timestamp.formattedTime().count + editedCount + 2)
#expect(timelineItem.additionalWhitespaces() == timestamp.formattedTime().count + editedCount + 2)
}
func testTextRoomTimelineItemWhitespaceEndWithEditAndAlert() {
@Test
func textRoomTimelineItemWhitespaceEndWithEditAndAlert() {
let timestamp = Date.mock
var timelineItem = TextRoomTimelineItem(id: .randomEvent,
timestamp: timestamp,
@@ -60,6 +66,6 @@ final class TextBasedRoomTimelineTests: XCTestCase {
timelineItem.properties.isEdited = true
timelineItem.properties.deliveryStatus = .sendingFailed(.unknown)
let editedCount = L10n.commonEditedSuffix.count
XCTAssertEqual(timelineItem.additionalWhitespaces(), timestamp.formattedTime().count + editedCount + 5)
#expect(timelineItem.additionalWhitespaces() == timestamp.formattedTime().count + editedCount + 5)
}
}