-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SwiftUI View to SnapshotTests (#34)
* Adds SwiftUI View with snapshot tests for iOS 13 and 14 * Sets tabWidth and indentWidth for Example Project for equal indentation rules when the developer's Xcode configuration is different from the default. * Adds weak framework SwiftUI to Other Linker Flags to make SwiftUI not required for < iOS 13 Tests. See https://stackoverflow.com/a/57907940
- Loading branch information
Showing
9 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Example/AccessibilitySnapshot/SwiftUIView+EmbedInHostingController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Copyright 2021 Square Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import SwiftUI | ||
import UIKit | ||
|
||
@available(iOS 13.0, *) | ||
extension View { | ||
|
||
// This method should be removed once we support snapshotting native SwiftUI views. | ||
// See cashapp/AccessibilitySnapshot#37. | ||
func embedInHostingController() -> UIViewController { | ||
return UIHostingController(rootView: self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// Copyright 2020 Square Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@available(iOS 13.0, *) | ||
fileprivate struct Circle: View { | ||
var body: some View { | ||
Rectangle() | ||
.foregroundColor(Color(UIColor.lightGray)) | ||
.frame(width: 30, height: 30) | ||
.cornerRadius(15) | ||
} | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
struct SwiftUIView: View { | ||
var body: some View { | ||
VStack(spacing: 30) { | ||
// View with nothing. | ||
Circle() | ||
.accessibility(label: Text("")) | ||
.accessibility(value: Text("")) | ||
.accessibility(hint: Text("")) | ||
|
||
// View with label. | ||
Circle() | ||
.accessibility(label: Text("Label")) | ||
.accessibility(value: Text("")) | ||
.accessibility(hint: Text("")) | ||
|
||
// View with value. | ||
Circle() | ||
.accessibility(label: Text("")) | ||
.accessibility(value: Text("Value")) | ||
.accessibility(hint: Text("")) | ||
|
||
// View with hint. | ||
Circle() | ||
.accessibility(label: Text("")) | ||
.accessibility(value: Text("")) | ||
.accessibility(hint: Text("Hint")) | ||
|
||
// View with label and value. | ||
Circle() | ||
.accessibility(label: Text("Label")) | ||
.accessibility(value: Text("Value")) | ||
.accessibility(hint: Text("")) | ||
|
||
// View with label and hint. | ||
Circle() | ||
.accessibility(label: Text("Label")) | ||
.accessibility(value: Text("")) | ||
.accessibility(hint: Text("Hint")) | ||
|
||
// View with value and hint. | ||
Circle() | ||
.accessibility(label: Text("")) | ||
.accessibility(value: Text("Value")) | ||
.accessibility(hint: Text("Hint")) | ||
|
||
// View with label, value, and hint. | ||
Circle() | ||
.accessibility(label: Text("Label")) | ||
.accessibility(value: Text("Value")) | ||
.accessibility(hint: Text("Hint")) | ||
|
||
Spacer() | ||
} | ||
} | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
struct SwiftUIView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SwiftUIView() | ||
.previewLayout(.sizeThatFits) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Example/AccessibilitySnapshot/SwiftUIViewWithScrollView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Copyright 2020 Square Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// A SwiftUI View inside a ScrollView will produce no accessibility elements for iOS 14.0 and 14.1, for more | ||
/// information see cashapp/AccessibilitySnapshot#33. This seems to be a SwiftUI bug which was resolved in iOS 14.2. | ||
@available(iOS 13.0, *) | ||
struct SwiftUIViewWithScrollView: View { | ||
var body: some View { | ||
ScrollView { | ||
SwiftUIView() | ||
} | ||
} | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
struct SwiftUIViewWithScrollView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SwiftUIViewWithScrollView() | ||
.previewLayout(.sizeThatFits) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+159 KB
...shots__/SnapshotTestingTests/testSimpleSwiftUIConfiguration.375x812-13-3-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+165 KB
...shots__/SnapshotTestingTests/testSimpleSwiftUIConfiguration.390x844-14-2-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+159 KB
...otTestingTests/testSimpleSwiftUIWithScrollViewConfiguration.375x812-13-3-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+165 KB
...otTestingTests/testSimpleSwiftUIWithScrollViewConfiguration.390x844-14-2-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.