From c991e9e3bd93a282af58004f097fa4eed557e9cb Mon Sep 17 00:00:00 2001 From: Jack Chen <76423ok@gmail.com> Date: Wed, 14 Sep 2022 01:51:13 +0800 Subject: [PATCH 1/5] container view add width constraint related to its super view --- WordPress/Classes/ViewRelated/Views/NoResults.storyboard | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Views/NoResults.storyboard b/WordPress/Classes/ViewRelated/Views/NoResults.storyboard index 333e0be0659e..2022f5d310dd 100644 --- a/WordPress/Classes/ViewRelated/Views/NoResults.storyboard +++ b/WordPress/Classes/ViewRelated/Views/NoResults.storyboard @@ -1,9 +1,9 @@ - + - + @@ -92,6 +92,7 @@ + From 951bf64cd184ddb4675a327caf7d9d2fe6212680 Mon Sep 17 00:00:00 2001 From: Jack Chen <76423ok@gmail.com> Date: Sun, 18 Sep 2022 23:06:30 +0800 Subject: [PATCH 2/5] add unit tests for testing label width in `NoResultsViewController` --- WordPress/WordPress.xcodeproj/project.pbxproj | 12 ++ .../NoResultsViewControllerTests.swift | 109 ++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 WordPress/WordPressTest/ViewRelated/Views/Controllers/NoResultsViewControllerTests.swift diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index b96a894a4fd8..604b9f2c5119 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -2120,6 +2120,7 @@ AB2211D225ED68E300BF72FC /* CommentServiceRemoteFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB2211D125ED68E300BF72FC /* CommentServiceRemoteFactory.swift */; }; AB2211F425ED6E7A00BF72FC /* CommentServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB2211F325ED6E7A00BF72FC /* CommentServiceTests.swift */; }; AB758D9E25EFDF9C00961C0B /* LikesListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB758D9D25EFDF9C00961C0B /* LikesListController.swift */; }; + ACACE3AE28D729FA000992F9 /* NoResultsViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACACE3AD28D729FA000992F9 /* NoResultsViewControllerTests.swift */; }; ACBAB5FE0E121C7300F38795 /* PostSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ACBAB5FD0E121C7300F38795 /* PostSettingsViewController.m */; }; ADF544C2195A0F620092213D /* CustomHighlightButton.m in Sources */ = {isa = PBXBuildFile; fileRef = ADF544C1195A0F620092213D /* CustomHighlightButton.m */; }; AE2F3125270B6DA000B2A9C2 /* Scanner+QuotedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE2F3124270B6DA000B2A9C2 /* Scanner+QuotedText.swift */; }; @@ -7029,6 +7030,7 @@ AB2211F325ED6E7A00BF72FC /* CommentServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentServiceTests.swift; sourceTree = ""; }; AB390AA9C94F16E78184E9D1 /* Pods_WordPressScreenshotGeneration.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WordPressScreenshotGeneration.framework; sourceTree = BUILT_PRODUCTS_DIR; }; AB758D9D25EFDF9C00961C0B /* LikesListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LikesListController.swift; sourceTree = ""; }; + ACACE3AD28D729FA000992F9 /* NoResultsViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoResultsViewControllerTests.swift; sourceTree = ""; }; ACBAB5FC0E121C7300F38795 /* PostSettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostSettingsViewController.h; sourceTree = ""; usesTabs = 0; }; ACBAB5FD0E121C7300F38795 /* PostSettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PostSettingsViewController.m; sourceTree = ""; usesTabs = 0; }; ADE06D6829F9044164BBA5AB /* Pods-WordPressIntents.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressIntents.release.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressIntents/Pods-WordPressIntents.release.xcconfig"; sourceTree = ""; }; @@ -11155,6 +11157,7 @@ 732A4738218786F30015DA74 /* Views */ = { isa = PBXGroup; children = ( + ACACE3AF28D76A62000992F9 /* Controllers */, 732A473B218787500015DA74 /* WPRichText */, ); name = Views; @@ -13310,6 +13313,14 @@ path = Blog; sourceTree = ""; }; + ACACE3AF28D76A62000992F9 /* Controllers */ = { + isa = PBXGroup; + children = ( + ACACE3AD28D729FA000992F9 /* NoResultsViewControllerTests.swift */, + ); + path = Controllers; + sourceTree = ""; + }; B0088A8F283D68B1008C9676 /* Stats Revamp v2 */ = { isa = PBXGroup; children = ( @@ -20702,6 +20713,7 @@ DC06DFF927BD52BE00969974 /* WeeklyRoundupBackgroundTaskTests.swift in Sources */, 24C69A8B2612421900312D9A /* UserSettingsTests.swift in Sources */, 8B6BD55024293FBE00DB8F28 /* PrepublishingNudgesViewControllerTests.swift in Sources */, + ACACE3AE28D729FA000992F9 /* NoResultsViewControllerTests.swift in Sources */, 8BFE36FF230F1C850061EBA8 /* AbstractPost+fixLocalMediaURLsTests.swift in Sources */, 08A2AD791CCED2A800E84454 /* PostTagServiceTests.m in Sources */, F543AF5723A84E4D0022F595 /* PublishSettingsControllerTests.swift in Sources */, diff --git a/WordPress/WordPressTest/ViewRelated/Views/Controllers/NoResultsViewControllerTests.swift b/WordPress/WordPressTest/ViewRelated/Views/Controllers/NoResultsViewControllerTests.swift new file mode 100644 index 000000000000..5c1a21b7f0f2 --- /dev/null +++ b/WordPress/WordPressTest/ViewRelated/Views/Controllers/NoResultsViewControllerTests.swift @@ -0,0 +1,109 @@ +// +// NoResultsViewControllerTests.swift +// WordPressTest +// +// Created by Jack Chen on 2022/9/18. +// Copyright © 2022 WordPress. All rights reserved. +// + +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 + } + + 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 < 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 < 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) + } +} From fffffb630ea9ae2d8bc9fb57a3d13fd25aadb523 Mon Sep 17 00:00:00 2001 From: Jack Chen <76423ok@gmail.com> Date: Fri, 23 Sep 2022 11:40:16 +0800 Subject: [PATCH 3/5] Wipe out the header of `NoResultsViewControllerTests` --- .../Views/Controllers/NoResultsViewControllerTests.swift | 8 -------- 1 file changed, 8 deletions(-) diff --git a/WordPress/WordPressTest/ViewRelated/Views/Controllers/NoResultsViewControllerTests.swift b/WordPress/WordPressTest/ViewRelated/Views/Controllers/NoResultsViewControllerTests.swift index 5c1a21b7f0f2..eea0bd3c65e3 100644 --- a/WordPress/WordPressTest/ViewRelated/Views/Controllers/NoResultsViewControllerTests.swift +++ b/WordPress/WordPressTest/ViewRelated/Views/Controllers/NoResultsViewControllerTests.swift @@ -1,11 +1,3 @@ -// -// NoResultsViewControllerTests.swift -// WordPressTest -// -// Created by Jack Chen on 2022/9/18. -// Copyright © 2022 WordPress. All rights reserved. -// - import XCTest @testable import WordPress From b89e278ee324b0e9a78ea5c113da9c5395f8bf89 Mon Sep 17 00:00:00 2001 From: Jack Chen <76423ok@gmail.com> Date: Wed, 28 Sep 2022 10:11:09 +0800 Subject: [PATCH 4/5] tweak noResultView horizontal layout margin from 0 to 20 --- .../ViewRelated/Views/NoResults.storyboard | 20 +++++++++---------- .../NoResultsViewControllerTests.swift | 13 ++++++------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Views/NoResults.storyboard b/WordPress/Classes/ViewRelated/Views/NoResults.storyboard index 2022f5d310dd..24cdd18badfd 100644 --- a/WordPress/Classes/ViewRelated/Views/NoResults.storyboard +++ b/WordPress/Classes/ViewRelated/Views/NoResults.storyboard @@ -1,9 +1,9 @@ - + - + @@ -20,7 +20,7 @@ - + @@ -39,19 +39,19 @@ - + - + - + @@ -59,13 +59,13 @@ - +