Skip to content

Commit

Permalink
Updates to tests for iOS 17 (#2080)
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 authored Feb 18, 2024
1 parent b6610a1 commit 7179901
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
16 changes: 13 additions & 3 deletions Loop/Managers/Alerts/StoredAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ import UIKit

extension StoredAlert {

static var encoder = JSONEncoder()
static var decoder = JSONDecoder()

static let encoder: JSONEncoder = {
let encoder = JSONEncoder()
encoder.outputFormatting = [.sortedKeys]
encoder.dateEncodingStrategy = .iso8601
return encoder
}()

static let decoder: JSONDecoder = {
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
return decoder
}()

convenience init(from alert: Alert, context: NSManagedObjectContext, issuedDate: Date = Date(), syncIdentifier: UUID = UUID()) {
do {
/// This code, using the `init(entity:insertInto:)` instead of the `init(context:)` avoids warnings during unit testing that look like this:
Expand Down
20 changes: 10 additions & 10 deletions LoopTests/Managers/Alerts/AlertStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class AlertStoreTests: XCTestCase {
let object = StoredAlert(from: alert2, context: alertStore.managedObjectContext, issuedDate: Self.historicDate)
XCTAssertNil(object.acknowledgedDate)
XCTAssertNil(object.retractedDate)
XCTAssertEqual("{\"title\":\"title\",\"acknowledgeActionButtonLabel\":\"label\",\"body\":\"body\"}", object.backgroundContent)
XCTAssertEqual("{\"title\":\"title\",\"acknowledgeActionButtonLabel\":\"label\",\"body\":\"body\"}", object.foregroundContent)
XCTAssertEqual("{\"acknowledgeActionButtonLabel\":\"label\",\"body\":\"body\",\"title\":\"title\"}", object.backgroundContent)
XCTAssertEqual("{\"acknowledgeActionButtonLabel\":\"label\",\"body\":\"body\",\"title\":\"title\"}", object.foregroundContent)
XCTAssertEqual("managerIdentifier2.alertIdentifier2", object.identifier.value)
XCTAssertEqual(Self.historicDate, object.issuedDate)
XCTAssertEqual(1, object.modificationCounter)
Expand Down Expand Up @@ -870,14 +870,14 @@ class AlertStoreLogCriticalEventLogTests: XCTestCase {
endDate: dateFormatter.date(from: "2100-01-02T03:09:00Z")!,
to: outputStream,
progress: progress))
XCTAssertEqual(outputStream.string, """
[
{"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},
{"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},
{"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}
]
"""
)

XCTAssertEqual(outputStream.string, #"""
[
{"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},
{"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},
{"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}
]
"""#)
XCTAssertEqual(progress.completedUnitCount, 3 * 1)
}

Expand Down
12 changes: 6 additions & 6 deletions LoopTests/Managers/Alerts/StoredAlertTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,34 @@ class StoredAlertEncodableTests: XCTestCase {
let storedAlert = StoredAlert(from: alert, context: managedObjectContext, syncIdentifier: UUID(uuidString: "A7073F28-0322-4506-A733-CF6E0687BAF7")!)
XCTAssertEqual(.active, storedAlert.interruptionLevel)
storedAlert.issuedDate = dateFormatter.date(from: "2020-05-14T21:00:12Z")!
try! assertStoredAlertEncodable(storedAlert, encodesJSON: """
try! assertStoredAlertEncodable(storedAlert, encodesJSON: #"""
{
"alertIdentifier" : "bar",
"backgroundContent" : "{\\\"title\\\":\\\"BACKGROUND\\\",\\\"acknowledgeActionButtonLabel\\\":\\\"OK\\\",\\\"body\\\":\\\"background\\\"}",
"backgroundContent" : "{\"acknowledgeActionButtonLabel\":\"OK\",\"body\":\"background\",\"title\":\"BACKGROUND\"}",
"interruptionLevel" : "active",
"issuedDate" : "2020-05-14T21:00:12Z",
"managerIdentifier" : "foo",
"modificationCounter" : 1,
"syncIdentifier" : "A7073F28-0322-4506-A733-CF6E0687BAF7",
"triggerType" : 0
}
"""
"""#
)

storedAlert.interruptionLevel = .critical
XCTAssertEqual(.critical, storedAlert.interruptionLevel)
try! assertStoredAlertEncodable(storedAlert, encodesJSON: """
try! assertStoredAlertEncodable(storedAlert, encodesJSON: #"""
{
"alertIdentifier" : "bar",
"backgroundContent" : "{\\\"title\\\":\\\"BACKGROUND\\\",\\\"acknowledgeActionButtonLabel\\\":\\\"OK\\\",\\\"body\\\":\\\"background\\\"}",
"backgroundContent" : "{\"acknowledgeActionButtonLabel\":\"OK\",\"body\":\"background\",\"title\":\"BACKGROUND\"}",
"interruptionLevel" : "critical",
"issuedDate" : "2020-05-14T21:00:12Z",
"managerIdentifier" : "foo",
"modificationCounter" : 1,
"syncIdentifier" : "A7073F28-0322-4506-A733-CF6E0687BAF7",
"triggerType" : 0
}
"""
"""#
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions LoopTests/ViewModels/BolusEntryViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,14 @@ class BolusEntryViewModelTests: XCTestCase {
func testCarbEntryDateAndAbsorptionTimeString() async throws {
await setUpViewModel(originalCarbEntry: mockOriginalCarbEntry, potentialCarbEntry: mockPotentialCarbEntry)

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

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

XCTAssertEqual("12:00 PM", bolusEntryViewModel.carbEntryDateAndAbsorptionTimeString)
XCTAssertEqual("12:00PM", bolusEntryViewModel.carbEntryDateAndAbsorptionTimeString)
}

func testIsManualGlucosePromptVisible() throws {
Expand Down

0 comments on commit 7179901

Please sign in to comment.