-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cover control components with screenshots tests (#51)
* APPS-7535 add snapshot tests to control components * APPS-7535 add snapshopping image files to project * Run swiftformat * APPS-7535 remove unnecessary parameters * Run swiftformat * APPS-7535 encapsulate duplicated code * Run swiftformat Co-authored-by: cbarcom <cbarcom@users.noreply.github.com>
- Loading branch information
Showing
28 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,200 @@ | ||
// | ||
// ControlsTests.swift | ||
// | ||
// Made with ❤️ by Novum | ||
// | ||
// Copyright © 2020 Telefonica. All rights reserved. | ||
// | ||
|
||
import Mistica | ||
import SnapshotTesting | ||
import XCTest | ||
|
||
final class ControlsTests: XCTestCase { | ||
override class func setUp() { | ||
super.setUp() | ||
|
||
isRecording = false | ||
} | ||
|
||
// MARK: - Switch Style | ||
|
||
func testSwitchDefaultState() { | ||
assertSnapshotForAllBrands( | ||
as: .image, | ||
viewBuilder: makeSwitchTemplate(isOn: false) | ||
) | ||
} | ||
|
||
func testSwitchOnState() { | ||
assertSnapshotForAllBrands( | ||
as: .image, | ||
viewBuilder: makeSwitchTemplate(isOn: true) | ||
) | ||
} | ||
|
||
// MARK: - UISegmentedControl Style | ||
|
||
func testSegmentedControl() { | ||
assertSnapshotForAllBrands( | ||
as: .image, | ||
viewBuilder: makeSegmentedControlTemplate() | ||
) | ||
} | ||
|
||
// MARK: - UITabBar Style | ||
|
||
func testTabBarControl() { | ||
assertSnapshotForAllBrands( | ||
as: .image, | ||
viewBuilder: makeTabBarTemplate() | ||
) | ||
} | ||
|
||
// MARK: - UIPageControl Style | ||
|
||
func testPageControl() { | ||
assertSnapshotForAllBrands( | ||
as: .image, | ||
viewBuilder: makePageControlTemplate() | ||
) | ||
} | ||
|
||
// MARK: - UISegmentedControl Behaviour | ||
|
||
func testSegmentedControlChangeSelectedSegment() { | ||
MisticaConfig.brandStyle = .o2 | ||
MisticaConfig.styleControls([.segmentedControl]) | ||
|
||
let segmentedControl = createSegmentControl() | ||
segmentedControl.selectedSegmentIndex = 1 | ||
|
||
assertSnapshot( | ||
matching: segmentedControl, | ||
as: .image(size: segmentedControl.intrinsicContentSize), | ||
named: "assertInitialState" | ||
) | ||
|
||
segmentedControl.selectedSegmentIndex = 3 | ||
|
||
assertSnapshot( | ||
matching: segmentedControl, | ||
as: .image(size: segmentedControl.intrinsicContentSize), | ||
named: "finalState" | ||
) | ||
} | ||
|
||
// MARK: - UITabBarControl Behaviour | ||
|
||
func testTabBarControlChangeSelectedItem() { | ||
MisticaConfig.brandStyle = .vivo | ||
MisticaConfig.styleControls([.tabBar]) | ||
|
||
let tabBarController = createTabBarController() | ||
tabBarController.selectedIndex = 1 | ||
|
||
assertSnapshot( | ||
matching: tabBarController, | ||
as: .image(size: CGSize(width: 420, height: 60)), | ||
named: "assertInitialState" | ||
) | ||
|
||
tabBarController.selectedIndex = 2 | ||
|
||
assertSnapshot( | ||
matching: tabBarController, | ||
as: .image(size: CGSize(width: 420, height: 60)), | ||
named: "finalState" | ||
) | ||
} | ||
|
||
// MARK: - UIPageControl Behaviour | ||
|
||
func testPageControlChangeCurrentPage() { | ||
MisticaConfig.brandStyle = .o2Classic | ||
MisticaConfig.styleControls([.pageControl]) | ||
|
||
let pageControl = UIPageControl() | ||
pageControl.numberOfPages = 5 | ||
pageControl.currentPage = 3 | ||
|
||
assertSnapshot( | ||
matching: pageControl, | ||
as: .image(size: pageControl.intrinsicContentSize), | ||
named: "assertInitialState" | ||
) | ||
|
||
pageControl.currentPage = 1 | ||
|
||
assertSnapshot( | ||
matching: pageControl, | ||
as: .image(size: pageControl.intrinsicContentSize), | ||
named: "finalState" | ||
) | ||
} | ||
} | ||
|
||
private extension ControlsTests { | ||
func makeSwitchTemplate(isOn: Bool) -> UIView { | ||
MisticaConfig.styleControls([.switch]) | ||
let _switch = UISwitch() | ||
_switch.isOn = isOn | ||
return _switch | ||
} | ||
|
||
func makeSegmentedControlTemplate() -> UIView { | ||
MisticaConfig.styleControls([.segmentedControl]) | ||
|
||
let segmentedControl = createSegmentControl() | ||
segmentedControl.selectedSegmentIndex = 1 | ||
|
||
return segmentedControl | ||
} | ||
|
||
func makeTabBarTemplate() -> UIView { | ||
MisticaConfig.styleControls([.tabBar]) | ||
|
||
let tabBarController = createTabBarController() | ||
tabBarController.selectedIndex = 1 | ||
|
||
return tabBarController.view | ||
} | ||
|
||
func makePageControlTemplate() -> UIView { | ||
MisticaConfig.styleControls([.pageControl]) | ||
|
||
let pageControl = UIPageControl() | ||
pageControl.numberOfPages = 5 | ||
pageControl.currentPage = 3 | ||
|
||
return pageControl | ||
} | ||
|
||
func createSegmentControl() -> UISegmentedControl { | ||
let segmentedControl = UISegmentedControl() | ||
segmentedControl.insertSegment(withTitle: "Segment 1", at: 0, animated: true) | ||
segmentedControl.insertSegment(withTitle: "Segment 2", at: 1, animated: true) | ||
segmentedControl.insertSegment(withTitle: "Segment 3", at: 2, animated: true) | ||
segmentedControl.insertSegment(withTitle: "Segment 4", at: 3, animated: true) | ||
|
||
return segmentedControl | ||
} | ||
|
||
func createTabBarController() -> UITabBarController { | ||
var tabs = [UIViewController]() | ||
for i in 0 ..< 3 { | ||
let tabBarItem = UITabBarItem(tabBarSystemItem: .contacts, tag: i) | ||
tabBarItem.title = "Tab \(i)" | ||
|
||
let viewController = UIViewController() | ||
viewController.tabBarItem = tabBarItem | ||
|
||
tabs.append(viewController) | ||
} | ||
|
||
let tabBarController = UITabBarController() | ||
tabBarController.viewControllers = tabs | ||
|
||
return tabBarController | ||
} | ||
} |
Binary file added
BIN
+1.3 KB
...icaTests/UI/__Snapshots__/ControlsTests/testPageControl.with-movistar-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.29 KB
...s/MisticaTests/UI/__Snapshots__/ControlsTests/testPageControl.with-o2-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.3 KB
...caTests/UI/__Snapshots__/ControlsTests/testPageControl.with-o2Classic-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.3 KB
...MisticaTests/UI/__Snapshots__/ControlsTests/testPageControl.with-vivo-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.3 KB
...apshots__/ControlsTests/testPageControlChangeCurrentPage.assertInitialState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.28 KB
.../UI/__Snapshots__/ControlsTests/testPageControlChangeCurrentPage.finalState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.9 KB
...sts/UI/__Snapshots__/ControlsTests/testSegmentedControl.with-movistar-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11 KB
...ticaTests/UI/__Snapshots__/ControlsTests/testSegmentedControl.with-o2-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.9 KB
...ts/UI/__Snapshots__/ControlsTests/testSegmentedControl.with-o2Classic-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.1 KB
...caTests/UI/__Snapshots__/ControlsTests/testSegmentedControl.with-vivo-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.8 KB
.../ControlsTests/testSegmentedControlChangeSelectedSegment.assertInitialState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.1 KB
...pshots__/ControlsTests/testSegmentedControlChangeSelectedSegment.finalState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.76 KB
...s/UI/__Snapshots__/ControlsTests/testSwitchDefaultState.with-movistar-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.76 KB
...caTests/UI/__Snapshots__/ControlsTests/testSwitchDefaultState.with-o2-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.76 KB
.../UI/__Snapshots__/ControlsTests/testSwitchDefaultState.with-o2Classic-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.76 KB
...Tests/UI/__Snapshots__/ControlsTests/testSwitchDefaultState.with-vivo-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.83 KB
...aTests/UI/__Snapshots__/ControlsTests/testSwitchOnState.with-movistar-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.72 KB
...MisticaTests/UI/__Snapshots__/ControlsTests/testSwitchOnState.with-o2-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.75 KB
...Tests/UI/__Snapshots__/ControlsTests/testSwitchOnState.with-o2Classic-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.83 KB
...sticaTests/UI/__Snapshots__/ControlsTests/testSwitchOnState.with-vivo-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.9 KB
...aTests/UI/__Snapshots__/ControlsTests/testTabBarControl.with-movistar-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.2 KB
...MisticaTests/UI/__Snapshots__/ControlsTests/testTabBarControl.with-o2-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.2 KB
...Tests/UI/__Snapshots__/ControlsTests/testTabBarControl.with-o2Classic-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.1 KB
...sticaTests/UI/__Snapshots__/ControlsTests/testTabBarControl.with-vivo-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.41 KB
...hots__/ControlsTests/testTabBarControlChangeSelectedItem.assertInitialState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.45 KB
.../__Snapshots__/ControlsTests/testTabBarControlChangeSelectedItem.finalState.png
Oops, something went wrong.