diff --git a/.github/workflows/xcode-build.yml b/.github/workflows/xcode-build.yml index b158364f..8e576e80 100644 --- a/.github/workflows/xcode-build.yml +++ b/.github/workflows/xcode-build.yml @@ -36,7 +36,7 @@ jobs: run: | xcodebuild clean test \ -project SlimHUD.xcodeproj \ - -scheme SlimHUD-GitHub-Action \ + -scheme SlimHUD-Unit-Only \ -destination platform=macOS \ -resultBundlePath TestResults \ -test-iterations 20 -retry-tests-on-failure \ @@ -69,7 +69,7 @@ jobs: with: name: sonarqube-generic-coverage - name: Setup sonarqube - uses: warchant/setup-sonar-scanner@v3 + uses: warchant/setup-sonar-scanner@v8 - name: Run sonarqube run: | sonar-scanner diff --git a/SlimHUD.xcodeproj/project.pbxproj b/SlimHUD.xcodeproj/project.pbxproj index f6988695..9c163b75 100644 --- a/SlimHUD.xcodeproj/project.pbxproj +++ b/SlimHUD.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ FA2D3DE22971EC2B00ABADDE /* MainMenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA2D3DE12971EC2B00ABADDE /* MainMenuController.swift */; }; FA322FC4297F485700E8F31A /* StandardLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA322FC3297F485700E8F31A /* StandardLabel.swift */; }; FA322FC6297F506200E8F31A /* EdgeSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA322FC5297F506200E8F31A /* EdgeSelector.swift */; }; + FA5023582BD5467C0051496C /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5023572BD5467C0051496C /* TestUtils.swift */; }; FA55A5EA29CCFF7D00415378 /* CALayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA55A5E929CCFF7D00415378 /* CALayer.swift */; }; FA56F6DE29666815008177B1 /* UITestsUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F6DD29666815008177B1 /* UITestsUtils.swift */; }; FA56F6E029666AB1008177B1 /* HudsUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F6DF29666AB1008177B1 /* HudsUITests.swift */; }; @@ -120,6 +121,7 @@ FA2D3DE12971EC2B00ABADDE /* MainMenuController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenuController.swift; sourceTree = ""; }; FA322FC3297F485700E8F31A /* StandardLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardLabel.swift; sourceTree = ""; }; FA322FC5297F506200E8F31A /* EdgeSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EdgeSelector.swift; sourceTree = ""; }; + FA5023572BD5467C0051496C /* TestUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestUtils.swift; sourceTree = ""; }; FA55A5E929CCFF7D00415378 /* CALayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CALayer.swift; sourceTree = ""; }; FA56F6DD29666815008177B1 /* UITestsUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITestsUtils.swift; sourceTree = ""; }; FA56F6DF29666AB1008177B1 /* HudsUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HudsUITests.swift; sourceTree = ""; }; @@ -431,6 +433,7 @@ FA95EE8429574495005B39CD /* SparkleUITests.swift */, FA56F6DD29666815008177B1 /* UITestsUtils.swift */, FAFC57A12967668500C32A80 /* XCUIApplicationExtension.swift */, + FA5023572BD5467C0051496C /* TestUtils.swift */, ); path = Utils; sourceTree = ""; @@ -682,6 +685,7 @@ FA56F6DE29666815008177B1 /* UITestsUtils.swift in Sources */, FA56F6E029666AB1008177B1 /* HudsUITests.swift in Sources */, FA56F6ED2966773F008177B1 /* AAAUITestSetup.swift in Sources */, + FA5023582BD5467C0051496C /* TestUtils.swift in Sources */, FA12B65829CEBD9E0027D6B0 /* LaunchAtLoginTests.swift in Sources */, FAFC57A22967668500C32A80 /* XCUIApplicationExtension.swift in Sources */, FAD49D1029B398ED0034A8D8 /* ConfigSettingsUITests.swift in Sources */, diff --git a/SlimHUD.xcodeproj/xcshareddata/xcschemes/SlimHUD-Unit-Only.xcscheme b/SlimHUD.xcodeproj/xcshareddata/xcschemes/SlimHUD-Unit-Only.xcscheme new file mode 100644 index 00000000..3e85a951 --- /dev/null +++ b/SlimHUD.xcodeproj/xcshareddata/xcschemes/SlimHUD-Unit-Only.xcscheme @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SlimHUD/AppDelegate.swift b/SlimHUD/AppDelegate.swift index 70e3c274..f00be635 100644 --- a/SlimHUD/AppDelegate.swift +++ b/SlimHUD/AppDelegate.swift @@ -50,7 +50,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { NotificationCenter.default.addObserver(forName: NSApplication.didChangeScreenParametersNotification, object: NSApplication.shared, - queue: OperationQueue.main) { _ -> Void in + queue: OperationQueue.main) { _ in self.positionManager.setupHUDsPosition(isFullscreen: false) self.changesObserver.resetTemporarelyDisabledBars() } diff --git a/SlimHUD/Services/LoginItemList.swift b/SlimHUD/Services/LoginItemList.swift index c6c7f4d3..c67670a9 100644 --- a/SlimHUD/Services/LoginItemList.swift +++ b/SlimHUD/Services/LoginItemList.swift @@ -55,8 +55,7 @@ class LoginItemsList: NSObject { // Iterate through login items to find one for given path NSLog("App URL: \(path)") - for index in (0.. 0 { + element.click() + usleep(100000) // 0.1s + limit -= 1 + actValue = actual.firstMatch.value as? Int + } + XCTAssertEqual(actValue, expected) + } } diff --git a/SlimHUDUITests/SettingsUITests.swift b/SlimHUDUITests/SettingsUITests.swift index 516abe0f..5ad1c9d9 100644 --- a/SlimHUDUITests/SettingsUITests.swift +++ b/SlimHUDUITests/SettingsUITests.swift @@ -120,7 +120,7 @@ final class SettingsUITest: SparkleUITests { XCTAssertEqual(2, settingsWindow.popovers.children(matching: .slider).count) } - func testChangeValuesInShadowPopupRadiusInput() throws { + func testChangeValuesInShadowPopupRadiusInput() throws { // todo: check why failed - flaky?,, also check for actual radius of bar let visibleFrame = NSScreen.screens[0].visibleFrame let position = NSPoint(x: 7, y: (visibleFrame.height/2)) diff --git a/SlimHUDUITests/StyleSettingsUITests.swift b/SlimHUDUITests/StyleSettingsUITests.swift index 6f84b8f9..9723e33a 100644 --- a/SlimHUDUITests/StyleSettingsUITests.swift +++ b/SlimHUDUITests/StyleSettingsUITests.swift @@ -19,13 +19,13 @@ final class StyleSettingsUITests: UITestsUtils { if checkBox.value as? Int == 1 { checkBox.click() XCTAssertFalse(isVolumeHudVisible(app: app)) - sleep(1) + usleep(100000) // 0.1s checkBox.click() XCTAssertTrue(isVolumeHudVisible(app: app)) } else { checkBox.click() XCTAssertTrue(isVolumeHudVisible(app: app)) - sleep(1) + usleep(100000) // 0.1s checkBox.click() XCTAssertFalse(isVolumeHudVisible(app: app)) } diff --git a/SlimHUDUITests/Utils/TestUtils.swift b/SlimHUDUITests/Utils/TestUtils.swift new file mode 100644 index 00000000..b6373d65 --- /dev/null +++ b/SlimHUDUITests/Utils/TestUtils.swift @@ -0,0 +1,27 @@ +// +// TestUtils.swift +// SlimHUDUITests +// +// Created by Alex Perathoner on 21/04/24. +// + +import XCTest + +final class TestUtils: UITestsUtils { + + func testH() { + XCTAssertTrue(h(screenFrame: .init(x: 0, y: 0, width: 1600, height: 900), x: 0, y: 400)) // left + XCTAssertTrue(h(screenFrame: .init(x: 0, y: 0, width: 1600, height: 900), x: 800, y: 0)) // bottom + XCTAssertFalse(h(screenFrame: .init(x: 0, y: 0, width: 1600, height: 900), x: 1600, y: 400)) // right + XCTAssertFalse(h(screenFrame: .init(x: 0, y: 0, width: 1600, height: 900), x: 800, y: 900)) // top + } + + func testG() { + XCTAssertTrue(g(screenFrame: .init(x: 0, y: 0, width: 1600, height: 900), x: 0, y: 400)) // left + XCTAssertTrue(g(screenFrame: .init(x: 0, y: 0, width: 1600, height: 900), x: -50, y: 638)) // left + XCTAssertFalse(g(screenFrame: .init(x: 0, y: 0, width: 1600, height: 900), x: 800, y: 0)) // bottom + XCTAssertFalse(g(screenFrame: .init(x: 0, y: 0, width: 1600, height: 900), x: 1600, y: 400)) // right + XCTAssertTrue(g(screenFrame: .init(x: 0, y: 0, width: 1600, height: 900), x: 800, y: 900)) // top + } + +} diff --git a/SlimHUDUITests/Utils/UITestsUtils.swift b/SlimHUDUITests/Utils/UITestsUtils.swift index 03582b87..0d567421 100644 --- a/SlimHUDUITests/Utils/UITestsUtils.swift +++ b/SlimHUDUITests/Utils/UITestsUtils.swift @@ -36,4 +36,63 @@ class UITestsUtils: XCTestCase { || app.windows.containing(.image, identifier: "key 2").element.waitForExistence(timeout: 1) || app.windows.containing(.image, identifier: "key 3").element.waitForExistence(timeout: 1) } + + public func getWindowEdge(app: XCUIApplication) -> Position { + let barFrame = findBarFrame(app) + let screenFrame = getScreenSize(app) + let x = barFrame.origin.x + let y = barFrame.origin.y // starting from top: 0, to bottom: screenFrame.height + if h(screenFrame: screenFrame, x: x, y: screenFrame.height-y) { + if g(screenFrame: screenFrame, x: x, y: screenFrame.height-y) { + return .left + } else { + return .bottom + } + } else { + if g(screenFrame: screenFrame, x: x, y: screenFrame.height-y) { + return .top + } else { + return .right + } + } + } + + // -900x/1600 + 900 > y + func h(screenFrame: CGRect, x: CGFloat, y: CGFloat) -> Bool { + return -screenFrame.height * x / screenFrame.width + screenFrame.height > y + } + + // 900x/1600 > y + func g(screenFrame: CGRect, x: CGFloat, y: CGFloat) -> Bool { + return screenFrame.height * x / screenFrame.width < y + } + + let KEYS = ["volume no", "volume 0", "volume 1", "volume 2", "volume 3", "sun 0", "sun 1", "sun 2", "sun 3", "key 0", "key 1", "key 2", "key 3"] + + private func findBarFrame(_ app: XCUIApplication) -> CGRect { + for key in KEYS { + if app.windows.containing(.image, identifier: key).children(matching: .any).allElementsBoundByIndex.count > 0 { + return app.windows.containing(.image, identifier: key).children(matching: .any).element.frame + } + } + XCTFail("Could not find bar frame") + return .null + } + + private func getScreenSize(_ app: XCUIApplication) -> CGRect { + for key in KEYS { + if app.windows.containing(.image, identifier: key).allElementsBoundByIndex.count > 0 { + return app.windows.containing(.image, identifier: key).element.frame + } + } + XCTFail("Could not find bar frame") + return .null + } + + enum Position: String { + case left + case right + case bottom + case top + } } diff --git a/sonar-project.properties b/sonar-project.properties index 771f7118..8ceb4ec4 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,4 +1,4 @@ -sonar.projectKey=alexpera_slimhud +sonar.projectKey=AlexPerathoner_SlimHUD sonar.organization=alexperathoner sonar.projectName=SlimHUD