Skip to content

Commit

Permalink
Snapshot tests for UIViewFlexContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Oct 10, 2023
1 parent ca76964 commit e526aca
Show file tree
Hide file tree
Showing 297 changed files with 256 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ abstract class AbstractFlexContainerTest<T : Any> {
this.modifier = modifier
}

@Test fun emptyLayout_Column() {
@Test fun testEmptyLayout_Column() {
emptyLayout(FlexDirectionEnum.Column)
}

@Test fun emptyLayout_Row() {
@Test fun testEmptyLayout_Row() {
emptyLayout(FlexDirectionEnum.Row)
}

Expand All @@ -63,35 +63,35 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun layoutWithConstraints_Column_Wrap_Wrap() {
@Test fun testLayoutWithConstraints_Column_Wrap_Wrap() {
layoutWithConstraints(FlexDirectionEnum.Column, ConstraintEnum.Wrap, ConstraintEnum.Wrap)
}

@Test fun layoutWithConstraints_Column_Wrap_Fill() {
@Test fun testLayoutWithConstraints_Column_Wrap_Fill() {
layoutWithConstraints(FlexDirectionEnum.Column, ConstraintEnum.Wrap, ConstraintEnum.Fill)
}

@Test fun layoutWithConstraints_Column_Fill_Wrap() {
@Test fun testLayoutWithConstraints_Column_Fill_Wrap() {
layoutWithConstraints(FlexDirectionEnum.Column, ConstraintEnum.Fill, ConstraintEnum.Wrap)
}

@Test fun layoutWithConstraints_Column_Fill_Fill() {
@Test fun testLayoutWithConstraints_Column_Fill_Fill() {
layoutWithConstraints(FlexDirectionEnum.Column, ConstraintEnum.Fill, ConstraintEnum.Fill)
}

@Test fun layoutWithConstraints_Row_Wrap_Wrap() {
@Test fun testLayoutWithConstraints_Row_Wrap_Wrap() {
layoutWithConstraints(FlexDirectionEnum.Row, ConstraintEnum.Wrap, ConstraintEnum.Wrap)
}

@Test fun layoutWithConstraints_Row_Wrap_Fill() {
@Test fun testLayoutWithConstraints_Row_Wrap_Fill() {
layoutWithConstraints(FlexDirectionEnum.Row, ConstraintEnum.Wrap, ConstraintEnum.Fill)
}

@Test fun layoutWithConstraints_Row_Fill_Wrap() {
@Test fun testLayoutWithConstraints_Row_Fill_Wrap() {
layoutWithConstraints(FlexDirectionEnum.Row, ConstraintEnum.Fill, ConstraintEnum.Wrap)
}

@Test fun layoutWithConstraints_Row_Fill_Fill() {
@Test fun testLayoutWithConstraints_Row_Fill_Fill() {
layoutWithConstraints(FlexDirectionEnum.Row, ConstraintEnum.Fill, ConstraintEnum.Fill)
}

Expand All @@ -112,11 +112,11 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun shortLayout_Column() {
@Test fun testShortLayout_Column() {
shortLayout(FlexDirectionEnum.Column)
}

@Test fun shortLayout_Row() {
@Test fun testShortLayout_Row() {
shortLayout(FlexDirectionEnum.Row)
}

Expand All @@ -134,11 +134,11 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun longLayout_Column() {
@Test fun testLongLayout_Column() {
longLayout(FlexDirectionEnum.Column)
}

@Test fun longLayout_Row() {
@Test fun testLongLayout_Row() {
longLayout(FlexDirectionEnum.Row)
}

Expand All @@ -156,11 +156,11 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun layoutWithMarginAndDifferentAlignments_Column() {
@Test fun testLayoutWithMarginAndDifferentAlignments_Column() {
layoutWithMarginAndDifferentAlignments(FlexDirectionEnum.Column)
}

@Test fun layoutWithMarginAndDifferentAlignments_Row() {
@Test fun testLayoutWithMarginAndDifferentAlignments_Row() {
layoutWithMarginAndDifferentAlignments(FlexDirectionEnum.Row)
}

Expand All @@ -186,35 +186,35 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun layoutWithCrossAxisAlignment_Column_Start() {
@Test fun testLayoutWithCrossAxisAlignment_Column_Start() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Column, CrossAxisAlignmentEnum.Start)
}

@Test fun layoutWithCrossAxisAlignment_Column_Center() {
@Test fun testLayoutWithCrossAxisAlignment_Column_Center() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Column, CrossAxisAlignmentEnum.Center)
}

@Test fun layoutWithCrossAxisAlignment_Column_End() {
@Test fun testLayoutWithCrossAxisAlignment_Column_End() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Column, CrossAxisAlignmentEnum.End)
}

@Test fun layoutWithCrossAxisAlignment_Column_Stretch() {
@Test fun testLayoutWithCrossAxisAlignment_Column_Stretch() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Column, CrossAxisAlignmentEnum.Stretch)
}

@Test fun layoutWithCrossAxisAlignment_Row_Start() {
@Test fun testLayoutWithCrossAxisAlignment_Row_Start() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Row, CrossAxisAlignmentEnum.Start)
}

@Test fun layoutWithCrossAxisAlignment_Row_Center() {
@Test fun testLayoutWithCrossAxisAlignment_Row_Center() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Row, CrossAxisAlignmentEnum.Center)
}

@Test fun layoutWithCrossAxisAlignment_Row_End() {
@Test fun testLayoutWithCrossAxisAlignment_Row_End() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Row, CrossAxisAlignmentEnum.End)
}

@Test fun layoutWithCrossAxisAlignment_Row_Stretch() {
@Test fun testLayoutWithCrossAxisAlignment_Row_Stretch() {
layoutWithCrossAxisAlignment(FlexDirectionEnum.Row, CrossAxisAlignmentEnum.Stretch)
}

Expand Down Expand Up @@ -252,15 +252,15 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container, "FlexEnd")
}

@Test fun columnWithMainAxisAlignment_Center() {
@Test fun testColumnWithMainAxisAlignment_Center() {
columnWithMainAxisAlignment(MainAxisAlignmentEnum.Center)
}

@Test fun columnWithMainAxisAlignment_SpaceBetween() {
@Test fun testColumnWithMainAxisAlignment_SpaceBetween() {
columnWithMainAxisAlignment(MainAxisAlignmentEnum.SpaceBetween)
}

@Test fun columnWithMainAxisAlignment_SpaceAround() {
@Test fun testColumnWithMainAxisAlignment_SpaceAround() {
columnWithMainAxisAlignment(MainAxisAlignmentEnum.SpaceAround)
}

Expand All @@ -281,7 +281,7 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun containerWithFixedWidthItems() {
@Test fun testContainerWithFixedWidthItems() {
val container = flexContainer(FlexDirection.Column)
container.width(Constraint.Fill)
container.height(Constraint.Fill)
Expand All @@ -293,7 +293,7 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun containerWithFixedHeightItems() {
@Test fun testContainerWithFixedHeightItems() {
val container = flexContainer(FlexDirection.Column)
container.width(Constraint.Fill)
container.height(Constraint.Fill)
Expand All @@ -305,7 +305,7 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun containerWithFixedSizeItems() {
@Test fun testContainerWithFixedSizeItems() {
val container = flexContainer(FlexDirection.Column)
container.width(Constraint.Fill)
container.height(Constraint.Fill)
Expand All @@ -317,7 +317,7 @@ abstract class AbstractFlexContainerTest<T : Any> {
verifySnapshot(container)
}

@Test fun childWithUpdatedProperty() {
@Test fun testChildWithUpdatedProperty() {
val container = flexContainer(FlexDirection.Column)
container.width(Constraint.Fill)
container.height(Constraint.Fill)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
objects = {

/* Begin PBXBuildFile section */
102FEEF22AD5D09F00246158 /* UIViewFlexContainerTestHost.swift in Sources */ = {isa = PBXBuildFile; fileRef = 102FEEF12AD5D09F00246158 /* UIViewFlexContainerTestHost.swift */; };
CB408CE82AC64CEF00E1BA00 /* UIViewSpacerTestHost.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB408CE72AC64CEF00E1BA00 /* UIViewSpacerTestHost.swift */; };
CB408CED2AC6549F00E1BA00 /* KotlinHostingXCTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB408CEC2AC6549F00E1BA00 /* KotlinHostingXCTestCase.swift */; };
CB408CF72AC657EF00E1BA00 /* KotlinHostingXCTestCaseHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = CB408CF62AC657EF00E1BA00 /* KotlinHostingXCTestCaseHelper.m */; };
CB8A21EF2AC6647F00C104C2 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = CB8A21EE2AC6647F00C104C2 /* SnapshotTesting */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
102FEEF12AD5D09F00246158 /* UIViewFlexContainerTestHost.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewFlexContainerTestHost.swift; sourceTree = "<group>"; };
63E90CF521FEBBB700449E04 /* RedwoodLayoutUIViewTestKt.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RedwoodLayoutUIViewTestKt.framework; path = "build/xcode-frameworks/RedwoodLayoutUIViewTestKt.framework"; sourceTree = "<group>"; };
CB408CE52AC64CEF00E1BA00 /* RedwoodLayoutUIViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RedwoodLayoutUIViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
CB408CE72AC64CEF00E1BA00 /* UIViewSpacerTestHost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewSpacerTestHost.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -63,6 +65,7 @@
CB408CE62AC64CEF00E1BA00 /* RedwoodLayoutUIViewTests */ = {
isa = PBXGroup;
children = (
102FEEF12AD5D09F00246158 /* UIViewFlexContainerTestHost.swift */,
CB408CE72AC64CEF00E1BA00 /* UIViewSpacerTestHost.swift */,
CB408CEC2AC6549F00E1BA00 /* KotlinHostingXCTestCase.swift */,
CB408CF62AC657EF00E1BA00 /* KotlinHostingXCTestCaseHelper.m */,
Expand Down Expand Up @@ -171,6 +174,7 @@
CB408CED2AC6549F00E1BA00 /* KotlinHostingXCTestCase.swift in Sources */,
CB408CF72AC657EF00E1BA00 /* KotlinHostingXCTestCaseHelper.m in Sources */,
CB408CE82AC64CEF00E1BA00 /* UIViewSpacerTestHost.swift in Sources */,
102FEEF22AD5D09F00246158 /* UIViewFlexContainerTestHost.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -302,7 +306,10 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
"$(PROJECT_DIR)/build/xcode-frameworks",
);
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -337,7 +344,10 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
"$(PROJECT_DIR)/build/xcode-frameworks",
);
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ open class KotlinHostingXCTestCase<KotlinTest>: KotlinHostingXCTestCaseHelper wh
public override class func createTestMethods() {
var targetClass: AnyClass = KotlinTest.self
while (targetClass != NSObject.self) {
print("inspecting class " + (targetClass.debugDescription()))
var methodCount: UInt32 = 0
let methodList = class_copyMethodList(targetClass, &methodCount)
if let methodList = methodList {
defer { free(methodList) }

for i in 0..<Int(methodCount) {
let selector = method_getName(methodList[i])
let selectorName = NSStringFromSelector(selector)

print("found method " + selectorName)

if selectorName.hasPrefix("test") {
let kotlinTest = initTest(name: selectorName)
createTestMethod(target: kotlinTest, selector: selector)
Expand All @@ -39,7 +43,7 @@ open class KotlinHostingXCTestCase<KotlinTest>: KotlinHostingXCTestCaseHelper wh
targetClass = nextClass
}
}

private static func createTestMethod(target: KotlinTest, selector: Selector) {
let block: @convention(block) () -> Void = {
if target.responds(to: #selector(setUp)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import SnapshotTesting
import RedwoodLayoutUIViewTestKt
import UIKit

final class UIViewFlexContainerTestHost: KotlinHostingXCTestCase<UIViewFlexContainerTest> {
override class func initTest(name: String) -> UIViewFlexContainerTest {
return UIViewFlexContainerTest(callback: Callback(named: name))
}
}

private class Callback : UIViewFlexContainerTestCallback {
private let testName: String

init(named testName: String) {
self.testName = testName
}

func verifySnapshot(view: UIView, name: String?) {
var snapshotName = testName
if (name != nil) {
snapshotName = "\(testName)-\(name!)"
}
assertSnapshot(of: view, as: .image, named: snapshotName, record: true)
}
}
Loading

0 comments on commit e526aca

Please sign in to comment.