diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..775cd68 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,36 @@ +name: Build + +on: + push: + branches: [main] + pull_request: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: macos-15 + steps: + - uses: actions/checkout@v4 + + - name: Build + run: | + xcodebuild build \ + -project TimeLapze.xcodeproj \ + -scheme ScreenTimeLapse \ + -destination 'platform=macOS' \ + -skipPackagePluginValidation \ + CODE_SIGNING_ALLOWED=NO + + - name: Unit Tests + run: | + xcodebuild test \ + -project TimeLapze.xcodeproj \ + -scheme Test \ + -destination 'platform=macOS' \ + -only-testing:TimeLapzeTests \ + -skipPackagePluginValidation \ + CODE_SIGNING_ALLOWED=NO diff --git a/TimeLapzeTests/RecorderViewModelTests.swift b/TimeLapzeTests/RecorderViewModelTests.swift index 4a95656..93b6c04 100644 --- a/TimeLapzeTests/RecorderViewModelTests.swift +++ b/TimeLapzeTests/RecorderViewModelTests.swift @@ -8,15 +8,27 @@ import XCTest final class RecorderViewModelTests: XCTestCase { // If a device is connected, then cameras should empty func testDeviceConnectedNotification() throws { + let discovery = AVCaptureDevice.DiscoverySession( + deviceTypes: [.builtInWideAngleCamera, .external], mediaType: .video, + position: .unspecified) + let expectedCameraCount = discovery.devices.count + + try XCTSkipIf( + expectedCameraCount == 0, + "This environment does not expose any video capture devices." + ) + let viewModel = RecorderViewModel() let expectation = XCTestExpectation(description: "Device connected should refresh camera list.") NotificationCenter.default.post(name: .AVCaptureDeviceWasConnected, object: nil) DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - XCTAssertFalse( - viewModel.cameras.isEmpty, - "Cameras should not be empty after device connection notification.") + XCTAssertEqual( + viewModel.cameras.count, + expectedCameraCount, + "Camera list should match the devices reported by AVFoundation after refresh." + ) expectation.fulfill() }