Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test in light and dark mode #265

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -22,3 +22,4 @@ build
.swiftpm

.DS_Store
.build/
2 changes: 2 additions & 0 deletions Bootstrap/Bootstrap.xcodeproj/project.pbxproj
Expand Up @@ -19,6 +19,7 @@
5EFDC7711F8699AA001453EC /* DynamicSizeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EFDC76E1F8699AA001453EC /* DynamicSizeTests.swift */; };
5EFDC7721F8699AA001453EC /* DynamicTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EFDC76F1F8699AA001453EC /* DynamicTypeTests.swift */; };
69BE287EA35A14E2787AC4AF /* Pods_Bootstrap_BootstrapTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CF2E7C50C1B84B73173ED6F7 /* Pods_Bootstrap_BootstrapTests.framework */; };
C31D2DD929D73AFE002BD84C /* BootstrapCustomFolderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EFDC7761F8699F9001453EC /* BootstrapCustomFolderTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -358,6 +359,7 @@
files = (
5EFDC7701F8699AA001453EC /* WithoutQuickTests.swift in Sources */,
5EFDC7711F8699AA001453EC /* DynamicSizeTests.swift in Sources */,
C31D2DD929D73AFE002BD84C /* BootstrapCustomFolderTests.swift in Sources */,
5EFDC7611F8698B4001453EC /* BootstrapTests.swift in Sources */,
5EFDC7721F8699AA001453EC /* DynamicTypeTests.swift in Sources */,
);
Expand Down
8 changes: 7 additions & 1 deletion Bootstrap/Bootstrap/DynamicTypeView.swift
Expand Up @@ -8,7 +8,13 @@ public final class DynamicTypeView: UIView {
label = UILabel()
super.init(frame: frame)

backgroundColor = .white
backgroundColor = UIColor { traits -> UIColor in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don´t need the else here

backgroundColor = UIColor { traits -> UIColor in
    if traits.userInterfaceStyle == .dark {
        return .lightGray
    }
    return .white
}

if traits.userInterfaceStyle == .dark {
return .lightGray
} else {
return .white
}
}
translatesAutoresizingMaskIntoConstraints = false

label.font = .preferredFont(forTextStyle: .body)
Expand Down
Expand Up @@ -12,19 +12,31 @@ final class BootstrapCustomFormatTests: QuickSpec {
beforeEach {
setNimbleTestFolder("CustomFolder")
view = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 44, height: 44)))
view.backgroundColor = .blue
view.backgroundColor = UIColor { traits -> UIColor in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about the else

if traits.userInterfaceStyle == .dark {
return .brown
} else {
return .blue
}
}
}

it("fails to find the snapshots due to the custom folder") {
expect(view).notTo(haveValidSnapshot(named: "something custom"))
expect(view).notTo(haveValidSnapshot(named: "something custom"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated?

}

it("finds the snapshots using a custom images directory") {
expect(view).to(haveValidSnapshot())
expect(view).to(recordSnapshot())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftovers?

}

it("finds device agnostic snapshots with custom images directory") {
expect(view).to(haveValidDeviceAgnosticSnapshot())
expect(view).to(recordDeviceAgnosticSnapshot())
}

it("find the snapshot using a custom image directory for light and dark mode") {
expect(view).to(recordSnapshot(userInterfaceStyle: .light))
expect(view).to(recordSnapshot(userInterfaceStyle: .dark))
Comment on lines +34 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess all of those also should be haveValid and not record

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get this test to run properly, we still need to record images for this test, that is why I left it like that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should stick to AAA (A.K.A Arrange, Act, and Assert) principles, and as we expect two different outputs , should be two isolated unit tests

}
}
}
Expand Down
11 changes: 9 additions & 2 deletions Bootstrap/BootstrapTests/BootstrapTests.swift
Expand Up @@ -16,11 +16,18 @@ final class BootstrapTests: QuickSpec {
setNimbleTolerance(0.1)
setNimbleTestFolder("tests")
view = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 44, height: 44)))
view.backgroundColor = .blue
view.backgroundColor = UIColor { traits -> UIColor in
if traits.userInterfaceStyle == .dark {
return .brown
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about the else statement

return .blue
}
}
}

it("has a valid snapshot") {
expect(view).to(haveValidSnapshot())
expect(view).to(haveValidSnapshot(userInterfaceStyle: .light))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about the expectations

expect(view).to(haveValidSnapshot(userInterfaceStyle: .dark))
expect(view).to(haveValidSnapshot(named: "something custom"))
}

