Skip to content

Commit 3befec7

Browse files
authored
Merge pull request #66 from jevonmao/develop
Merge 'develop' into 'main'
2 parents 023111e + 49a12a3 commit 3befec7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+107
-80
lines changed

.github/documentation_coverage.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
percentage=$(jazzy --module PermissionsSwiftUI --swift-build-tool xcodebuild --build-tool-arguments -scheme,PermissionsSwiftUI,-sdk,iphoneos --author 'Jevon Mao' --author_url https://jingwen-mao.mit-license.org/ | tail -4 | head -n 1 | cut -d " " -f1)
4+
if test "${percentage%?}" == "100"
5+
then
6+
echo "Documentation coverage 100%, test passed."
7+
else
8+
echo "Documentation coverage is $percentage%, which is below 100%, test failed."
9+
exit 1
10+
fi

.github/workflows/swift.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@ jobs:
4343

4444
- name: Format Swift code
4545
run: swiftformat --verbose . --swiftversion 5.2
46+
Documentation_coverage:
47+
name: Documentation coverage
48+
runs-on: macos-latest
49+
steps:
50+
- name: Checkout repo
51+
uses: actions/checkout@v2
52+
- name: Install Jazzy
53+
run: sudo gem install jazzy
54+
- name: Ready shell script
55+
run: chmod +x .github/documentation_coverage.sh
56+
- name: Execute shell script
57+
run: .github/documentation_coverage.sh

Sources/PermissionsSwiftUI/Modifiers/ViewProtocols/CustomizableView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ public protocol CustomizableView: View {
1818
var store: PermissionStore {get}
1919
///A schema storage object that is implemented by views
2020
var schemaStore: PermissionSchemaStore {get}
21+
///Concrete type should be constraint to of type View
2122
associatedtype ViewType
23+
///Binding variable to control the presentable of view
2224
var showing: Binding<Bool> {get set}
25+
///The layer of passed in view below PermisisonsSwiftUI's view
2326
var bodyView: ViewType {get set}
2427
}

Tests/PermissionsSwiftUITests/PermissionsSwiftUITests.swift

Lines changed: 82 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,33 @@ import HealthKit
66

77
fileprivate let referenceSize = UIScreen.main.bounds.size
88
#warning("Write unit tests")
9-
#warning("Documentation and migration guide")
109
final class PermissionsSwiftUITests: XCTestCase {
1110
let placeholderText = """
1211
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec congue metus.
1312
"""
1413
func testPermissionStoreCurrentPermissionGet(){
15-
let store = PermissionComponentsStore()
14+
var store = PermissionComponentsStore()
1615
if #available(iOS 14.5, *) {
17-
let trackingPermission = store.getPermissionComponent(for: .tracking)
16+
let trackingPermission = store.getPermissionComponent(for: .tracking, modify: {_ in })
1817
XCTAssertEqual(trackingPermission, JMPermission(
1918
imageIcon: AnyView(Image(systemName: "person.circle.fill")),
2019
title: "Tracking",
2120
description: "Allow to track your data", authorized: false
2221
))
2322
}
24-
let photoPermission = store.getPermissionComponent(for: .photo)
25-
let cameraPermission = store.getPermissionComponent(for: .camera)
26-
let locationPermission = store.getPermissionComponent(for: .location)
27-
let reminderPermission = store.getPermissionComponent(for: .reminders)
28-
let speechPermission = store.getPermissionComponent(for: .speech)
29-
let bluetoothPermission = store.getPermissionComponent(for: .bluetooth)
30-
let calendarPermission = store.getPermissionComponent(for: .calendar)
31-
let contactsPermission = store.getPermissionComponent(for: .contacts)
32-
let locationAlwaysPermission = store.getPermissionComponent(for: .locationAlways)
33-
let microphonePermission = store.getPermissionComponent(for: .microphone)
34-
let notificationPermission = store.getPermissionComponent(for: .notification)
35-
let healthPermission = store.getPermissionComponent(for: .health(categories: nil))
36-
let musicPermission = store.getPermissionComponent(for: .music)
23+
let photoPermission = store.getPermissionComponent(for: .photo, modify: {_ in })
24+
let cameraPermission = store.getPermissionComponent(for: .camera, modify: {_ in })
25+
let locationPermission = store.getPermissionComponent(for: .location, modify: {_ in })
26+
let reminderPermission = store.getPermissionComponent(for: .reminders, modify: {_ in })
27+
let speechPermission = store.getPermissionComponent(for: .speech, modify: {_ in })
28+
let bluetoothPermission = store.getPermissionComponent(for: .bluetooth, modify: {_ in })
29+
let calendarPermission = store.getPermissionComponent(for: .calendar, modify: {_ in })
30+
let contactsPermission = store.getPermissionComponent(for: .contacts, modify: {_ in })
31+
let locationAlwaysPermission = store.getPermissionComponent(for: .locationAlways, modify: {_ in })
32+
let microphonePermission = store.getPermissionComponent(for: .microphone, modify: {_ in })
33+
let notificationPermission = store.getPermissionComponent(for: .notification, modify: {_ in })
34+
let healthPermission = store.getPermissionComponent(for: .health(categories: nil), modify: {_ in })
35+
let musicPermission = store.getPermissionComponent(for: .music, modify: {_ in })
3736
XCTAssertEqual(photoPermission, JMPermission(
3837
imageIcon: AnyView(Image(systemName: "photo")),
3938
title: "Photo Library",
@@ -315,61 +314,65 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec congue metus.
315314
// XCTAssert(authorized)
316315
// }
317316
// }
318-
// func testModalViewSnapshot14_0(){
319-
// if #available(iOS 14.5, *) {}
320-
// else{
321-
// store.updateStore(property: {$0.permissions=$1}, value: PermissionType.allCases)
322-
// store.updateStore(property: {$0.autoCheckModalAuth=$1}, value: false)
323-
// let view = ModalView(showModal: .constant(true))
324-
// assertSnapshot(matching: view.referenceFrame(), as: .image)
325-
// }
326-
// }
327-
// func testModalViewSnapshot14_5(){
328-
// if #available(iOS 14.5, *) {
329-
// let view = ModalView(showModal: .constant(true))
330-
// store.updateStore(property: {$0.permissions=$1}, value: PermissionType.allCases)
331-
// assertSnapshot(matching: view.referenceFrame(), as: .image)
332-
// }
333-
// }
334-
//
335-
// func testCustomizeHeaderSnapshot(){
336-
// let newHeader = "Permissions Request"
337-
// let view = ModalView(showModal: .constant(true))
338-
// .referenceFrame()
339-
// .changeHeaderTo(newHeader)
340-
// .changeHeaderDescriptionTo(placeholderText)
341-
// .changeBottomDescriptionTo(placeholderText)
342-
// XCTAssertEqual(newHeader, store.mainTexts.headerText)
343-
// XCTAssertEqual(placeholderText, store.mainTexts.headerDescription)
344-
// XCTAssertEqual(placeholderText, store.mainTexts.bottomDescription)
345-
// assertSnapshot(matching: view, as: .image)
346-
//
347-
// }
348-
// func testPermissionCell(){
349-
// for permission in PermissionType.allCases{
350-
// let title = permission.currentPermission.title
351-
// let views = getPermissionView(for: permission)
352-
// let testingPermission = JMPermission(imageIcon: AnyView(Image(systemName: "gear")), title: "Testing \(title)", description: placeholderText, authorized: false)
353-
// XCTAssertEqual(testingPermission, permission.currentPermission)
354-
// for i in views{
355-
// assertSnapshot(matching: i, as: .image)
356-
// }
357-
// }
358-
// }
359-
// func getPermissionView(for permission: PermissionType) -> [AnyView]{
360-
// let title = permission.currentPermission.title
361-
// switch permission {
362-
// default:
363-
// let views:[AnyView] = AllowButtonStatus.allCases.map{
364-
// let view = PermissionSectionCell(permission: permission, allowButtonStatus: $0, showModal: .constant(true), isAlert: false)
365-
// .setPermissionComponent(for: permission, image: AnyView(Image(systemName: "gear")), title: "Testing \(title)", description: placeholderText)
366-
// .referenceFrameCell()
367-
// return AnyView(view)
368-
// }
369-
// return views
370-
//
371-
// }
372-
// }
317+
func testModalViewSnapshot14_0(){
318+
if #available(iOS 14.5, *) {}
319+
else{
320+
let store = PermissionStore()
321+
store.permissions = PermissionType.allCases
322+
store.configStore.autoCheckAuth = false
323+
let view = ModalView(showModal: .constant(true)).withEnvironmentObjects(store: store, permissionStyle: .modal)
324+
assertSnapshot(matching: view.referenceFrame(count: store.permissions.count), as: .image)
325+
}
326+
}
327+
func testModalViewSnapshot14_5(){
328+
if #available(iOS 14.5, *) {
329+
let store = PermissionStore()
330+
store.permissions = PermissionType.allCases
331+
store.configStore.autoCheckAuth = false
332+
let view = ModalView(showModal: .constant(true)).withEnvironmentObjects(store: store, permissionStyle: .modal)
333+
assertSnapshot(matching: view.referenceFrame(count: store.permissions.count), as: .image)
334+
}
335+
}
336+
337+
func testCustomizeHeaderSnapshot(){
338+
let newHeader = "Permissions Request"
339+
let store = PermissionStore()
340+
_ = ModalMainView(for: Color.red, showing: .constant(true), store: store)
341+
.changeHeaderTo(newHeader)
342+
.changeHeaderDescriptionTo(placeholderText)
343+
.changeBottomDescriptionTo(placeholderText)
344+
.referenceFrame(count: 0)
345+
346+
XCTAssertEqual(newHeader, store.configStore.mainTexts.headerText)
347+
XCTAssertEqual(placeholderText, store.configStore.mainTexts.headerDescription)
348+
XCTAssertEqual(placeholderText, store.configStore.mainTexts.bottomDescription)
349+
let view = ModalView(showModal: .constant(true)).withEnvironmentObjects(store: store, permissionStyle: .modal)
350+
assertSnapshot(matching: view, as: .image)
351+
352+
}
353+
func testPermissionCell(){
354+
for permission in PermissionType.allCases{
355+
let currentPermission = PermissionStore().permissionComponentsStore.getPermissionComponent(for: permission, modify: {_ in})
356+
let title = currentPermission.title
357+
let views = getPermissionView(for: permission)
358+
for i in views{
359+
assertSnapshot(matching: i, as: .image)
360+
}
361+
}
362+
}
363+
func getPermissionView(for permission: PermissionType) -> [AnyView]{
364+
switch permission {
365+
default:
366+
let views:[AnyView] = AllowButtonStatus.allCases.map{
367+
let view = PermissionSectionCell(permission: permission, allowButtonStatus: $0, showing: .constant(true))
368+
.withEnvironmentObjects(store: PermissionStore(), permissionStyle: .modal)
369+
.referenceFrameCell()
370+
return AnyView(view)
371+
}
372+
return views
373+
374+
}
375+
}
373376
// func testStateChangeClosures(){
374377
// XCTAssertNil(store.onAppear)
375378
// XCTAssertNil(store.onDisappear)
@@ -555,15 +558,14 @@ struct testViewGreenBG:View{
555558
}
556559
}
557560
}
558-
//private extension SwiftUI.View {
559-
// func referenceFrame() -> some View {
560-
// let count = store.permissions.count
561-
// return self.frame(width: referenceSize.width, height: referenceSize.height+CGFloat(count*60))
562-
// }
563-
// func referenceFrameCell() -> some View{
564-
// return self.frame(width: referenceSize.width, height: 70)
565-
// }
566-
//}
561+
private extension SwiftUI.View {
562+
func referenceFrame(count: Int) -> some View {
563+
return self.frame(width: referenceSize.width, height: referenceSize.height+CGFloat(count*60))
564+
}
565+
func referenceFrameCell() -> some View{
566+
return self.frame(width: referenceSize.width, height: 70)
567+
}
568+
}
567569

568570
public extension UIDevice {
569571
enum DeviceType{

0 commit comments

Comments
 (0)