Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

found (extension .WrapperView instead of (extension in .WrapperView) for UIViewRepresentable #221

Open
bitsmakerde opened this issue Jan 8, 2023 · 2 comments
Labels
more info needed The progress is halted due to insufficient information

Comments

@bitsmakerde
Copy link

@nalexn

after switching to the version 0.9.3 from 0.9.2 I get this error

import XCTest
import ViewInspector
import AVFoundation
import SwiftUI
@testable import BusinessPhotoApp

class CameraControllerTests: XCTestCase {
	func testViewLoad_shouldNotCrash() throws {
		let (sut, _) = makeSUT()
		XCTAssertNotNil(sut)
	}

	func testViewLoad_renderAVCaptureVideoPreviewLayer() throws {
		var (sut, viewModel) = makeSUT()

		let exp = sut.on(\.didAppear) { view in
			let uiView = try view.view(CameraDeviceController.self).actualView().uiView()

			XCTAssertEqual(uiView.layer.sublayers?.first, viewModel.preview)
		}

		ViewHosting.host(view: sut)
		wait(for: [exp], timeout: 0.1)
	}

	// MARK: - helper

	func makeSUT() -> (sut: CameraDeviceController.WrapperView, viewModel: CameraDeviceViewModel) {
		let cameraDeviceService = CameraDeviceService(
			cameraAccessDelegate: CameraAccessNavigationAdapter()
		)
		let cameraDeviceViewModel = CameraDeviceViewModel(preview: CALayer(layer: Text("hallo")))
		let cameraDeviceStore = CameraDeviceStore(cameraDeviceViewModel: cameraDeviceViewModel)
		let sut = CameraDeviceController.WrapperView(
			cameraDeviceService: cameraDeviceService,
			cameraDeviceViewModel: cameraDeviceViewModel,
			cameraDeviceStore: cameraDeviceStore
		)

		return (sut: sut, viewModel: cameraDeviceViewModel)
	}
}

extension CameraDeviceController {
	struct WrapperView: View {
		var didAppear: ((Self) -> Void)?
		let cameraDeviceService: CameraDeviceService
		let cameraDeviceViewModel: CameraDeviceViewModel
		let cameraDeviceStore: CameraDeviceStore

		var body: some View {
			CameraDeviceController(cameraDeviceStore: cameraDeviceStore)
				.onAppear {
					DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
						didAppear?(self)
					}
				}
		}
	}
}

Here my CameraDeviceController which use UIViewRepresentable

import SwiftUI
import AVFoundation

struct CameraDeviceController: UIViewRepresentable {
	@ObservedObject var cameraDeviceStore: CameraDeviceStore

	func makeUIView(context: Context) -> UIView {
		let view = UIView(frame: UIScreen.main.bounds)

		view.layer.addSublayer(cameraDeviceStore.cameraDeviceViewModel.preview)

		return view
	}

	func updateUIView(_ uiView: UIView, context: Context) {}
}

@nalexn
Copy link
Owner

nalexn commented Jan 8, 2023

I had to refactor your code to remove references to Service, ViewModel, and Store objects for which you didn't provide the source. Those objects didn't seem essential for the reproduction of the failure, however, the resulting test succeeds for me, I don't get any error:

class CameraControllerTests: XCTestCase {

    func testViewLoad_renderAVCaptureVideoPreviewLayer() throws {
        var sut = CameraDeviceController.WrapperView()
        let exp = sut.on(\.didAppear) { view in
            let uiView = try view.view(CameraDeviceController.self).actualView().uiView()
            XCTAssertEqual(uiView.tag, 422)
        }
        ViewHosting.host(view: sut)
        wait(for: [exp], timeout: 0.1)
    }
}

struct CameraDeviceController: UIViewRepresentable {

    func makeUIView(context: Context) -> UIView {
        let view = UIView(frame: UIScreen.main.bounds)
        view.tag = 422
        return view
    }

    func updateUIView(_ uiView: UIView, context: Context) {}
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
extension CameraDeviceController {
    struct WrapperView: View {
        var didAppear: ((Self) -> Void)?

        var body: some View {
            CameraDeviceController()
                .onAppear {
                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
                        didAppear?(self)
                    }
                }
        }
    }
}

Could you run this test and see if the error pops up or not? The error message you posted originally here:

found (extension in BusinessPhotoAppTests):BusinessPhotoApp.CameraDeviceController.WrapperView instead of (extension in BusinessPhotoAppTests):BusinessPhotoApp.CameraDeviceController.WrapperView

I haven't seen this pattern of type prefixes before ((extension in <app>):), could you share details of your environment, that is, Xcode version, Swift version, or any other note about your setup if it's untraditional in any way

@bitsmakerde
Copy link
Author

@nalexn

Thank you for the fast response. Your code works by me. I added @available but nothing change.

Here my setup:

Xcode Version 14.2 (14C18)
Swift 5
Dev Target 16.1

In the worst case, I will give you access to the project. but before I muss bring all over tests to green ;-)

@nalexn nalexn added the help wanted Extra attention is needed label Jan 14, 2023
@nalexn nalexn added more info needed The progress is halted due to insufficient information and removed help wanted Extra attention is needed labels Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed The progress is halted due to insufficient information
Projects
None yet
Development

No branches or pull requests

2 participants