Expand Down
16 changes: 15 additions & 1 deletion Bootstrap/BootstrapTests/DynamicSizeTests.swift
Expand Up @@ -27,14 +27,28 @@ final class DynamicSizeTests: QuickSpec {

beforeEach {
view = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
view.backgroundColor = .blue
view.backgroundColor = UIColor { traits -> UIColor in
if traits.userInterfaceStyle == .dark {
return .brown
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about the else statement

return .blue
}
}
}

it("has a valid snapshot to all sizes") {
expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes))
// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes))
}

it("has a valid snapshot to all sizes in light and dark mode") {
expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes, userInterfaceStyle: .light))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about expectations

expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes, userInterfaceStyle: .dark))
// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes, userInterfaceStyle: .light))
// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes, userInterfaceStyle: .dark))
}


it("has a valid snapshot to all sizes with identifier") {
// expect(view).to(recordDynamicSizeSnapshot(identifier: "bootstrap", sizes: sizes))
expect(view).to(haveValidDynamicSizeSnapshot(identifier: "bootstrap", sizes: sizes))
Expand Down
20 changes: 20 additions & 0 deletions Bootstrap/BootstrapTests/DynamicTypeTests.swift
Expand Up @@ -81,6 +81,26 @@ final class DynamicTypeTests: QuickSpec {
identifier: "bootstrap"))
}

it("has a valid snapshot with identifier in light and dark mode") {
// expect(view).to(recordDynamicTypeSnapshot(identifier: "bootstrap", userInterfaceStyle: .light))
// expect(view).to(recordDynamicTypeSnapshot(identifier: "bootstrap", userInterfaceStyle: .dark))
expect(view).to(haveValidDynamicTypeSnapshot(identifier: "bootstrap", userInterfaceStyle: .light))
expect(view).to(haveValidDynamicTypeSnapshot(identifier: "bootstrap", userInterfaceStyle: .dark))

// expect(view).to(recordDynamicTypeSnapshot(named: "something custom with model and OS",
// identifier: "bootstrap",
// userInterfaceStyle: .light))
// expect(view).to(recordDynamicTypeSnapshot(named: "something custom with model and OS",
// identifier: "bootstrap",
// userInterfaceStyle: .dark))
expect(view).to(haveValidDynamicTypeSnapshot(named: "something custom with model and OS",
identifier: "bootstrap",
userInterfaceStyle: .light))
expect(view).to(haveValidDynamicTypeSnapshot(named: "something custom with model and OS",
identifier: "bootstrap",
userInterfaceStyle: .dark))
}

it("works with adjustsFontForContentSizeCategory") {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 100))
label.text = "Example"
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions Bootstrap/Podfile.lock
Expand Up @@ -8,9 +8,9 @@ PODS:
- iOSSnapshotTestCase/SwiftSupport (8.0.0):
- iOSSnapshotTestCase/Core
- Nimble (11.0.0)
- Nimble-Snapshots (9.4.0):
- Nimble-Snapshots/Core (= 9.4.0)
- Nimble-Snapshots/Core (9.4.0):
- Nimble-Snapshots (9.6.0):
- Nimble-Snapshots/Core (= 9.6.0)
- Nimble-Snapshots/Core (9.6.0):
- iOSSnapshotTestCase (~> 8.0)
- Nimble (~> 11.0)
- Quick (6.0.0)
Expand All @@ -35,7 +35,7 @@ SPEC CHECKSUMS:
Forgeries: 64ced144ea8341d89a7eec9d1d7986f0f1366250
iOSSnapshotTestCase: a670511f9ee3829c2b9c23e6e68f315fd7b6790f
Nimble: a854c12888a21d9e25a0413bb743ad76c37ef50c
Nimble-Snapshots: 9f29ff080d7aeceedd1c9b929cdb690e0a86439a
Nimble-Snapshots: 685ec7707c6055bce156341aa9d398a9d3e02f6f
Quick: 4d5ab9e81f0a632cbf9bc4f3069b55e5eeb175df

PODFILE CHECKSUM: cd5b709b72116303d001ccd6a46fecaf6ce2c21b
Expand Down
4 changes: 2 additions & 2 deletions Bootstrap/Pods/Local Podspecs/Nimble-Snapshots.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Bootstrap/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Bootstrap/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@

- Nothing yet!

## 9.6.0

- Add abitlity to test in light and dark mode

## 9.5.1

- Fixes SPM definition. See #255 - @diogot
Expand Down