-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19305 from ipalm0423/fix/19244-19246-fix-oversize…
…-label-on-NoResultVC-for-iPad Fix oversize label in no result side menu on iPad
- Loading branch information
Showing
4 changed files
with
125 additions
and
9 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
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
102 changes: 102 additions & 0 deletions
102
WordPress/WordPressTest/ViewRelated/Views/Controllers/NoResultsViewControllerTests.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,102 @@ | ||
import XCTest | ||
@testable import WordPress | ||
|
||
class NoResultsViewControllerTests: XCTestCase { | ||
|
||
private enum Constants { | ||
static let shortText = "This is a text" | ||
static let longText = """ | ||
This is a long Text. This is a long Text. This is a long Text. This is a long Text. This is a long Text. | ||
This is a long Text. This is a long Text. This is a long Text. This is a long Text. This is a long Text. | ||
This is a long Text. This is a long Text. This is a long Text. This is a long Text. This is a long Text. | ||
""" | ||
static let iPhoneSeSize = CGSize(width: 320, height: 568) | ||
static let iPadProSize = CGSize(width: 1024, height: 1366) | ||
static let resultViewMaxWidth: CGFloat = 360 | ||
static let resultViewHorizontalMargin: CGFloat = 20 | ||
} | ||
|
||
private var resultViewController: NoResultsViewController! | ||
private var parentViewController: UIViewController! | ||
|
||
override func setUpWithError() throws { | ||
self.resultViewController = NoResultsViewController.controller() | ||
self.parentViewController = UIViewController() | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
self.resultViewController = nil | ||
self.parentViewController = nil | ||
} | ||
|
||
func testTitleLabelWidthForLongTextInSmallScreen() { | ||
// Given | ||
let parentViewSize = Constants.iPhoneSeSize | ||
let title = Constants.longText | ||
|
||
// When | ||
parentViewController.view.frame = CGRect(origin: .zero, size: parentViewSize) | ||
resultViewController.configure(title: title) | ||
addResultViewControllerToParent() | ||
|
||
// Then | ||
XCTAssertEqual(resultViewController.titleLabel.text, title) | ||
XCTAssertTrue(resultViewController.titleLabel.frame.width + Constants.resultViewHorizontalMargin * 2 <= parentViewSize.width) | ||
} | ||
|
||
func testTitleLabelWidthForLongTextInLargeScreen() { | ||
// Given | ||
let parentViewSize = Constants.iPadProSize | ||
let title = Constants.longText | ||
|
||
// When | ||
parentViewController.view.frame = CGRect(origin: .zero, size: parentViewSize) | ||
resultViewController.configure(title: title) | ||
addResultViewControllerToParent() | ||
|
||
// Then | ||
XCTAssertEqual(resultViewController.titleLabel.text, title) | ||
XCTAssertTrue(resultViewController.titleLabel.frame.width <= parentViewSize.width) | ||
XCTAssertTrue(resultViewController.titleLabel.frame.width <= Constants.resultViewMaxWidth) | ||
} | ||
|
||
func testSubtitleLabelWidthForLongTextInSmallScreen() { | ||
// Given | ||
let parentViewSize = Constants.iPhoneSeSize | ||
let subtitle = Constants.longText | ||
|
||
// When | ||
parentViewController.view.frame = CGRect(origin: .zero, size: parentViewSize) | ||
resultViewController.configure(title: Constants.shortText, subtitle: subtitle) | ||
addResultViewControllerToParent() | ||
|
||
// Then | ||
XCTAssertEqual(resultViewController.subtitleTextView.text, subtitle) | ||
XCTAssertTrue(resultViewController.subtitleTextView.frame.width + Constants.resultViewHorizontalMargin * 2 <= parentViewSize.width) | ||
} | ||
|
||
func testSubtitleLabelWidthForLongTextInLargeScreen() { | ||
// Given | ||
let parentViewSize = Constants.iPadProSize | ||
let subtitle = Constants.longText | ||
|
||
// When | ||
parentViewController.view.frame = CGRect(origin: .zero, size: parentViewSize) | ||
resultViewController.configure(title: Constants.shortText, subtitle: subtitle) | ||
addResultViewControllerToParent() | ||
|
||
// Then | ||
XCTAssertEqual(resultViewController.subtitleTextView.text, subtitle) | ||
XCTAssertTrue(resultViewController.subtitleTextView.frame.width <= parentViewSize.width) | ||
XCTAssertTrue(resultViewController.subtitleTextView.frame.width <= Constants.resultViewMaxWidth) | ||
} | ||
|
||
} | ||
|
||
private extension NoResultsViewControllerTests { | ||
func addResultViewControllerToParent() { | ||
parentViewController.view.addSubview(resultViewController.view) | ||
resultViewController.view.frame = parentViewController.view.bounds | ||
resultViewController.didMove(toParent: parentViewController) | ||
} | ||
} |