Skip to content

Commit

Permalink
[MINI-6243] Refactor to use constants (#522)
Browse files Browse the repository at this point in the history
* Refactor to use constants

* Codecov fix
  • Loading branch information
rleojoseph authored Aug 2, 2023
1 parent 02a2385 commit b6e0d36
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 22 deletions.
9 changes: 0 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ orbs:
gh: circleci/[email protected]
macos: circleci/macos@2
ruby: circleci/[email protected]
codecov: codecov/[email protected]
app-center: rakutentech/[email protected]

container_medium: &container_medium
Expand Down Expand Up @@ -37,8 +36,6 @@ jobs:
- run:
name: Execute Tests
command: fastlane ci
- store_artifacts:
path: ./artifacts/unit-tests
- persist_to_workspace:
root: .
paths:
Expand All @@ -47,12 +44,6 @@ jobs:
root: ../
paths:
- MiniApp-Secrets.xcconfig
- codecov/upload:
file: "artifacts/unit-tests/report.junit"
- codecov/upload:
file: "artifacts/unit-tests/report.html"
- codecov/upload:
file: "artifacts/unit-tests/compile_commands.json"

app-center-publish-sim:
<<: *container_medium
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/fastlane.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Build and Test using Fastlane

on:
push:
branches:
- master
- candidate
pull_request:

jobs:
Expand Down
2 changes: 1 addition & 1 deletion Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
MiniApp.configure()
MiniApp.unzipMiniApp(fileName: "js-miniapp-sample", miniAppId: "mini-app-testing-appid", versionId: "mini-app-testing-versionid")
MiniApp.unzipMiniApp(fileName: "js-miniapp-sample", miniAppId: Global.DemoApp.bundleMiniAppId, versionId: Global.DemoApp.bundleMiniAppVersionId)
AppCenter.start(withAppSecret: Bundle.main.value(for: "AppCenterSecret"), services: [Crashes.self])

GADMobileAds.sharedInstance().start(completionHandler: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ struct MiniAppFromBundle: View {
VStack {
MiniAppSUIView(params: miniAppViewParams(config: ListConfiguration(listType: .listI).sdkConfig), fromCache: true, handler: MiniAppSUIViewHandler(), fromBundle: true)
}
.navigationTitle("MiniApp")
.navigationTitle(MiniAppSDKConstants.miniAppRootFolderName)
}

func miniAppViewParams(config: MiniAppSdkConfig) -> MiniAppViewParameters.DefaultParams {
return MiniAppViewParameters.DefaultParams.init(
config: MiniAppConfig(
config: config,
adsDisplayer: AdMobDisplayer(),
messageDelegate: MiniAppViewMessageDelegator(),
messageDelegate: MiniAppViewMessageDelegator(miniAppId: Global.DemoApp.bundleMiniAppId,
miniAppVersion: Global.DemoApp.bundleMiniAppVersionId),
navigationDelegate: MiniAppViewNavigationDelegator()
),
type: .miniapp,
appId: "mini-app-testing-appid",
version: "mini-app-testing-versionid",
appId: Global.DemoApp.bundleMiniAppId,
version: Global.DemoApp.bundleMiniAppVersionId,
queryParams: getQueryParam()
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI
import Combine
import MiniApp

struct MiniAppFeatureListView: View {

Expand All @@ -17,7 +18,7 @@ struct MiniAppFeatureListView: View {
})
NavigationLink(destination: MiniAppFromBundle(), label: {
MiniAppFeatureListCell(
title: "Miniapp",
title: MiniAppSDKConstants.miniAppRootFolderName,
subTitle: "Open a miniapp from Bundle",
active: true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct MiniAppSingleView: View {
VStack {
MiniAppWithTermsView(viewModel: viewModel, handler: handler)
}
.navigationTitle(handler.isActive ? handler.miniAppTitle?() ?? "MiniApp" : "MiniApp")
.navigationTitle(handler.isActive ? handler.miniAppTitle?() ?? MiniAppSDKConstants.miniAppRootFolderName : MiniAppSDKConstants.miniAppRootFolderName)
.navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden(true)
.toolbar(content: {
Expand Down
8 changes: 8 additions & 0 deletions Example/Utils/Global.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

struct Global {
struct DemoApp {
static let bundleMiniAppId = "mini-app-testing-appid"
static let bundleMiniAppVersionId = "mini-app-testing-versionid"
}
}
4 changes: 4 additions & 0 deletions Sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
1CD1591829421FDF001E0E21 /* UniversalBridgeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD1591729421FDF001E0E21 /* UniversalBridgeView.swift */; };
2A52E3C12A42EFAC00DC8EFE /* js-miniapp-sample.zip in Resources */ = {isa = PBXBuildFile; fileRef = 2A52E3C02A42EFAC00DC8EFE /* js-miniapp-sample.zip */; };
2A52E3C42A42F0F100DC8EFE /* MiniAppFromBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A52E3C32A42F0F100DC8EFE /* MiniAppFromBundle.swift */; };
2A708B452A79F2C900E4E1BF /* Global.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A708B442A79F2C900E4E1BF /* Global.swift */; };
2AB1B0A226A6CDEF004CAC1B /* MASDKLocaleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB1B0A126A6CDEF004CAC1B /* MASDKLocaleTests.swift */; };
2AB1B0E326A6D7DA004CAC1B /* MiniAppExternalWebViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB1B0D926A6D7B4004CAC1B /* MiniAppExternalWebViewControllerTests.swift */; };
2AB1B0E926A6D7F3004CAC1B /* CustomPermissionsViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB1B0E826A6D7F3004CAC1B /* CustomPermissionsViewControllerTests.swift */; };
Expand Down Expand Up @@ -160,6 +161,7 @@
1CD1591729421FDF001E0E21 /* UniversalBridgeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniversalBridgeView.swift; sourceTree = "<group>"; };
2A52E3C02A42EFAC00DC8EFE /* js-miniapp-sample.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = "js-miniapp-sample.zip"; sourceTree = "<group>"; };
2A52E3C32A42F0F100DC8EFE /* MiniAppFromBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MiniAppFromBundle.swift; sourceTree = "<group>"; };
2A708B442A79F2C900E4E1BF /* Global.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Global.swift; sourceTree = "<group>"; };
2AB1B0A126A6CDEF004CAC1B /* MASDKLocaleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MASDKLocaleTests.swift; sourceTree = "<group>"; };
2AB1B0D926A6D7B4004CAC1B /* MiniAppExternalWebViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MiniAppExternalWebViewControllerTests.swift; sourceTree = "<group>"; };
2AB1B0E826A6D7F3004CAC1B /* CustomPermissionsViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomPermissionsViewControllerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -435,6 +437,7 @@
3857ED7D25DEE0690083F3E1 /* Bundle+MiniApp.swift */,
31850BC0269837F300CFE422 /* UIColor+MiniApp.swift */,
D0CACE25281A68D700E39920 /* Base64UriHelper.swift */,
2A708B442A79F2C900E4E1BF /* Global.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -893,6 +896,7 @@
38920AF2251D9C57004C5DDD /* ImageCache.swift in Sources */,
F70DD8EF28D417C4003EF1F1 /* MiniAppSettingsGeneralView.swift in Sources */,
F70DD8FD28D417C4003EF1F1 /* MiniAppListView.swift in Sources */,
2A708B452A79F2C900E4E1BF /* Global.swift in Sources */,
F70DD90628D417C4003EF1F1 /* LocationManager.swift in Sources */,
A13C249826A15048003ADC6D /* UserPointsModel.swift in Sources */,
F70DD8E728D417C4003EF1F1 /* MiniAppDashboardView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CustomPermissionsRequestViewController: UIViewController {

var customPermissionHandlerObj: CustomPermissionsCompletionHandler?
var permissionsRequestList: [MASDKCustomPermissionModel]?
var miniAppTitle: String = "MiniApp"
var miniAppTitle: String = MiniAppSDKConstants.miniAppRootFolderName

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Classes/core/Extensions/Bundle+Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension Bundle {
}

public class var miniAppSDKBundle: Bundle {
miniAppBundle("MiniApp")
miniAppBundle(MiniAppSDKConstants.miniAppRootFolderName)
}

class var miniAppLocalizationBundle: Bundle {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Classes/core/Utilities/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ enum Constants {
public typealias MASDKDownloadedListPermissionsPair = [(MiniAppInfo, [MASDKCustomPermissionModel])]

let offlineErrorCodeList: [Int] = [NSURLErrorNotConnectedToInternet, NSURLErrorTimedOut, NSURLErrorDataNotAllowed]

public struct MiniAppSDKConstants {
public static let miniAppRootFolderName = "MiniApp"
}
2 changes: 1 addition & 1 deletion Sources/Classes/core/View/MiniAppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public class MiniAppView: UIView, MiniAppViewable {
}

public var miniAppTitle: String {
return miniAppHandler.title.isEmpty ? "MiniApp" : miniAppHandler.title
return miniAppHandler.title.isEmpty ? MiniAppSDKConstants.miniAppRootFolderName : miniAppHandler.title
}

public enum MiniAppLoadStatus {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Classes/core/View/MiniAppViewHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class MiniAppViewHandler: NSObject {
}
switch result {
case .success(let info):
let miniAppTitle = info.displayName ?? "MiniApp"
let miniAppTitle = info.displayName ?? MiniAppSDKConstants.miniAppRootFolderName
self.title = miniAppTitle
self.downloadMiniApp(appInfo: info, queryParams: self.queryParams) { result in
switch result {
Expand Down Expand Up @@ -330,7 +330,7 @@ class MiniAppViewHandler: NSObject {

func loadWebView(
webView: MiniAppWebView,
miniAppTitle: String = "MiniApp",
miniAppTitle: String = MiniAppSDKConstants.miniAppRootFolderName,
miniAppId: String,
versionId: String,
queryParams: String? = nil,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/MiniAppViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class MiniAppViewTests: XCTestCase {
)
)
let view = MiniAppView(params: params)
XCTAssertEqual(view.miniAppTitle, "MiniApp")
XCTAssertEqual(view.miniAppTitle, MiniAppSDKConstants.miniAppRootFolderName)

view.miniAppHandler.title = "MiniApp (Test)"
XCTAssertEqual(view.miniAppTitle, "MiniApp (Test)")
Expand Down

0 comments on commit b6e0d36

Please sign in to comment.