Skip to content

Commit

Permalink
add slider and picker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shamanec committed Jul 26, 2023
1 parent ab9ccb6 commit c2331c3
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 0 deletions.
27 changes: 27 additions & 0 deletions xcuitest-sample-proj.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
FF7C55402A6EF2DA00102A71 /* LaunchArgumentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF7C553F2A6EF2DA00102A71 /* LaunchArgumentTests.swift */; };
FF86799B2A69699D00C4A1A7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF86799A2A69699D00C4A1A7 /* AppDelegate.swift */; };
FF86799E2A696BDC00C4A1A7 /* CarouselItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF86799D2A696BDC00C4A1A7 /* CarouselItemView.swift */; };
FFED40FE2A714284005B0940 /* Sliders in Frameworks */ = {isa = PBXBuildFile; productRef = FFED40FD2A714284005B0940 /* Sliders */; };
FFF0348F2A6CFA6500A33E97 /* FirstPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFF0348E2A6CFA6500A33E97 /* FirstPage.swift */; };
FFF034912A6CFA8B00A33E97 /* BasePage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFF034902A6CFA8B00A33E97 /* BasePage.swift */; };
FFF034932A6CFEA200A33E97 /* SecondPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFF034922A6CFEA200A33E97 /* SecondPage.swift */; };
Expand Down Expand Up @@ -79,6 +80,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
FFED40FE2A714284005B0940 /* Sliders in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -225,6 +227,9 @@
dependencies = (
);
name = "xcuitest-sample-proj";
packageProductDependencies = (
FFED40FD2A714284005B0940 /* Sliders */,
);
productName = "xcuitest-sample-proj";
productReference = FF79C1E42A66F1B600BBC60A /* xcuitest-sample-proj.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -297,6 +302,9 @@
Base,
);
mainGroup = FF79C1DB2A66F1B600BBC60A;
packageReferences = (
FFED40FC2A714284005B0940 /* XCRemoteSwiftPackageReference "swiftui-sliders" */,
);
productRefGroup = FF79C1E52A66F1B600BBC60A /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -683,6 +691,25 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
FFED40FC2A714284005B0940 /* XCRemoteSwiftPackageReference "swiftui-sliders" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "[email protected]:spacenation/swiftui-sliders.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
FFED40FD2A714284005B0940 /* Sliders */ = {
isa = XCSwiftPackageProductDependency;
package = FFED40FC2A714284005B0940 /* XCRemoteSwiftPackageReference "swiftui-sliders" */;
productName = Sliders;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = FF79C1DC2A66F1B600BBC60A /* Project object */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swiftui-sliders",
"kind" : "remoteSourceControl",
"location" : "[email protected]:spacenation/swiftui-sliders.git",
"state" : {
"revision" : "d5a7d856655d5c91f891c2b69d982c30fd5c7bdf",
"version" : "2.1.0"
}
}
],
"version" : 2
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,21 @@
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "CB5BA038-F170-4EE1-ABDC-0EED64624611"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "xcuitest-sample-projUITests/Helpers/Elements.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "40"
endingLineNumber = "40"
landmarkName = "setSlider(_:_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
18 changes: 18 additions & 0 deletions xcuitest-sample-proj/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import Sliders

@main
struct YourAppNameApp: App {
Expand Down Expand Up @@ -39,6 +40,9 @@ struct CarouselView: View {
@StateObject var viewModel = ArgumentTextViewModel()
@State private var isButtonVisible = true
@State private var text: String = ""
@State var sliderValue: Double = .zero
@State var selectedDate = Date()
@State var selectedPickerValue = "None"

var body: some View {
VStack {
Expand Down Expand Up @@ -86,6 +90,20 @@ struct CarouselView: View {
viewModel.displayText = "Custom"
}
}

Slider(value: $sliderValue, in: 0...1)
.frame(width: 300, height: 50)
.accessibilityIdentifier("slider")

let pickerValues = ["None", "Little", "Medium", "Normal", "More", "Many"]
Picker("", selection: $selectedPickerValue) {
ForEach(pickerValues, id: \.self) {
Text($0)
}
}
.pickerStyle(.wheel)
.frame(height: 150)
.accessibilityIdentifier("picker")
}
}

Expand Down
12 changes: 12 additions & 0 deletions xcuitest-sample-projUITests/Helpers/Elements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ class Elements {
XCTAssertTrue(result, "\(firstElement) is not in `\(relativePosition)` relative position to \(secondElement)")
}

/// Set a slider element to specific value when `adjust(toNormalizedSliderPosition: value)` doesn't work
/// The adjustment is based on the slider coordinates, absolute fidelity is not guaranteed.
static func setSlider(_ element: XCUIElement, _ value: CGFloat) {
let start = element.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.0))
let end = element.coordinate(withNormalizedOffset: CGVector(dx: value, dy: 0.0))
start.press(forDuration: 0.05, thenDragTo: end)
}

static func setPickerValue(_ element: XCUIElement, _ value: String) {
element.adjust(toPickerWheelValue: value)
}

// MARK: - Wait functions

/// Wait for element to exist
Expand Down
3 changes: 3 additions & 0 deletions xcuitest-sample-projUITests/Pages/FirstPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ class FirstPage: BasePage {
var disappearingButton: XCUIElement { app.buttons["disappearing-button"] }
var textField: XCUIElement { app.textFields["text-field"] }
var argumentText: XCUIElement { app.staticTexts["argument-text"] }
var slider: XCUIElement { app.sliders["slider"] }
var picker: XCUIElement { app.pickers["picker"] }
var pickerWheel: XCUIElement { picker.pickerWheels.firstMatch }
}
13 changes: 13 additions & 0 deletions xcuitest-sample-projUITests/SampleAppUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,17 @@ final class SampleAppUITests: BaseTest {
let firstPage = FirstPage(app: getApp())
XCTAssertEqual(firstPage.argumentText.label, "Argument:Default")
}

func testSelectPickerWheelValue() {
let firstPage = FirstPage(app: getApp())
XCTAssertEqual(firstPage.pickerWheel.textFromValue, "None")
Elements.setPickerValue(firstPage.pickerWheel, "Many")
XCTAssertEqual(firstPage.pickerWheel.textFromValue, "Many")
}

func testSetSliderPosition() {
let firstPage = FirstPage(app: getApp())
Elements.setSlider(firstPage.slider, 0.8)
print(firstPage.slider.textFromValue)
}
}

0 comments on commit c2331c3

Please sign in to comment.