Skip to content

Commit 7179901

Browse files
authored
Updates to tests for iOS 17 (#2080)
1 parent b6610a1 commit 7179901

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

Loop/Managers/Alerts/StoredAlert.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ import UIKit
1212

1313
extension StoredAlert {
1414

15-
static var encoder = JSONEncoder()
16-
static var decoder = JSONDecoder()
17-
15+
static let encoder: JSONEncoder = {
16+
let encoder = JSONEncoder()
17+
encoder.outputFormatting = [.sortedKeys]
18+
encoder.dateEncodingStrategy = .iso8601
19+
return encoder
20+
}()
21+
22+
static let decoder: JSONDecoder = {
23+
let decoder = JSONDecoder()
24+
decoder.dateDecodingStrategy = .iso8601
25+
return decoder
26+
}()
27+
1828
convenience init(from alert: Alert, context: NSManagedObjectContext, issuedDate: Date = Date(), syncIdentifier: UUID = UUID()) {
1929
do {
2030
/// This code, using the `init(entity:insertInto:)` instead of the `init(context:)` avoids warnings during unit testing that look like this:

LoopTests/Managers/Alerts/AlertStoreTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class AlertStoreTests: XCTestCase {
7272
let object = StoredAlert(from: alert2, context: alertStore.managedObjectContext, issuedDate: Self.historicDate)
7373
XCTAssertNil(object.acknowledgedDate)
7474
XCTAssertNil(object.retractedDate)
75-
XCTAssertEqual("{\"title\":\"title\",\"acknowledgeActionButtonLabel\":\"label\",\"body\":\"body\"}", object.backgroundContent)
76-
XCTAssertEqual("{\"title\":\"title\",\"acknowledgeActionButtonLabel\":\"label\",\"body\":\"body\"}", object.foregroundContent)
75+
XCTAssertEqual("{\"acknowledgeActionButtonLabel\":\"label\",\"body\":\"body\",\"title\":\"title\"}", object.backgroundContent)
76+
XCTAssertEqual("{\"acknowledgeActionButtonLabel\":\"label\",\"body\":\"body\",\"title\":\"title\"}", object.foregroundContent)
7777
XCTAssertEqual("managerIdentifier2.alertIdentifier2", object.identifier.value)
7878
XCTAssertEqual(Self.historicDate, object.issuedDate)
7979
XCTAssertEqual(1, object.modificationCounter)
@@ -870,14 +870,14 @@ class AlertStoreLogCriticalEventLogTests: XCTestCase {
870870
endDate: dateFormatter.date(from: "2100-01-02T03:09:00Z")!,
871871
to: outputStream,
872872
progress: progress))
873-
XCTAssertEqual(outputStream.string, """
874-
[
875-
{"acknowledgedDate":"2100-01-02T03:08:00.000Z","alertIdentifier":"a1","backgroundContent":"{\\\"title\\\":\\\"BACKGROUND\\\",\\\"acknowledgeActionButtonLabel\\\":\\\"OK\\\",\\\"body\\\":\\\"background\\\"}","interruptionLevel":"timeSensitive","issuedDate":"2100-01-02T03:08:00.000Z","managerIdentifier":"m1","modificationCounter":1,"syncIdentifier":"52A046F7-F449-49B2-B003-7A378D0002DE","triggerType":0},
876-
{"acknowledgedDate":"2100-01-02T03:04:00.000Z","alertIdentifier":"a3","backgroundContent":"{\\\"title\\\":\\\"BACKGROUND\\\",\\\"acknowledgeActionButtonLabel\\\":\\\"OK\\\",\\\"body\\\":\\\"background\\\"}","interruptionLevel":"timeSensitive","issuedDate":"2100-01-02T03:04:00.000Z","managerIdentifier":"m3","modificationCounter":3,"syncIdentifier":"285AEA4B-0DEE-41F4-8669-800E9582A6E7","triggerType":0},
877-
{"acknowledgedDate":"2100-01-02T03:06:00.000Z","alertIdentifier":"a4","backgroundContent":"{\\\"title\\\":\\\"BACKGROUND\\\",\\\"acknowledgeActionButtonLabel\\\":\\\"OK\\\",\\\"body\\\":\\\"background\\\"}","interruptionLevel":"timeSensitive","issuedDate":"2100-01-02T03:06:00.000Z","managerIdentifier":"m4","modificationCounter":4,"syncIdentifier":"4B3109BD-DE11-42BD-A777-D4783459C483","triggerType":0}
878-
]
879-
"""
880-
)
873+
874+
XCTAssertEqual(outputStream.string, #"""
875+
[
876+
{"acknowledgedDate":"2100-01-02T03:08:00.000Z","alertIdentifier":"a1","backgroundContent":"{\"acknowledgeActionButtonLabel\":\"OK\",\"body\":\"background\",\"title\":\"BACKGROUND\"}","interruptionLevel":"timeSensitive","issuedDate":"2100-01-02T03:08:00.000Z","managerIdentifier":"m1","modificationCounter":1,"syncIdentifier":"52A046F7-F449-49B2-B003-7A378D0002DE","triggerType":0},
877+
{"acknowledgedDate":"2100-01-02T03:04:00.000Z","alertIdentifier":"a3","backgroundContent":"{\"acknowledgeActionButtonLabel\":\"OK\",\"body\":\"background\",\"title\":\"BACKGROUND\"}","interruptionLevel":"timeSensitive","issuedDate":"2100-01-02T03:04:00.000Z","managerIdentifier":"m3","modificationCounter":3,"syncIdentifier":"285AEA4B-0DEE-41F4-8669-800E9582A6E7","triggerType":0},
878+
{"acknowledgedDate":"2100-01-02T03:06:00.000Z","alertIdentifier":"a4","backgroundContent":"{\"acknowledgeActionButtonLabel\":\"OK\",\"body\":\"background\",\"title\":\"BACKGROUND\"}","interruptionLevel":"timeSensitive","issuedDate":"2100-01-02T03:06:00.000Z","managerIdentifier":"m4","modificationCounter":4,"syncIdentifier":"4B3109BD-DE11-42BD-A777-D4783459C483","triggerType":0}
879+
]
880+
"""#)
881881
XCTAssertEqual(progress.completedUnitCount, 3 * 1)
882882
}
883883

LoopTests/Managers/Alerts/StoredAlertTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,34 @@ class StoredAlertEncodableTests: XCTestCase {
4545
let storedAlert = StoredAlert(from: alert, context: managedObjectContext, syncIdentifier: UUID(uuidString: "A7073F28-0322-4506-A733-CF6E0687BAF7")!)
4646
XCTAssertEqual(.active, storedAlert.interruptionLevel)
4747
storedAlert.issuedDate = dateFormatter.date(from: "2020-05-14T21:00:12Z")!
48-
try! assertStoredAlertEncodable(storedAlert, encodesJSON: """
48+
try! assertStoredAlertEncodable(storedAlert, encodesJSON: #"""
4949
{
5050
"alertIdentifier" : "bar",
51-
"backgroundContent" : "{\\\"title\\\":\\\"BACKGROUND\\\",\\\"acknowledgeActionButtonLabel\\\":\\\"OK\\\",\\\"body\\\":\\\"background\\\"}",
51+
"backgroundContent" : "{\"acknowledgeActionButtonLabel\":\"OK\",\"body\":\"background\",\"title\":\"BACKGROUND\"}",
5252
"interruptionLevel" : "active",
5353
"issuedDate" : "2020-05-14T21:00:12Z",
5454
"managerIdentifier" : "foo",
5555
"modificationCounter" : 1,
5656
"syncIdentifier" : "A7073F28-0322-4506-A733-CF6E0687BAF7",
5757
"triggerType" : 0
5858
}
59-
"""
59+
"""#
6060
)
6161

6262
storedAlert.interruptionLevel = .critical
6363
XCTAssertEqual(.critical, storedAlert.interruptionLevel)
64-
try! assertStoredAlertEncodable(storedAlert, encodesJSON: """
64+
try! assertStoredAlertEncodable(storedAlert, encodesJSON: #"""
6565
{
6666
"alertIdentifier" : "bar",
67-
"backgroundContent" : "{\\\"title\\\":\\\"BACKGROUND\\\",\\\"acknowledgeActionButtonLabel\\\":\\\"OK\\\",\\\"body\\\":\\\"background\\\"}",
67+
"backgroundContent" : "{\"acknowledgeActionButtonLabel\":\"OK\",\"body\":\"background\",\"title\":\"BACKGROUND\"}",
6868
"interruptionLevel" : "critical",
6969
"issuedDate" : "2020-05-14T21:00:12Z",
7070
"managerIdentifier" : "foo",
7171
"modificationCounter" : 1,
7272
"syncIdentifier" : "A7073F28-0322-4506-A733-CF6E0687BAF7",
7373
"triggerType" : 0
7474
}
75-
"""
75+
"""#
7676
)
7777
}
7878
}

LoopTests/ViewModels/BolusEntryViewModelTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,14 @@ class BolusEntryViewModelTests: XCTestCase {
702702
func testCarbEntryDateAndAbsorptionTimeString() async throws {
703703
await setUpViewModel(originalCarbEntry: mockOriginalCarbEntry, potentialCarbEntry: mockPotentialCarbEntry)
704704

705-
XCTAssertEqual("12:00 PM + 0m", bolusEntryViewModel.carbEntryDateAndAbsorptionTimeString)
705+
XCTAssertEqual("12:00PM + 0m", bolusEntryViewModel.carbEntryDateAndAbsorptionTimeString)
706706
}
707707

708708
func testCarbEntryDateAndAbsorptionTimeString2() async throws {
709709
let potentialCarbEntry = NewCarbEntry(quantity: BolusEntryViewModelTests.exampleCarbQuantity, startDate: Self.exampleStartDate, foodType: nil, absorptionTime: nil)
710710
await setUpViewModel(originalCarbEntry: mockOriginalCarbEntry, potentialCarbEntry: potentialCarbEntry)
711711

712-
XCTAssertEqual("12:00 PM", bolusEntryViewModel.carbEntryDateAndAbsorptionTimeString)
712+
XCTAssertEqual("12:00PM", bolusEntryViewModel.carbEntryDateAndAbsorptionTimeString)
713713
}
714714

715715
func testIsManualGlucosePromptVisible() throws {

0 commit comments

Comments
 (0)