mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
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:
@@ -8,57 +8,62 @@
|
||||
|
||||
import CoreLocation
|
||||
@testable import ElementX
|
||||
import XCTest
|
||||
import Testing
|
||||
|
||||
final class MapTilerURLBuilderTests: XCTestCase {
|
||||
@Suite
|
||||
struct MapTilerURLBuilderTests {
|
||||
private static let baseURL: URL = "http://www.foo.com"
|
||||
private static let apiKey = "some_key"
|
||||
private static let lightStyleID = "9bc819c8-e627-474a-a348-ec144fe3d810"
|
||||
private static let darkStyleID = "dea61faf-292b-4774-9660-58fcef89a7f3"
|
||||
|
||||
var builder: MapTilerURLBuilderProtocol!
|
||||
var builder: MapTilerURLBuilderProtocol
|
||||
|
||||
override func setUp() {
|
||||
init() {
|
||||
builder = MapTilerConfiguration(baseURL: Self.baseURL,
|
||||
apiKey: Self.apiKey,
|
||||
lightStyleID: Self.lightStyleID,
|
||||
darkStyleID: Self.darkStyleID)
|
||||
}
|
||||
|
||||
func testStaticMapBuilder() {
|
||||
|
||||
@Test
|
||||
func staticMapBuilder() {
|
||||
let url = builder.staticMapTileImageURL(for: .light,
|
||||
coordinates: .init(latitude: 1, longitude: 2),
|
||||
zoomLevel: 5,
|
||||
size: .init(width: 300, height: 200),
|
||||
attribution: .hidden)
|
||||
|
||||
|
||||
let expectedURL: URL = "http://www.foo.com/9bc819c8-e627-474a-a348-ec144fe3d810/static/2.000000,1.000000,5.000000/300x200@2x.png?key=some_key&attribution=false"
|
||||
XCTAssertEqual(url, expectedURL)
|
||||
#expect(url == expectedURL)
|
||||
}
|
||||
|
||||
func testStaticMapBuilderWithAttribution() {
|
||||
|
||||
@Test
|
||||
func staticMapBuilderWithAttribution() {
|
||||
let url = builder.staticMapTileImageURL(for: .dark,
|
||||
coordinates: .init(latitude: 1, longitude: 2),
|
||||
zoomLevel: 5,
|
||||
size: .init(width: 300, height: 200),
|
||||
attribution: .topLeft)
|
||||
|
||||
|
||||
let expectedURL: URL = "http://www.foo.com/dea61faf-292b-4774-9660-58fcef89a7f3/static/2.000000,1.000000,5.000000/300x200@2x.png?key=some_key&attribution=topleft"
|
||||
XCTAssertEqual(url, expectedURL)
|
||||
}
|
||||
|
||||
func testDynamicMapBuilder() {
|
||||
let url = builder.interactiveMapURL(for: .dark)
|
||||
let expectedURL: URL = "http://www.foo.com/dea61faf-292b-4774-9660-58fcef89a7f3/style.json?key=some_key"
|
||||
XCTAssertEqual(url, expectedURL)
|
||||
#expect(url == expectedURL)
|
||||
}
|
||||
|
||||
func testNilAPIKey() {
|
||||
@Test
|
||||
func dynamicMapBuilder() {
|
||||
let url = builder.interactiveMapURL(for: .dark)
|
||||
let expectedURL: URL = "http://www.foo.com/dea61faf-292b-4774-9660-58fcef89a7f3/style.json?key=some_key"
|
||||
#expect(url == expectedURL)
|
||||
}
|
||||
|
||||
@Test
|
||||
mutating func nilAPIKey() {
|
||||
let configuration = MapTilerConfiguration(baseURL: Self.baseURL,
|
||||
apiKey: nil,
|
||||
lightStyleID: Self.lightStyleID,
|
||||
darkStyleID: Self.darkStyleID)
|
||||
XCTAssertFalse(configuration.isEnabled)
|
||||
#expect(!configuration.isEnabled)
|
||||
|
||||
builder = configuration
|
||||
|
||||
@@ -67,9 +72,9 @@ final class MapTilerURLBuilderTests: XCTestCase {
|
||||
zoomLevel: 5,
|
||||
size: .init(width: 300, height: 200),
|
||||
attribution: .topLeft)
|
||||
XCTAssertNil(staticMapURL)
|
||||
#expect(staticMapURL == nil)
|
||||
|
||||
let dynamicMapURL = builder.interactiveMapURL(for: .light)
|
||||
XCTAssertNil(dynamicMapURL)
|
||||
#expect(dynamicMapURL == nil)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user