From 259ae9444dfb488365a24bc701c77377712a133c Mon Sep 17 00:00:00 2001 From: Abhash Kumar Singh Date: Fri, 13 Oct 2023 13:04:55 -0700 Subject: [PATCH] Add a public boolean isLoaded property --- .../DataStore/Model/Lazy/List+Model.swift | 14 ++++++++++++-- .../AWSDataStorePluginTests/Core/ListTests.swift | 10 ++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift b/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift index 4833ba07e9..aee10e9e53 100644 --- a/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift +++ b/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift @@ -19,13 +19,22 @@ public class List: Collection, Codable, ExpressibleByArrayLite public typealias Element = ModelType /// Represents the data state of the `List`. - public enum LoadedState { + enum LoadedState { case notLoaded case loaded([Element]) } /// The current state of lazily loaded list - public internal(set) var loadedState: LoadedState + var loadedState: LoadedState + + /// Boolean property to check if list is loaded + public var isLoaded: Bool { + if case .loaded = loadedState { + return true + } + + return false + } /// The provider for fulfilling list behaviors let listProvider: AnyModelListProvider @@ -61,6 +70,7 @@ public class List: Collection, Codable, ExpressibleByArrayLite } } + // MARK: - Initializers public init(listProvider: AnyModelListProvider) { diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift index d69639c799..d94be55588 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift @@ -25,15 +25,9 @@ class ListTests: BaseDataStoreTests { let postId = preparePostDataForTest() func checkComments(_ comments: List) async throws { - guard case .notLoaded = comments.loadedState else { - XCTFail("Should not be loaded") - return - } + XCTAssertFalse(comments.isLoaded) try await comments.fetch() - guard case .loaded = comments.loadedState else { - XCTFail("Should be loaded") - return - } + XCTAssertTrue(comments.isLoaded) XCTAssertEqual(comments.count, 2) expect.fulfill() }