Skip to content

Commit

Permalink
Merge pull request #56 from chrs1885/feature/53-plugin-architecture
Browse files Browse the repository at this point in the history
Feature/53 plugin architecture
  • Loading branch information
chrs1885 authored May 31, 2021
2 parents c097808 + 90ff0f1 commit 7ec3612
Show file tree
Hide file tree
Showing 54 changed files with 3,409 additions and 3,456 deletions.
22 changes: 1 addition & 21 deletions Documentation/Reference/enums/CapableFeature.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum CapableFeature: String, CaseIterable

> Restricts access to certain features of a single app to keep the user focused.

### `hearingDevice`
### `hearingDevicePairedEar`

> Pairing status of a hearing aid.

Expand Down Expand Up @@ -128,23 +128,3 @@ case voiceOver
```

> The screen reader available on Apple platforms.

## Methods
### `keys(forFeatures:)`

```swift
public static func keys(forFeatures features: [CapableFeature]) -> [String]
```

> Iterates through a given list of feature types and returns an array containing the feature names as strings.
>
> - Parameters:
> - features: An array containing the feature types of interest.
>
> - Returns: An array containing the feature names as strings

#### Parameters

| Name | Description |
| ---- | ----------- |
| features | An array containing the feature types of interest. |
102 changes: 52 additions & 50 deletions Example/Example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 4be5f3d8c8dceba64f29d52556419c2c3a677413

COCOAPODS: 1.9.3
COCOAPODS: 1.10.1
2,963 changes: 1,560 additions & 1,403 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

13 changes: 1 addition & 12 deletions Example/Source/FeatureOverviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@

import Capable
import UIKit

#if os(iOS)

// import Answers
// import AppCenter
// import AppCenterAnalytics
// import Fabric
// import Firebase

#endif
// import Firebase

class FeatureOverviewController: UITableViewController {
var alert: UIAlertController?
Expand Down Expand Up @@ -53,9 +44,7 @@ class FeatureOverviewController: UITableViewController {
#if os(iOS)
if let statusMap = self.capable?.statusMap {
let eventName = "Capable features received"
// MSAnalytics.trackEvent(eventName, withProperties: statusMap)
// Analytics.logEvent(eventName, parameters: statusMap)
// Answers.logCustomEvent(withName: eventName, customAttributes: statusMap)
}
#endif
}
Expand Down
68 changes: 20 additions & 48 deletions Example/Tests/Features/CapableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,28 @@

@testable import Capable
import Nimble
import os.log
import Quick

class CapableTests: QuickSpec {
override func spec() {
describe("The Capable class") {
var featureStatusesProviderMock: FeatureStatusesProviderMock?

beforeEach {
featureStatusesProviderMock = FeatureStatusesProviderMock()
}
var sut: Capable!

context("after initialization with features") {
context("when providing specific features") {
var sut: Capable?
var testedFeatures: [CapableFeature]?
var testedFeatures: [CapableFeature]!

beforeEach {
testedFeatures = [.reduceMotion, .voiceOver]
sut = Capable(withFeatures: testedFeatures!)
sut = Capable(withFeatures: testedFeatures)
}

it("creates a Capable instance") {
expect(sut!).to(beAnInstanceOf(Capable.self))
}

it("initializes its feature statuses provider correctly") {
expect(sut!.featureStatusesProvider).to(beAnInstanceOf(FeatureStatusesProvider.self))
}

it("initializes its statuses module correctly") {
expect(sut!.statusesModule).to(beAnInstanceOf(FeatureStatuses.self))
// swiftlint:disable force_cast
let featureStatuses = sut!.statusesModule as! FeatureStatuses
// swiftlint:enable force_cast
expect(featureStatuses.features).to(equal(sut!.features))
expect(featureStatuses.featureStatusesProvider).to(be(sut!.featureStatusesProvider))
expect(sut).to(beAnInstanceOf(Capable.self))
}

it("initializes its notifications module correctly") {
expect(sut!.notificationsModule).to(beAnInstanceOf(FeatureNotifications.self))
// swiftlint:disable force_cast
let featureNotifications = sut!.notificationsModule as! FeatureNotifications
// swiftlint:enable force_cast

expect(featureNotifications.featureStatusesProvider).to(be(sut!.featureStatusesProvider))
expect(featureNotifications.targetNotificationCenter).to(equal(NotificationCenter.default))

#if os(OSX)
expect(featureNotifications.systemNotificationCenter).to(equal(NSWorkspace.shared.notificationCenter))
#else
expect(featureNotifications.systemNotificationCenter).to(equal(NotificationCenter.default))
#endif
it("initializes its feature provider correctly") {
expect(sut.featureStatusProvider).to(beAnInstanceOf(FeatureStatusProvider.self))
}

it("sets the features property correctly") {
Expand All @@ -70,8 +39,6 @@
}

context("when providing no parameters") {
var sut: Capable?

beforeEach {
sut = Capable()
}
Expand All @@ -82,31 +49,36 @@
}

context("after initialization") {
var sut: Capable?
var testStatuses: FeatureStatusesMock?
var featureStatusProviderMock: FeatureStatusProviderMock!

beforeEach {
testStatuses = FeatureStatusesMock()
sut = Capable(withFeatures: [], featureStatusesProvider: featureStatusesProviderMock!, statusesModule: testStatuses!, notificationModule: FeatureNotifications(featureStatusesProvider: featureStatusesProviderMock!))
featureStatusProviderMock = FeatureStatusProviderMock()
sut = Capable(withFeatures: CapableFeature.allCases, featureStatusProvider: featureStatusProviderMock)
}

context("when calling statusMap") {
let testStatusMap = ["foo": "bar"]

beforeEach {
_ = sut!.statusMap
featureStatusProviderMock.statusMap = testStatusMap
_ = sut.statusMap
}

it("requests the status map from the statuses module") {
expect(testStatuses!.didCallStatusMap).to(beTrue())
expect(sut.statusMap).to(equal(testStatusMap))
}
}

context("when calling isFeatureEnabled") {
let testFeature = CapableFeature.voiceOver

beforeEach {
_ = sut!.isFeatureEnabled(feature: .voiceOver)
_ = sut.isFeatureEnabled(feature: testFeature)
}

it("requests the status map from the statuses module") {
expect(featureStatusesProviderMock!.didCallIsFeatureEnabled).to(beTrue())
it("requests the feature status from the feature provider") {
expect(featureStatusProviderMock!.didCallIsFeatureEnabled).to(beTrue())
expect(featureStatusProviderMock!.requestedFeature).to(equal(testFeature))
}
}
}
Expand Down
Loading

0 comments on commit 7ec3612

Please sign in to comment.