-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 09964ba
Showing
43 changed files
with
1,989 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc | ||
Package.resolved |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
556 changes: 556 additions & 0 deletions
556
Examples/PreviewSnapshotsTestApp.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Examples/PreviewSnapshotsTestApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...eviewSnapshotsTestApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
11 changes: 11 additions & 0 deletions
11
Examples/PreviewSnapshotsTestApp/Assets.xcassets/AccentColor.colorset/Contents.json
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,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Examples/PreviewSnapshotsTestApp/Assets.xcassets/AppIcon.appiconset/Contents.json
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,13 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Examples/PreviewSnapshotsTestApp/Assets.xcassets/Contents.json
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
Examples/PreviewSnapshotsTestApp/ObservableObjectView.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,78 @@ | ||
// Copyright 2022 DoorDash, 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 PreviewSnapshots | ||
import SwiftUI | ||
|
||
final class ObservableObjectViewModel: ObservableObject { | ||
@Published var input = "" | ||
@Published var errorMessage: String? | ||
|
||
func validate() { | ||
if input.count < 5 { | ||
errorMessage = "Message Too Short" | ||
} else { | ||
errorMessage = nil | ||
} | ||
} | ||
} | ||
|
||
struct ObservableObjectView: View { | ||
@ObservedObject var viewModel: ObservableObjectViewModel | ||
|
||
var body: some View { | ||
VStack(spacing: 8) { | ||
TextField("Input", text: $viewModel.input) | ||
|
||
if let errorMessage = viewModel.errorMessage { | ||
Text(errorMessage) | ||
.font(.caption) | ||
.foregroundColor(.red) | ||
} | ||
|
||
Button("Submit") { | ||
viewModel.validate() | ||
} | ||
} | ||
.padding(8) | ||
} | ||
} | ||
|
||
struct ObservableObjectView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
snapshots.previews.previewLayout(.sizeThatFits) | ||
} | ||
|
||
static var snapshots: PreviewSnapshots<ObservableObjectViewModel> { | ||
let empty = ObservableObjectViewModel() | ||
|
||
let tooShort = ObservableObjectViewModel() | ||
tooShort.input = "Hi" | ||
tooShort.validate() | ||
|
||
let valid = ObservableObjectViewModel() | ||
valid.input = "Hello World" | ||
valid.validate() | ||
|
||
return PreviewSnapshots( | ||
configurations: [ | ||
.init(name: "Empty", state: empty), | ||
.init(name: "Too Short", state: tooShort), | ||
.init(name: "Valid", state: valid), | ||
], | ||
configure: { | ||
ObservableObjectView(viewModel: $0) | ||
} | ||
) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Examples/PreviewSnapshotsTestApp/PreviewSnapshotsTestApp.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,38 @@ | ||
// Copyright 2022 DoorDash, 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 | ||
|
||
@main | ||
struct PreviewSnapshotsTestApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
NavigationView { | ||
List { | ||
NavigationLink("Simple View") { | ||
SimpleView(message: "Hello World!") | ||
} | ||
|
||
NavigationLink("PreviewState View") { | ||
PreviewStateView(title: "Hello", subtitle: "Word", message: "Hello World") | ||
} | ||
|
||
NavigationLink("ObservableObject View") { | ||
ObservableObjectView(viewModel: .init()) | ||
} | ||
} | ||
.navigationTitle("Test Views") | ||
} | ||
} | ||
} | ||
} |
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,68 @@ | ||
// Copyright 2022 DoorDash, 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 PreviewSnapshots | ||
import SwiftUI | ||
|
||
struct PreviewStateView: View { | ||
let title: String | ||
let subtitle: String | ||
let message: String | ||
|
||
var body: some View { | ||
VStack(spacing: 24) { | ||
VStack(spacing: 8) { | ||
Text(title) | ||
.font(.title) | ||
|
||
Text(subtitle) | ||
.font(.subheadline) | ||
} | ||
|
||
Text(message) | ||
.font(.body) | ||
} | ||
.multilineTextAlignment(.center) | ||
.padding(8) | ||
} | ||
} | ||
|
||
struct PreviewStateView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
snapshots.previews.previewLayout(.sizeThatFits) | ||
} | ||
|
||
static var snapshots: PreviewSnapshots<PreviewState> { | ||
PreviewSnapshots( | ||
states: [ | ||
.init(name: "Short", title: "Hello", subtitle: "PreviewSnapshots", message: "This is a test"), | ||
.init( | ||
name: "Long", | ||
title: "Hello PreviewSnapshots", | ||
subtitle: "Welcome to PreviewSnapshots", | ||
message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." | ||
) | ||
], | ||
configure: { | ||
PreviewStateView(title: $0.title, subtitle: $0.subtitle, message: $0.message) | ||
} | ||
) | ||
} | ||
|
||
struct PreviewState: NamedPreviewState { | ||
let name: String | ||
let title: String | ||
let subtitle: String | ||
let message: String | ||
} | ||
} |
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,48 @@ | ||
// Copyright 2022 DoorDash, 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 PreviewSnapshots | ||
import SwiftUI | ||
|
||
struct SimpleView: View { | ||
let message: String | ||
|
||
var body: some View { | ||
VStack(spacing: 8) { | ||
Image(systemName: "globe") | ||
.imageScale(.large) | ||
.foregroundColor(.accentColor) | ||
|
||
Text(message) | ||
} | ||
.padding(8) | ||
} | ||
} | ||
|
||
struct SimpleView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
snapshots.previews.previewLayout(.sizeThatFits) | ||
} | ||
|
||
static var snapshots: PreviewSnapshots<String> { | ||
PreviewSnapshots( | ||
configurations: [ | ||
.init(name: "Short Message", state: "Hello World"), | ||
.init(name: "Long Message", state: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."), | ||
], | ||
configure: { | ||
SimpleView(message: $0) | ||
} | ||
) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
Examples/PreviewSnapshotsTestAppTests/PreviewSnapshotsTestAppTests.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,56 @@ | ||
// Copyright 2022 DoorDash, 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 PreviewSnapshotsTesting | ||
import SnapshotTesting | ||
import SwiftUI | ||
import XCTest | ||
|
||
@testable import PreviewSnapshotsTestApp | ||
|
||
final class PreviewSnapshotsTestAppTests: XCTestCase { | ||
func test_simpleViewSnapshots() { | ||
SimpleView_Previews.snapshots.assertSnapshots(as: .testStrategy()) | ||
} | ||
|
||
func test_previewStateViewSnapshots() { | ||
PreviewStateView_Previews.snapshots.assertSnapshots(as: .testStrategy()) | ||
} | ||
|
||
func test_observableObjectSnapshots() { | ||
ObservableObjectView_Previews.snapshots.assertSnapshots(as: .testStrategy()) | ||
} | ||
|
||
func test_previewStateLightAndDark() { | ||
PreviewStateView_Previews.snapshots | ||
.assertSnapshots(as: [ | ||
"Light": .testStrategy(userInterfaceStyle: .light), | ||
"Dark": .testStrategy(userInterfaceStyle: .dark), | ||
]) | ||
} | ||
} | ||
|
||
extension Snapshotting where Value: SwiftUI.View, Format == UIImage { | ||
/// Shared image test strategy | ||
static func testStrategy(userInterfaceStyle: UIUserInterfaceStyle = .light) -> Self { | ||
let traits = UITraitCollection(traitsFrom: [ | ||
UITraitCollection(displayScale: 1), | ||
UITraitCollection(userInterfaceStyle: userInterfaceStyle), | ||
]) | ||
|
||
return .image( | ||
layout: .fixed(width: 400, height: 400), | ||
traits: traits | ||
) | ||
} | ||
} |
Binary file added
BIN
+6.3 KB
...apshots__/PreviewSnapshotsTestAppTests/test_observableObjectSnapshots.Empty.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
+8.03 KB
...ots__/PreviewSnapshotsTestAppTests/test_observableObjectSnapshots.Too-Short.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
+7.59 KB
...apshots__/PreviewSnapshotsTestAppTests/test_observableObjectSnapshots.Valid.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
+27.3 KB
...hots__/PreviewSnapshotsTestAppTests/test_previewStateLightAndDark.Long-Dark.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
+26.4 KB
...ots__/PreviewSnapshotsTestAppTests/test_previewStateLightAndDark.Long-Light.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
+11.4 KB
...ots__/PreviewSnapshotsTestAppTests/test_previewStateLightAndDark.Short-Dark.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
+10.5 KB
...ts__/PreviewSnapshotsTestAppTests/test_previewStateLightAndDark.Short-Light.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
+26.4 KB
...napshots__/PreviewSnapshotsTestAppTests/test_previewStateViewSnapshots.Long.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
+10.5 KB
...apshots__/PreviewSnapshotsTestAppTests/test_previewStateViewSnapshots.Short.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
+19.6 KB
...pshots__/PreviewSnapshotsTestAppTests/test_simpleViewSnapshots.Long-Message.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
+7.22 KB
...shots__/PreviewSnapshotsTestAppTests/test_simpleViewSnapshots.Short-Message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.