Skip to content

Commit

Permalink
Merge pull request #12 from MFB-Technologies-Inc/feature/fix-test-war…
Browse files Browse the repository at this point in the history
…nings

Feature/fix test warnings
  • Loading branch information
roanutil authored Nov 13, 2024
2 parents fcd8b27 + a2d1693 commit 1b42855
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: macos-13
environment: default
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Format lint
run: swiftformat --lint .
- name: Lint
Expand All @@ -37,7 +37,7 @@ jobs:
sim: iPhone 15
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Select Xcode ${{ matrix.xcode }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
- name: Boot simulator
Expand Down
13 changes: 8 additions & 5 deletions Example/ExampleUITests/ExampleUITestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import XCTest
import Example_macOS
#endif

@MainActor
class ExampleUITestCase: XCUITestCase {
var _sectionNavItem: (() throws -> XCUIElement)? {
var _sectionNavItem: (@MainActor () throws -> XCUIElement)? {
nil
}

func sectionNavItem() throws -> XCUIElement {
try XCTUnwrap(_sectionNavItem)()
}

var _picker: (() throws -> XCUIElement)? {
var _picker: (@MainActor () throws -> XCUIElement)? {
nil
}

Expand All @@ -36,9 +37,11 @@ class ExampleUITestCase: XCUITestCase {
#if os(iOS)
// iPad has a bug where view is blank when starting in portrait
// Let's rotate it landscape and back to work around that bug.
XCUIDevice.shared.orientation = .portrait
XCUIDevice.shared.orientation = .landscapeRight
XCUIDevice.shared.orientation = .portrait
Task { @MainActor in
XCUIDevice.shared.orientation = .portrait
XCUIDevice.shared.orientation = .landscapeRight
XCUIDevice.shared.orientation = .portrait
}
#endif
}

Expand Down
11 changes: 7 additions & 4 deletions Example/ExampleUITests/MutliValueUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import XCTest
import Example_macOS
#endif

@MainActor
final class MultiValueUITests: ExampleUITestCase {
override var _sectionNavItem: (() throws -> XCUIElement)? {
@MainActor
override var _sectionNavItem: (@MainActor () throws -> XCUIElement)? {
multiValueNavItem
}

override var _picker: (() throws -> XCUIElement)? {
@MainActor
override var _picker: (@MainActor () throws -> XCUIElement)? {
multiValuePicker
}

Expand Down Expand Up @@ -56,14 +59,14 @@ final class MultiValueUITests: ExampleUITestCase {
XCTAssert(try !buttonOne().isSelected, "'1' is still not selected after being deselected and '0' is deselected")
}

func testGridStyleDeselectAndSelectNew() throws {
func testGridStyleDeselectAndSelectNew() async throws {
_ = try gridStyleToggle().waitForExistence(timeout: 1)
try setGridStyle()

try sharedTestSteps()
}

func testListStyleDeselectAndSelectNew() throws {
func testListStyleDeselectAndSelectNew() async throws {
_ = try gridStyleToggle().waitForExistence(timeout: 1)
try setListStyle()

Expand Down
11 changes: 7 additions & 4 deletions Example/ExampleUITests/SingleOptionalValueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import XCTest
import Example_macOS
#endif

@MainActor
final class SingleOptionalValueUITests: ExampleUITestCase {
override var _sectionNavItem: (() throws -> XCUIElement)? {
@MainActor
override var _sectionNavItem: (@MainActor () throws -> XCUIElement)? {
singleOptionalValueNavItem
}

override var _picker: (() throws -> XCUIElement)? {
@MainActor
override var _picker: (@MainActor () throws -> XCUIElement)? {
singleOptionalValuePicker
}

Expand Down Expand Up @@ -54,14 +57,14 @@ final class SingleOptionalValueUITests: ExampleUITestCase {
XCTAssert(try buttonOne().isSelected, "'1' should be selected after it is tapped.")
}

func testGridStyleDeselectAndSelectNew() throws {
func testGridStyleDeselectAndSelectNew() async throws {
_ = try gridStyleToggle().waitForExistence(timeout: 1)
try setGridStyle()

try sharedTestSteps()
}

func testListStyleDeselectAndSelectNew() throws {
func testListStyleDeselectAndSelectNew() async throws {
_ = try gridStyleToggle().waitForExistence(timeout: 1)
try setListStyle()

Expand Down
11 changes: 7 additions & 4 deletions Example/ExampleUITests/SingleValueUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import XCTest
import Example_macOS
#endif

@MainActor
final class SingleValueUITests: ExampleUITestCase {
override var _sectionNavItem: (() throws -> XCUIElement)? {
@MainActor
override var _sectionNavItem: (@MainActor () throws -> XCUIElement)? {
singleValueNavItem
}

override var _picker: (() throws -> XCUIElement)? {
@MainActor
override var _picker: (@MainActor () throws -> XCUIElement)? {
singleValuePicker
}

Expand Down Expand Up @@ -67,7 +70,7 @@ final class SingleValueUITests: ExampleUITestCase {
XCTAssert(try !buttonZero().isSelected, "'0' should no longer be selected after tapping a new item.")
}

func testGridStyleDeselectAndSelectNew() throws {
func testGridStyleDeselectAndSelectNew() async throws {
_ = try gridStyleToggle().waitForExistence(timeout: 1)
#if os(tvOS)
guard try findVertically(gridStyleToggle(), method: .downOnly) else {
Expand All @@ -80,7 +83,7 @@ final class SingleValueUITests: ExampleUITestCase {
try sharedTestSteps()
}

func testListStyleDeselectAndSelectNew() throws {
func testListStyleDeselectAndSelectNew() async throws {
_ = try gridStyleToggle().waitForExistence(timeout: 1)
#if os(tvOS)
guard try findVertically(gridStyleToggle(), method: .downOnly) else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import XCTest

extension XCUIElementQuery {
@MainActor
public func exactlyOneMatch() throws -> XCUIElement {
XCTAssertEqual(count, 1, "Requiring only one element match the query resulting in `self`")
return firstMatch
Expand Down
18 changes: 12 additions & 6 deletions Example/ExampleUITests/XCUITestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import XCTest

@MainActor
class XCUITestCase: XCTestCase {
private var _app: XCUIApplication?

Expand All @@ -30,14 +31,18 @@ class XCUITestCase: XCTestCase {
}

func elementCompoundOrPredicate(labeled labels: Set<String>) -> NSPredicate {
NSCompoundPredicate(orPredicateWithSubpredicates: labels.map(elementPredicate(labeled:)))
let subpredicates = labels.map { label in
elementPredicate(labeled: label)
}
return NSCompoundPredicate(orPredicateWithSubpredicates: subpredicates)
}

override func setUpWithError() throws {
_app = XCUIApplication()
continueAfterFailure = false

try app().launch()
override func setUp() async throws {
Task { @MainActor in
self._app = XCUIApplication()
self.continueAfterFailure = false
try? self.app().launch()
}
}
}

Expand All @@ -53,6 +58,7 @@ class XCUITestCase: XCTestCase {
)
}

@MainActor
func currentFocus() throws -> XCUIElement {
try allElements().descendants(matching: .any).element(matching: focusPredicate)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PickBetter/PlainInlineBetterPickerStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct PlainInlineBetterPickerStyle: BetterPickerStyle {
let id: String
}

private var items: [PreviewItem] = ["A", "B", "C"].map { PreviewItem(id: $0) }
private let items: [PreviewItem] = ["A", "B", "C"].map { PreviewItem(id: $0) }

private func itemContent(_ item: PreviewItem) -> some View {
Text(item.id)
Expand Down

0 comments on commit 1b42855

Please sign in to comment.