deep-linking-sample/Apps/Wikipedia/WikipediaUnitTests/Code/ArticleViewControllerTests.swift
Javier Cicchelli 9bcdaa697b [Setup] Basic project structure (#1)
This PR contains all the work related to setting up this project as required to implement the [Assignment](https://repo.rock-n-code.com/rock-n-code/deep-linking-assignment/wiki/Assignment) on top, as intended.

To summarise this work:
- [x] created a new **Xcode** project;
- [x] cloned the `Wikipedia` app and inserted it into the **Xcode** project;
- [x] created the `Locations` app and also, its `Libraries` package;
- [x] created the `Shared` package to share dependencies between the apps;
- [x] added a `Makefile` file and implemented some **environment** and **help** commands.

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: rock-n-code/deep-linking-assignment#1
2023-04-08 18:37:13 +00:00

60 lines
2.1 KiB
Swift

@testable import Wikipedia
import XCTest
private class MockSchemeHandler: SchemeHandler {
var accessed = false
required init(scheme: String, session: Session) {
super.init(scheme: scheme, session: session)
let didReceiveDataCallback: ((WKURLSchemeTask, Data) -> Void)? = { [weak self] _, _ in
self?.accessed = true
}
self.didReceiveDataCallback = didReceiveDataCallback
}
}
class ArticleViewControllerTests: XCTestCase {
let timeout: TimeInterval = 10
override func setUp() {
super.setUp()
LSNocilla.sharedInstance().start()
ArticleTestHelpers.stubCompleteMobileHTMLResponse(inBundle: wmf_bundle())
}
override func tearDown() {
super.tearDown()
LSNocilla.sharedInstance().stop()
}
func testArticleVCAccessesSchemeHandler() throws {
// test that articleVC converts articleURL to proper scheme and sets up SchemeHandler to ensure it is accessed during a load
let dataStore = MWKDataStore.temporary()
let theme = Theme.light
let url = URL(string: "https://en.wikipedia.org/wiki/Dog")!
let schemeHandler = MockSchemeHandler(scheme: "app", session: dataStore.session)
guard let articleVC = ArticleViewController(articleURL: url, dataStore: dataStore, theme: theme, schemeHandler: schemeHandler) else {
XCTFail("Failure initializing Article View Controller")
return
}
let setupExpectation = expectation(description: "Waiting for article initial setup call")
articleVC.initialSetupCompletion = {
setupExpectation.fulfill()
XCTAssert(schemeHandler.accessed, "SchemeHandler was not accessed during article load.")
UIApplication.shared.workaroundKeyWindow?.rootViewController = nil
dataStore.clearTemporaryCache()
dataStore.session.teardown()
}
UIApplication.shared.workaroundKeyWindow?.rootViewController = articleVC
wait(for: [setupExpectation], timeout: timeout)
}
}