Skip to content

Commit

Permalink
Fix UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tattn committed Oct 21, 2023
1 parent 30b641d commit c848df9
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 17 deletions.
18 changes: 11 additions & 7 deletions app/xcode/App/VCam.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
0612386D2ADE9A8400B67618 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0612386C2ADE9A8400B67618 /* Preview Assets.xcassets */; };
061238752ADE9C6D00B67618 /* xcode in Resources */ = {isa = PBXBuildFile; fileRef = 061238742ADE9C6D00B67618 /* xcode */; };
061238782ADE9CEE00B67618 /* VCam in Frameworks */ = {isa = PBXBuildFile; productRef = 061238772ADE9CEE00B67618 /* VCam */; };
06A72E8B2AE4305D000D0B25 /* XCUIApplication+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A72E8A2AE4305D000D0B25 /* XCUIApplication+.swift */; };
06A72E8D2AE4359E000D0B25 /* VCam in Frameworks */ = {isa = PBXBuildFile; productRef = 06A72E8C2AE4359E000D0B25 /* VCam */; };
06EC61182ADEE7A900D2A5C9 /* VCamStub in Frameworks */ = {isa = PBXBuildFile; productRef = 06EC61172ADEE7A900D2A5C9 /* VCamStub */; };
06EC61202AE016C300D2A5C9 /* VCamUIPreviewUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06EC611F2AE016C300D2A5C9 /* VCamUIPreviewUITests.swift */; };
06EC61222AE016C300D2A5C9 /* LaunchScreenshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06EC61212AE016C300D2A5C9 /* LaunchScreenshotTests.swift */; };
06EC61292AE0296600D2A5C9 /* VCamLocalization in Frameworks */ = {isa = PBXBuildFile; productRef = 06EC61282AE0296600D2A5C9 /* VCamLocalization */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -37,6 +38,7 @@
0612386C2ADE9A8400B67618 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
0612386E2ADE9A8400B67618 /* VCamUIPreview.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = VCamUIPreview.entitlements; sourceTree = "<group>"; };
061238742ADE9C6D00B67618 /* xcode */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = xcode; path = ..; sourceTree = "<group>"; };
06A72E8A2AE4305D000D0B25 /* XCUIApplication+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIApplication+.swift"; sourceTree = "<group>"; };
06EC611D2AE016C300D2A5C9 /* VCamUIPreviewUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = VCamUIPreviewUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
06EC611F2AE016C300D2A5C9 /* VCamUIPreviewUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VCamUIPreviewUITests.swift; sourceTree = "<group>"; };
06EC61212AE016C300D2A5C9 /* LaunchScreenshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchScreenshotTests.swift; sourceTree = "<group>"; };
Expand All @@ -56,7 +58,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
06EC61292AE0296600D2A5C9 /* VCamLocalization in Frameworks */,
06A72E8D2AE4359E000D0B25 /* VCam in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -115,6 +117,7 @@
children = (
06EC611F2AE016C300D2A5C9 /* VCamUIPreviewUITests.swift */,
06EC61212AE016C300D2A5C9 /* LaunchScreenshotTests.swift */,
06A72E8A2AE4305D000D0B25 /* XCUIApplication+.swift */,
);
path = VCamUIPreviewUITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -158,7 +161,7 @@
);
name = VCamUIPreviewUITests;
packageProductDependencies = (
06EC61282AE0296600D2A5C9 /* VCamLocalization */,
06A72E8C2AE4359E000D0B25 /* VCam */,
);
productName = VCamUIPreviewUITests;
productReference = 06EC611D2AE016C300D2A5C9 /* VCamUIPreviewUITests.xctest */;
Expand Down Expand Up @@ -237,6 +240,7 @@
buildActionMask = 2147483647;
files = (
06EC61222AE016C300D2A5C9 /* LaunchScreenshotTests.swift in Sources */,
06A72E8B2AE4305D000D0B25 /* XCUIApplication+.swift in Sources */,
06EC61202AE016C300D2A5C9 /* VCamUIPreviewUITests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -499,13 +503,13 @@
isa = XCSwiftPackageProductDependency;
productName = VCam;
};
06EC61172ADEE7A900D2A5C9 /* VCamStub */ = {
06A72E8C2AE4359E000D0B25 /* VCam */ = {
isa = XCSwiftPackageProductDependency;
productName = VCamStub;
productName = VCam;
};
06EC61282AE0296600D2A5C9 /* VCamLocalization */ = {
06EC61172ADEE7A900D2A5C9 /* VCamStub */ = {
isa = XCSwiftPackageProductDependency;
productName = VCamLocalization;
productName = VCamStub;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down
4 changes: 4 additions & 0 deletions app/xcode/App/VCamUIPreview/VCamUIPreviewApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ struct VCamUIPreviewApp: App {

final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
if ProcessInfo.processInfo.arguments.contains("UITesting") {
UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
}

Task {
await configureApp()
}
Expand Down
46 changes: 38 additions & 8 deletions app/xcode/App/VCamUIPreviewUITests/LaunchScreenshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import VCamLocalization
final class LaunchScreenshotTests: XCTestCase {

override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
false // Light mode only
}

override func setUpWithError() throws {
Expand All @@ -20,15 +20,9 @@ final class LaunchScreenshotTests: XCTestCase {
}

func testLaunch() throws {
let app = XCUIApplication()
let app = XCUIApplication.make()
app.launch()

// Close the alert about the virtual camera if needed"
if app.staticTexts[L10n.installVirtualCamera.text].exists {
app.buttons["OK"].click()
app.buttons["OK"].click()
}

XCTContext.runActivity(named: "Launch Screen") { activity in
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}
Expand All @@ -44,6 +38,42 @@ final class LaunchScreenshotTests: XCTestCase {
_ = app.staticTexts[L10n.startRecording.text].waitForExistence(timeout: 5)
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}

XCTContext.runActivity(named: "\(L10n.settings.text) Screen") { activity in
app.buttons["btn_settings"].click()
_ = app.staticTexts[L10n.settings.text].waitForExistence(timeout: 5)
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
XCTAssertTrue(app.cells.firstMatch.isSelected)

XCTContext.runActivity(named: "\(L10n.settings.text) Screen - \(L10n.rendering.text)") { activity in
app.cells.staticTexts[L10n.rendering.text].click()
_ = app.staticTexts[L10n.renderingQuality.text].waitForExistence(timeout: 5)
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}

XCTContext.runActivity(named: "\(L10n.settings.text) Screen - \(L10n.tracking.text)") { activity in
app.cells.staticTexts[L10n.tracking.text].click()
_ = app.staticTexts[L10n.fpsCamera.text].waitForExistence(timeout: 5)
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}

XCTContext.runActivity(named: "\(L10n.settings.text) Screen - \(L10n.virtualCamera.text)") { activity in
app.cells.staticTexts[L10n.virtualCamera.text].click()
_ = app.staticTexts[L10n.noteEnableNewCameraExtension.text].waitForExistence(timeout: 5)
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}

XCTContext.runActivity(named: "\(L10n.settings.text) Screen - \(L10n.integration.text)") { activity in
app.cells.staticTexts[L10n.integration.text].click()
_ = app.staticTexts["VCamMocap"].waitForExistence(timeout: 5)
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}

XCTContext.runActivity(named: "\(L10n.settings.text) Screen - \(L10n.experiment.text)") { activity in
app.cells.staticTexts[L10n.experiment.text].click()
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class VCamUIPreviewUITests: XCTestCase {
}

func testLaunchApp() throws {
let app = XCUIApplication()
let app = XCUIApplication.make()
app.launch()

// Close the alert about the virtual camera if needed"
Expand Down
30 changes: 30 additions & 0 deletions app/xcode/App/VCamUIPreviewUITests/XCUIApplication+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// XCUIApplication+.swift
// VCamUIPreviewUITests
//
// Created by Tatsuya Tanaka on 2023/10/22.
//

import XCTest
import VCamData
import VCamDefaults

extension XCUIApplication {
struct Configuration {
static let `default` = Configuration()
var previousVersion: String? = "999.9.9" // skip migration
}

static func make(with configuration: Configuration = .default) -> XCUIApplication {
let app = XCUIApplication()
app.launchArguments += ["UITesting"]
if let value = configuration.previousVersion {
app.setUserDefaults(value: value, for: .previousVersion)
}
return app
}

func setUserDefaults<T: UserDefaultsValue>(value: String, for key: UserDefaults.Key<T>) {
launchArguments += ["-\(key.rawValue)", value]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
import SwiftUI

public enum VCamSettingExperimentView {
public static var make: () -> AnyView = { fatalError() }
public static var make: () -> AnyView = {
AnyView(EmptyView())
}
}
2 changes: 2 additions & 0 deletions app/xcode/Sources/VCamUI/VCamMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private struct MenuBottomView: View {
}
.buttonStyle(.plain)
.disabled(recorder.isRecording)
.accessibilityIdentifier("btn_settings")
}
.controlSize(.small)

Expand Down Expand Up @@ -126,6 +127,7 @@ private struct VCamMenuButtonStyle: ButtonStyle {
)
.cornerRadius(6.0)
.contentShape(Rectangle())
.accessibilityAddTraits(isSelected ? [.isButton, .isSelected] : [.isButton])
}
}

Expand Down
6 changes: 6 additions & 0 deletions app/xcode/Sources/VCamUI/VCamSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ public final class VCamSystem {

Task { @MainActor in
if !windowManager.isUnity {
#if DEBUG
if !ProcessInfo.processInfo.arguments.contains("UITesting") {
await AppUpdater.vcam.presentUpdateAlertIfAvailable()
}
#else
await AppUpdater.vcam.presentUpdateAlertIfAvailable()
#endif
}

await Migration.migrate()
Expand Down

0 comments on commit c848df9

Please sign in to comment.