This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enabled subclassing on BeagleScreenViewControllers to observe l…
…ifecycle events as well as server driven state events without having to use a navigation controller. (#52)
- Loading branch information
1 parent
e3a36ca
commit 670c1cf
Showing
4 changed files
with
106 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
Sources/Beagle/BeagleTests/Renderer/CustomBeagleScreenViewControllerTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
/* | ||
* Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import XCTest | ||
import SnapshotTesting | ||
@testable import Beagle | ||
|
||
final class CustomBeagleScreenViewControllerTests: EnvironmentTestCase { | ||
|
||
func testLifecycleMethods() { | ||
let viewController = CustomBeagleScreenViewControllerStub(ComponentStub(), controllerId: #function) | ||
viewController.viewDidAppearExpectation.expectedFulfillmentCount = 1 | ||
viewController.viewWillAppearExpectation.expectedFulfillmentCount = 1 | ||
viewController.viewDidDisappearExpectation.expectedFulfillmentCount = 1 | ||
|
||
viewController.viewWillAppear(true) | ||
viewController.viewDidAppear(true) | ||
viewController.viewDidDisappear(true) | ||
|
||
wait( | ||
for: [ | ||
viewController.viewDidAppearExpectation, | ||
viewController.viewWillAppearExpectation, | ||
viewController.viewDidDisappearExpectation | ||
], | ||
timeout: 0.1 | ||
) | ||
} | ||
|
||
func testScreenDidChangeState() { | ||
let viewController = CustomBeagleScreenViewControllerStub(ComponentStub(), controllerId: #function) | ||
viewController.didChangeStateExpectation.expectedFulfillmentCount = 1 | ||
|
||
viewController.didChangeState(.started) | ||
|
||
wait(for: [viewController.didChangeStateExpectation], timeout: 0.1) | ||
} | ||
|
||
} | ||
|
||
|
||
class CustomBeagleScreenViewControllerStub: BeagleScreenViewController { | ||
|
||
private(set) var viewWillAppearExpectation: XCTestExpectation = .init(description: "viewWillAppearExpectation") | ||
private(set) var viewDidAppearExpectation: XCTestExpectation = .init(description: "viewDidAppearExpectation") | ||
private(set) var viewDidDisappearExpectation: XCTestExpectation = .init(description: "viewDidDisappearExpectation") | ||
private(set) var didChangeStateExpectation: XCTestExpectation = .init(description: "didChangeStateExpectation") | ||
|
||
public override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
viewWillAppearExpectation.fulfill() | ||
} | ||
|
||
public override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
viewDidAppearExpectation.fulfill() | ||
} | ||
|
||
public override func viewDidDisappear(_ animated: Bool) { | ||
super.viewDidDisappear(animated) | ||
viewDidDisappearExpectation.fulfill() | ||
} | ||
|
||
override func didChangeState(_ state: ServerDrivenState) { | ||
super.didChangeState(state) | ||
didChangeStateExpectation.fulfill() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters