Skip to content

Commit

Permalink
♻️ Rename ExperienceLoader to ContentLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt authored and iujames committed Sep 17, 2024
1 parent 092cfbb commit 3ecde9c
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 45 deletions.
14 changes: 7 additions & 7 deletions Sources/AppcuesKit/Appcues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public class Appcues: NSObject {
return _actionRegistry as! ActionRegistry
}

private var _experienceLoader: Any?
private var _contentLoader: Any?
@available(iOS 13.0, *)
private var experienceLoader: ExperienceLoading {
if _experienceLoader == nil {
_experienceLoader = container.resolve(ExperienceLoading.self)
private var contentLoader: ContentLoading {
if _contentLoader == nil {
_contentLoader = container.resolve(ContentLoading.self)
}
// swiftlint:disable:next force_cast
return _experienceLoader as! ExperienceLoading
return _contentLoader as! ContentLoading
}

private lazy var notificationCenter = container.resolve(NotificationCenter.self)
Expand Down Expand Up @@ -227,7 +227,7 @@ public class Appcues: NSObject {
return
}

experienceLoader.load(experienceID: experienceID, published: true, queryItems: [], trigger: .showCall) { result in
contentLoader.load(experienceID: experienceID, published: true, queryItems: [], trigger: .showCall) { result in
switch result {
case .success:
completion?(true, nil)
Expand Down Expand Up @@ -360,7 +360,7 @@ public class Appcues: NSObject {
container.registerLazy(PushVerifier.self, initializer: PushVerifier.init)
container.registerLazy(DeepLinkHandling.self, initializer: DeepLinkHandler.init)
container.registerLazy(UIDebugging.self, initializer: UIDebugger.init)
container.registerLazy(ExperienceLoading.self, initializer: ExperienceLoader.init)
container.registerLazy(ContentLoading.self, initializer: ContentLoader.init)
container.registerLazy(ExperienceRendering.self, initializer: ExperienceRenderer.init)
container.registerLazy(TraitRegistry.self, initializer: TraitRegistry.init)
container.registerLazy(ActionRegistry.self, initializer: ActionRegistry.init)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ internal class AppcuesLaunchExperienceAction: AppcuesExperienceAction {
return completion()
}

let experienceLoading = appcues.container.resolve(ExperienceLoading.self)
experienceLoading.load(experienceID: experienceID, published: true, queryItems: [], trigger: trigger) { _ in
let contentLoader = appcues.container.resolve(ContentLoading.self)
contentLoader.load(experienceID: experienceID, published: true, queryItems: [], trigger: trigger) { _ in
completion()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ExperienceLoader.swift
// ContentLoader.swift
// AppcuesKit
//
// Created by James Ellis on 10/28/21.
Expand All @@ -9,7 +9,7 @@
import Foundation

@available(iOS 13.0, *)
internal protocol ExperienceLoading: AnyObject {
internal protocol ContentLoading: AnyObject {
func load(
experienceID: String,
published: Bool,
Expand All @@ -27,7 +27,7 @@ internal protocol ExperienceLoading: AnyObject {
}

@available(iOS 13.0, *)
internal class ExperienceLoader: ExperienceLoading {
internal class ContentLoader: ContentLoading {

private let config: Appcues.Config
private let storage: DataStoring
Expand Down
8 changes: 4 additions & 4 deletions Sources/AppcuesKit/Presentation/DeepLinkHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,30 @@ internal class DeepLinkHandler: DeepLinkHandling {
private func handle(action: Action) {
switch action {
case let .preview(experienceID, queryItems):
container?.resolve(ExperienceLoading.self).load(
container?.resolve(ContentLoading.self).load(
experienceID: experienceID,
published: false,
queryItems: queryItems,
trigger: .preview,
completion: previewCompletion
)
case let .show(experienceID, queryItems):
container?.resolve(ExperienceLoading.self).load(
container?.resolve(ContentLoading.self).load(
experienceID: experienceID,
published: true,
queryItems: queryItems,
trigger: .deepLink,
completion: nil
)
case let .pushPreview(id, queryItems):
container?.resolve(ExperienceLoading.self).loadPush(
container?.resolve(ContentLoading.self).loadPush(
id: id,
published: false,
queryItems: queryItems,
completion: nil
)
case let .pushContent(id):
container?.resolve(ExperienceLoading.self).loadPush(
container?.resolve(ContentLoading.self).loadPush(
id: id,
published: true,
queryItems: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AppcuesLaunchExperienceActionTests: XCTestCase {
// Arrange
var completionCount = 0
var loadCount = 0
appcues.experienceLoader.onLoad = { contentID, published, trigger, completion in
appcues.contentLoader.onLoad = { contentID, published, trigger, completion in
XCTAssertEqual(contentID, "123")
guard case .launchExperienceAction = trigger else { return XCTFail() }
loadCount += 1
Expand All @@ -55,7 +55,7 @@ class AppcuesLaunchExperienceActionTests: XCTestCase {
// Arrange
var completionCount = 0
var loadCount = 0
appcues.experienceLoader.onLoad = { contentID, published, trigger, completion in
appcues.contentLoader.onLoad = { contentID, published, trigger, completion in
XCTAssertEqual(contentID, "123")
guard case .launchExperienceAction = trigger else { return XCTFail() }
loadCount += 1
Expand Down
10 changes: 5 additions & 5 deletions Tests/AppcuesKitTests/AppcuesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class AppcuesTests: XCTestCase {
appcues.sessionID = UUID()
var completionCount = 0
var experienceShownCount = 0
appcues.experienceLoader.onLoad = { experienceID, published, trigger, completion in
appcues.contentLoader.onLoad = { experienceID, published, trigger, completion in
XCTAssertEqual(true, published)
XCTAssertEqual("1234", experienceID)
guard case .showCall = trigger else { return XCTFail() }
Expand All @@ -219,7 +219,7 @@ class AppcuesTests: XCTestCase {
appcues.sessionID = nil
var completionCount = 0
var experienceShownCount = 0
appcues.experienceLoader.onLoad = { experienceID, published, trigger, completion in
appcues.contentLoader.onLoad = { experienceID, published, trigger, completion in
experienceShownCount += 1
completion?(.failure(AppcuesError.noActiveSession))
}
Expand Down Expand Up @@ -319,7 +319,7 @@ class AppcuesTests: XCTestCase {
weak var weakActivityStoring = appcues?.container.resolve(ActivityStoring.self)
weak var weakDeepLinkHandling = appcues?.container.resolve(DeepLinkHandling.self)
weak var weakUIDebugging = appcues?.container.resolve(UIDebugging.self)
weak var weakExperienceLoading = appcues?.container.resolve(ExperienceLoading.self)
weak var weakContentLoading = appcues?.container.resolve(ContentLoading.self)
weak var weakExperienceRendering = appcues?.container.resolve(ExperienceRendering.self)
weak var weakTraitRegistry = appcues?.container.resolve(TraitRegistry.self)
weak var weakActionRegistry = appcues?.container.resolve(ActionRegistry.self)
Expand All @@ -338,7 +338,7 @@ class AppcuesTests: XCTestCase {
XCTAssertNotNil(weakActivityStoring)
XCTAssertNotNil(weakDeepLinkHandling)
XCTAssertNotNil(weakUIDebugging)
XCTAssertNotNil(weakExperienceLoading)
XCTAssertNotNil(weakContentLoading)
XCTAssertNotNil(weakExperienceRendering)
XCTAssertNotNil(weakTraitRegistry)
XCTAssertNotNil(weakActionRegistry)
Expand All @@ -361,7 +361,7 @@ class AppcuesTests: XCTestCase {
XCTAssertNil(weakActivityStoring)
XCTAssertNil(weakDeepLinkHandling)
XCTAssertNil(weakUIDebugging)
XCTAssertNil(weakExperienceLoading)
XCTAssertNil(weakContentLoading)
XCTAssertNil(weakExperienceRendering)
XCTAssertNil(weakTraitRegistry)
XCTAssertNil(weakActionRegistry)
Expand Down
10 changes: 5 additions & 5 deletions Tests/AppcuesKitTests/DeepLinkHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DeepLinkHandlerTests: XCTestCase {
let url = try XCTUnwrap(URL(string: "appcues-abc://sdk/experience_preview/invalid-id"))

var loaderCalled = false
appcues.experienceLoader.onLoad = { id, published, trigger, completion in
appcues.contentLoader.onLoad = { id, published, trigger, completion in
XCTAssertEqual(id, "invalid-id")
XCTAssertFalse(published)
guard case .preview = trigger else { return XCTFail() }
Expand Down Expand Up @@ -80,7 +80,7 @@ class DeepLinkHandlerTests: XCTestCase {
let url = try XCTUnwrap(URL(string: "appcues-abc://sdk/experience_preview/f0edab83-5257-47a5-81fc-80389d14905b"))

var loaderCalled = false
appcues.experienceLoader.onLoad = { id, published, trigger, completion in
appcues.contentLoader.onLoad = { id, published, trigger, completion in
XCTAssertEqual(id, "f0edab83-5257-47a5-81fc-80389d14905b")
XCTAssertFalse(published)
guard case .preview = trigger else { return XCTFail() }
Expand All @@ -102,7 +102,7 @@ class DeepLinkHandlerTests: XCTestCase {
let url = try XCTUnwrap(URL(string: "appcues-abc://sdk/experience_content/f0edab83-5257-47a5-81fc-80389d14905b"))

var loaderCalled = false
appcues.experienceLoader.onLoad = { id, published, trigger, completion in
appcues.contentLoader.onLoad = { id, published, trigger, completion in
XCTAssertEqual(id, "f0edab83-5257-47a5-81fc-80389d14905b")
XCTAssertTrue(published)
guard case .deepLink = trigger else { return XCTFail() }
Expand All @@ -125,7 +125,7 @@ class DeepLinkHandlerTests: XCTestCase {
let url = try XCTUnwrap(URL(string: "appcues-abc://sdk/push_preview/f0edab83-5257-47a5-81fc-80389d14905b?key=value"))

var loaderCalled = false
appcues.experienceLoader.onLoadPush = { id, published, queryItems, completion in
appcues.contentLoader.onLoadPush = { id, published, queryItems, completion in
XCTAssertEqual(id, "f0edab83-5257-47a5-81fc-80389d14905b")
XCTAssertEqual(queryItems, [URLQueryItem(name: "key", value: "value")])
XCTAssertFalse(published)
Expand All @@ -147,7 +147,7 @@ class DeepLinkHandlerTests: XCTestCase {
let url = try XCTUnwrap(URL(string: "appcues-abc://sdk/push_content/f0edab83-5257-47a5-81fc-80389d14905b"))

var loaderCalled = false
appcues.experienceLoader.onLoadPush = { id, published, queryItems, completion in
appcues.contentLoader.onLoadPush = { id, published, queryItems, completion in
XCTAssertEqual(id, "f0edab83-5257-47a5-81fc-80389d14905b")
XCTAssertEqual(queryItems.count, 0)
XCTAssertTrue(published)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ExperienceLoaderTests.swift
// ContentLoaderTests.swift
// AppcuesKitTests
//
// Created by Matt on 2022-05-25.
Expand All @@ -10,14 +10,14 @@ import XCTest
@testable import AppcuesKit

@available(iOS 13.0, *)
class ExperienceLoaderTests: XCTestCase {
class ContentLoaderTests: XCTestCase {

var appcues: MockAppcues!
var experienceLoader: ExperienceLoader!
var contentLoader: ContentLoader!

override func setUpWithError() throws {
appcues = MockAppcues()
experienceLoader = ExperienceLoader(container: appcues.container)
contentLoader = ContentLoader(container: appcues.container)
}

func testLoadPublished() throws {
Expand All @@ -39,7 +39,7 @@ class ExperienceLoaderTests: XCTestCase {
let completionExpectation = expectation(description: "Completion called")

// Act
experienceLoader.load(experienceID: "123", published: true, queryItems: [], trigger: .showCall) { result in
contentLoader.load(experienceID: "123", published: true, queryItems: [], trigger: .showCall) { result in
if case .success = result {
completionExpectation.fulfill()
}
Expand Down Expand Up @@ -68,7 +68,7 @@ class ExperienceLoaderTests: XCTestCase {
let completionExpectation = expectation(description: "Completion called")

// Act
experienceLoader.load(experienceID: "123", published: false, queryItems: [URLQueryItem(name: "query", value: "xyz")], trigger: .preview) { result in
contentLoader.load(experienceID: "123", published: false, queryItems: [URLQueryItem(name: "query", value: "xyz")], trigger: .preview) { result in
if case .success = result {
completionExpectation.fulfill()
}
Expand All @@ -87,7 +87,7 @@ class ExperienceLoaderTests: XCTestCase {
let completionExpectation = expectation(description: "Completion called")

// Act
experienceLoader.load(experienceID: "123", published: true, queryItems: [], trigger: .showCall) { result in
contentLoader.load(experienceID: "123", published: true, queryItems: [], trigger: .showCall) { result in
if case .failure = result {
completionExpectation.fulfill()
}
Expand All @@ -102,7 +102,7 @@ class ExperienceLoaderTests: XCTestCase {
let reloadExpectation = expectation(description: "Data loaded called")

// Load the initial preview
experienceLoader.load(experienceID: "123", published: false, queryItems: [], trigger: .preview, completion: nil)
contentLoader.load(experienceID: "123", published: false, queryItems: [], trigger: .preview, completion: nil)

appcues.networking.onGet = { endpoint, authorization, completion in
XCTAssertEqual(
Expand All @@ -127,9 +127,9 @@ class ExperienceLoaderTests: XCTestCase {
reloadExpectation.isInverted = true

// Load the initial preview
experienceLoader.load(experienceID: "123", published: false, queryItems: [], trigger: .preview, completion: nil)
contentLoader.load(experienceID: "123", published: false, queryItems: [], trigger: .preview, completion: nil)
// Load a published experience
experienceLoader.load(experienceID: "abc", published: true, queryItems: [], trigger: .preview, completion: nil)
contentLoader.load(experienceID: "abc", published: true, queryItems: [], trigger: .preview, completion: nil)

appcues.networking.onGet = { endpoint, authorization, completion in
reloadExpectation.fulfill()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class ExperienceStateMachineTests: XCTestCase {
let action: Action = .endExperience(markComplete: true)
let stateMachine = givenState(is: initialState)

appcues.experienceLoader.onLoad = { contentID, published, trigger, completion in
appcues.contentLoader.onLoad = { contentID, published, trigger, completion in
XCTAssertEqual(contentID, ExperienceData.mock.nextContentID)
XCTAssertTrue(published)
nextContentLoadedExpectation.fulfill()
Expand Down Expand Up @@ -251,7 +251,7 @@ class ExperienceStateMachineTests: XCTestCase {
let action: Action = .endExperience(markComplete: false)
let stateMachine = givenState(is: initialState)

appcues.experienceLoader.onLoad = { contentID, published, trigger, completion in
appcues.contentLoader.onLoad = { contentID, published, trigger, completion in
XCTFail("no next content should be shown")
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/AppcuesKitTests/MockAppcues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MockAppcues: Appcues {
if #available(iOS 13.0, *) {
container.register(DeepLinkHandling.self, value: deepLinkHandler)
container.register(UIDebugging.self, value: debugger)
container.register(ExperienceLoading.self, value: experienceLoader)
container.register(ContentLoading.self, value: contentLoader)
container.register(ExperienceRendering.self, value: MockExperienceRenderer())
container.registerLazy(TraitRegistry.self, initializer: TraitRegistry.init)
container.registerLazy(ActionRegistry.self, initializer: ActionRegistry.init)
Expand All @@ -56,7 +56,7 @@ class MockAppcues: Appcues {

var analyticsPublisher = MockAnalyticsPublisher()
var storage = MockStorage()
var experienceLoader = MockExperienceLoader()
var contentLoader = MockContentLoader()
var sessionMonitor = MockSessionMonitor()
var activityProcessor = MockActivityProcessor()
var debugger = MockDebugger()
Expand Down Expand Up @@ -124,7 +124,7 @@ class MockStorage: DataStoring {
var pushToken: String?
}

class MockExperienceLoader: ExperienceLoading {
class MockContentLoader: ContentLoading {

var onLoad: ((String, Bool, ExperienceTrigger, ((Result<Void, Error>) -> Void)?) -> Void)?
func load(
Expand Down
4 changes: 2 additions & 2 deletions Tests/AppcuesKitTests/Push/PushMonitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class PushMonitorTests: XCTestCase {
linkCompletionExpectation.fulfill()
}

appcues.experienceLoader.onLoad = { experienceID, published, trigger, completion in
appcues.contentLoader.onLoad = { experienceID, published, trigger, completion in
XCTAssertEqual(experienceID, "<some-experience>")
XCTAssertTrue(published)
XCTAssertEqual(trigger, .push)
Expand Down Expand Up @@ -274,7 +274,7 @@ class PushMonitorTests: XCTestCase {
linkCompletionExpectation.fulfill()
}

appcues.experienceLoader.onLoad = { experienceID, published, trigger, completion in
appcues.contentLoader.onLoad = { experienceID, published, trigger, completion in
XCTAssertEqual(experienceID, "<some-experience>")
XCTAssertTrue(published)
XCTAssertEqual(trigger, .push)
Expand Down

0 comments on commit 3ecde9c

Please sign in to comment.