@@ -6,34 +6,33 @@ import HealthKit
6
6
7
7
fileprivate let referenceSize = UIScreen . main. bounds. size
8
8
#warning("Write unit tests")
9
- #warning("Documentation and migration guide")
10
9
final class PermissionsSwiftUITests : XCTestCase {
11
10
let placeholderText = """
12
11
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec congue metus.
13
12
"""
14
13
func testPermissionStoreCurrentPermissionGet( ) {
15
- let store = PermissionComponentsStore ( )
14
+ var store = PermissionComponentsStore ( )
16
15
if #available( iOS 14 . 5 , * ) {
17
- let trackingPermission = store. getPermissionComponent ( for: . tracking)
16
+ let trackingPermission = store. getPermissionComponent ( for: . tracking, modify : { _ in } )
18
17
XCTAssertEqual ( trackingPermission, JMPermission (
19
18
imageIcon: AnyView ( Image ( systemName: " person.circle.fill " ) ) ,
20
19
title: " Tracking " ,
21
20
description: " Allow to track your data " , authorized: false
22
21
) )
23
22
}
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 } )
37
36
XCTAssertEqual ( photoPermission, JMPermission (
38
37
imageIcon: AnyView ( Image ( systemName: " photo " ) ) ,
39
38
title: " Photo Library " ,
@@ -315,61 +314,65 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec congue metus.
315
314
// XCTAssert(authorized)
316
315
// }
317
316
// }
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
+ }
373
376
// func testStateChangeClosures(){
374
377
// XCTAssertNil(store.onAppear)
375
378
// XCTAssertNil(store.onDisappear)
@@ -555,15 +558,14 @@ struct testViewGreenBG:View{
555
558
}
556
559
}
557
560
}
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
+ }
567
569
568
570
public extension UIDevice {
569
571
enum DeviceType {
0 commit comments