Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Site Name] Adjusts design picker buttons for treatment variation #18397

Merged
merged 10 commits into from
Apr 21, 2022
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import UIKit

class SiteDesignPreviewViewController: TemplatePreviewViewController {
private let createsSite: Bool
let completion: SiteDesignStep.SiteDesignSelection
let siteDesign: RemoteSiteDesign

init(siteDesign: RemoteSiteDesign, selectedPreviewDevice: PreviewDevice?, onDismissWithDeviceSelected: ((PreviewDevice) -> ())?, completion: @escaping SiteDesignStep.SiteDesignSelection) {
init(siteDesign: RemoteSiteDesign, selectedPreviewDevice: PreviewDevice?, createsSite: Bool, onDismissWithDeviceSelected: ((PreviewDevice) -> ())?, completion: @escaping SiteDesignStep.SiteDesignSelection) {
self.completion = completion
self.siteDesign = siteDesign
self.createsSite = createsSite
super.init(demoURL: siteDesign.demoURL, selectedPreviewDevice: selectedPreviewDevice, onDismissWithDeviceSelected: onDismissWithDeviceSelected)
delegate = self
title = NSLocalizedString("Preview", comment: "Title for screen to preview a selected homepage design")
title = TextContent.previewTitle
}

required init?(coder: NSCoder) {
Expand All @@ -19,6 +21,17 @@ class SiteDesignPreviewViewController: TemplatePreviewViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = CollapsableHeaderViewController.closeButton(target: self, action: #selector(closeButtonTapped))
setPrimaryActionButtonTitle()
}

private func setPrimaryActionButtonTitle() {
primaryActionButton.setTitle(createsSite ? TextContent.createSiteButton : TextContent.chooseButton, for: .normal)
}

private enum TextContent {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, good suggestion @Gio2018 and implementation @antonis. Makes things a lot cleaner!

static let previewTitle = NSLocalizedString("Preview", comment: "Title for screen to preview a selected homepage design.")
static let createSiteButton = NSLocalizedString("Create Site", comment: "Title for the button to progress with creating the site with the selected design.")
static let chooseButton = NSLocalizedString("Choose", comment: "Title for the button to progress with the selected site homepage design.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SiteDesignSection: CategorySection {

class SiteDesignContentCollectionViewController: FilterableCategoriesViewController, UIPopoverPresentationControllerDelegate {
typealias TemplateGroup = SiteDesignRequest.TemplateGroup
private let createsSite: Bool
private let templateGroups: [TemplateGroup] = [.stable, .singlePage]

let completion: SiteDesignStep.SiteDesignSelection
Expand Down Expand Up @@ -55,15 +56,16 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
return sections[sectionIndex].designs[position]
}

init(_ completion: @escaping SiteDesignStep.SiteDesignSelection) {
init(createsSite: Bool, _ completion: @escaping SiteDesignStep.SiteDesignSelection) {
self.completion = completion
self.createsSite = createsSite

super.init(
analyticsLocation: "site_creation",
mainTitle: NSLocalizedString("Choose a design", comment: "Title for the screen to pick a design and homepage for a site."),
prompt: NSLocalizedString("Pick your favorite homepage layout. You can edit and customize it later.", comment: "Prompt for the screen to pick a design and homepage for a site."),
primaryActionTitle: NSLocalizedString("Choose", comment: "Title for the button to progress with the selected site homepage design"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comments here: the comment should have a period, and since this file has quite a few hardcoded strings, wondering if we can group them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above handled with babc542. Thank you for the feedback 🙇

secondaryActionTitle: NSLocalizedString("Preview", comment: "Title for button to preview a selected homepage design")
mainTitle: TextContent.mainTitle,
prompt: TextContent.subtitle,
primaryActionTitle: createsSite ? TextContent.createSiteButton : TextContent.chooseButton,
secondaryActionTitle: TextContent.previewButton
)
}

Expand All @@ -73,7 +75,7 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl

override func viewDidLoad() {
super.viewDidLoad()
navigationItem.backButtonTitle = NSLocalizedString("Design", comment: "Shortened version of the main title to be used in back navigation")
navigationItem.backButtonTitle = TextContent.backButtonTitle
fetchSiteDesigns()
configureCloseButton()
configureSkipButton()
Expand All @@ -100,7 +102,7 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
}

private func configureSkipButton() {
let skip = UIBarButtonItem(title: NSLocalizedString("Skip", comment: "Continue without making a selection"), style: .done, target: self, action: #selector(skipButtonTapped))
let skip = UIBarButtonItem(title: TextContent.skipButtonTitle, style: .done, target: self, action: #selector(skipButtonTapped))
navigationItem.rightBarButtonItem = skip
}

Expand All @@ -115,7 +117,7 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
return
}

navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Cancel", comment: "Cancel site creation"), style: .done, target: self, action: #selector(closeButtonTapped))
navigationItem.leftBarButtonItem = UIBarButtonItem(title: TextContent.cancelButtonTitle, style: .done, target: self, action: #selector(closeButtonTapped))
}

@objc func skipButtonTapped(_ sender: Any) {
Expand Down Expand Up @@ -151,7 +153,7 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
override func secondaryActionSelected(_ sender: Any) {
guard let design = selectedDesign else { return }

let previewVC = SiteDesignPreviewViewController(siteDesign: design, selectedPreviewDevice: selectedPreviewDevice, onDismissWithDeviceSelected: { [weak self] device in
let previewVC = SiteDesignPreviewViewController(siteDesign: design, selectedPreviewDevice: selectedPreviewDevice, createsSite: createsSite, onDismissWithDeviceSelected: { [weak self] device in
self?.selectedPreviewDevice = device
}, completion: completion)

Expand All @@ -162,10 +164,23 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl

private func handleError(_ error: Error) {
SiteCreationAnalyticsHelper.trackError(error)
let titleText = NSLocalizedString("Unable to load this content right now.", comment: "Informing the user that a network request failed becuase the device wasn't able to establish a network connection.")
let subtitleText = NSLocalizedString("Check your network connection and try again.", comment: "Default subtitle for no-results when there is no connection.")
let titleText = TextContent.errorTitle
let subtitleText = TextContent.errorSubtitle
displayNoResultsController(title: titleText, subtitle: subtitleText, resultsDelegate: self)
}

private enum TextContent {
static let mainTitle = NSLocalizedString("Choose a design", comment: "Title for the screen to pick a design and homepage for a site.")
static let subtitle = NSLocalizedString("Pick your favorite homepage layout. You can edit and customize it later.", comment: "Prompt for the screen to pick a design and homepage for a site.")
static let createSiteButton = NSLocalizedString("Create Site", comment: "Title for the button to progress with creating the site with the selected design.")
static let chooseButton = NSLocalizedString("Choose", comment: "Title for the button to progress with the selected site homepage design.")
static let previewButton = NSLocalizedString("Preview", comment: "Title for button to preview a selected homepage design.")
static let backButtonTitle = NSLocalizedString("Design", comment: "Shortened version of the main title to be used in back navigation.")
static let skipButtonTitle = NSLocalizedString("Skip", comment: "Continue without making a selection.")
static let cancelButtonTitle = NSLocalizedString("Cancel", comment: "Cancel site creation.")
static let errorTitle = NSLocalizedString("Unable to load this content right now.", comment: "Informing the user that a network request failed becuase the device wasn't able to establish a network connection.")
static let errorSubtitle = NSLocalizedString("Check your network connection and try again.", comment: "Default subtitle for no-results when there is no connection.")
}
}

// MARK: - NoResultsViewControllerDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ final class SiteDesignStep: WizardStep {
typealias SiteDesignSelection = (_ design: RemoteSiteDesign?) -> Void
weak var delegate: WizardDelegate?
private let creator: SiteCreator
private let isLastStep: Bool

private(set) lazy var content: UIViewController = {
return SiteDesignContentCollectionViewController { [weak self] (design) in
return SiteDesignContentCollectionViewController(createsSite: isLastStep) { [weak self] (design) in
self?.didSelect(design)
}
}()

init(creator: SiteCreator) {
init(creator: SiteCreator, isLastStep: Bool) {
self.creator = creator
self.isLastStep = isLastStep
}

private func didSelect(_ design: RemoteSiteDesign?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ final class SiteCreationWizardLauncher {
let addressService = DomainsServiceAdapter(managedObjectContext: ContextManager.sharedInstance().mainContext)
return WebAddressStep(creator: self.creator, service: addressService)
case .design:
return SiteDesignStep(creator: self.creator)
// we call dropLast to remove .siteAssembly
let isLastStep = steps.dropLast().last == .design
return SiteDesignStep(creator: self.creator, isLastStep: isLastStep)
case .intent:
return SiteIntentStep(creator: self.creator)
case .name:
Expand Down
4 changes: 4 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,7 @@
C373D6EA280452F6008F8C26 /* SiteIntentDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C373D6E9280452F6008F8C26 /* SiteIntentDataTests.swift */; };
C387B7A22638D66F00BDEF86 /* PostAuthorSelectorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3E2462826277B7700B99EA6 /* PostAuthorSelectorViewController.swift */; };
C38C5D8127F61D2C002F517E /* MenuItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C38C5D8027F61D2C002F517E /* MenuItemTests.swift */; };
C396C80B280F2401006FE7AC /* SiteDesignTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C396C80A280F2401006FE7AC /* SiteDesignTests.swift */; };
C3C39B0726F50D3900B1238D /* WordPressSupportSourceTag+Editor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C39B0626F50D3900B1238D /* WordPressSupportSourceTag+Editor.swift */; };
C3C39B0826F50D3900B1238D /* WordPressSupportSourceTag+Editor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C39B0626F50D3900B1238D /* WordPressSupportSourceTag+Editor.swift */; };
C3DA0EE02807062600DA3250 /* SiteCreationNameTracksEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3DA0EDF2807062600DA3250 /* SiteCreationNameTracksEventTests.swift */; };
Expand Down Expand Up @@ -6913,6 +6914,7 @@
C373D6E628045281008F8C26 /* SiteIntentData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteIntentData.swift; sourceTree = "<group>"; };
C373D6E9280452F6008F8C26 /* SiteIntentDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteIntentDataTests.swift; sourceTree = "<group>"; };
C38C5D8027F61D2C002F517E /* MenuItemTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MenuItemTests.swift; path = Menus/MenuItemTests.swift; sourceTree = "<group>"; };
C396C80A280F2401006FE7AC /* SiteDesignTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteDesignTests.swift; sourceTree = "<group>"; };
C3ABE791263099F7009BD402 /* WordPress 121.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 121.xcdatamodel"; sourceTree = "<group>"; };
C3C39B0626F50D3900B1238D /* WordPressSupportSourceTag+Editor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WordPressSupportSourceTag+Editor.swift"; sourceTree = "<group>"; };
C3DA0EDF2807062600DA3250 /* SiteCreationNameTracksEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteCreationNameTracksEventTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -10531,6 +10533,7 @@
73178C2221BEE09300E37C9A /* SiteCreationDataCoordinatorTests.swift */,
73178C2621BEE09300E37C9A /* SiteCreationHeaderDataTests.swift */,
730354B921C867E500CD18C2 /* SiteCreatorTests.swift */,
C396C80A280F2401006FE7AC /* SiteDesignTests.swift */,
73178C2421BEE09300E37C9A /* SiteSegmentsCellTests.swift */,
73178C2321BEE09300E37C9A /* SiteSegmentsStepTests.swift */,
73178C3421BEE9AC00E37C9A /* TitleSubtitleHeaderTests.swift */,
Expand Down Expand Up @@ -19460,6 +19463,7 @@
748437EE1F1D4A7300E8DDAF /* RichContentFormatterTests.swift in Sources */,
C81CCD6A243AEE1100A83E27 /* TenorAPIResponseTests.swift in Sources */,
8BE7C84123466927006EDE70 /* I18n.swift in Sources */,
C396C80B280F2401006FE7AC /* SiteDesignTests.swift in Sources */,
806E53E427E01CFE0064315E /* DashboardStatsViewModelTests.swift in Sources */,
D88A649E208D82D2008AE9BC /* XCTestCase+Wait.swift in Sources */,
C38C5D8127F61D2C002F517E /* MenuItemTests.swift in Sources */,
Expand Down
76 changes: 76 additions & 0 deletions WordPress/WordPressTest/SiteCreation/SiteDesignTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

import XCTest
@testable import WordPress

class SiteDesignTests: XCTestCase {
private var remoteDesign: RemoteSiteDesign {
let siteDesignPayload = "{\"slug\":\"alves\",\"title\":\"Alves\",\"segment_id\":1,\"categories\":[{\"slug\":\"business\",\"title\":\"Business\",\"description\":\"Business\",\"emoji\":\"💼\"}],\"demo_url\":\"https://public-api.wordpress.com/rest/v1/template/demo/alves/alvesstartermobile.wordpress.com/?language=en\",\"theme\":\"alves\",\"preview\":\"https://s0.wp.com/mshots/v1/public-api.wordpress.com/rest/v1/template/demo/alves/alvesstartermobile.wordpress.com/%3Flanguage%3Den?vpw=1200&vph=1600&w=800&h=1067\",\"preview_tablet\":\"https://s0.wp.com/mshots/v1/public-api.wordpress.com/rest/v1/template/demo/alves/alvesstartermobile.wordpress.com/%3Flanguage%3Den?vpw=800&vph=1066&w=800&h=1067\",\"preview_mobile\":\"https://s0.wp.com/mshots/v1/public-api.wordpress.com/rest/v1/template/demo/alves/alvesstartermobile.wordpress.com/%3Flanguage%3Den?vpw=400&vph=533&w=400&h=534\"}"
return try! JSONDecoder().decode(RemoteSiteDesign.self, from: siteDesignPayload.data(using: .utf8)!)
}

func testSiteDesignPrimaryButtonTextNotLastStep() throws {

// given
let creator = SiteCreator()
let siteDesignStep = SiteDesignStep(creator: creator, isLastStep: false)
let expectedPrimaryTitle = "Choose"

// when
let siteDesignVC = try XCTUnwrap(siteDesignStep.content as? SiteDesignContentCollectionViewController)
siteDesignVC.loadViewIfNeeded()
siteDesignVC.viewDidLoad()

// then
let currentTitle = siteDesignVC.primaryActionButton.currentTitle
XCTAssertEqual(expectedPrimaryTitle, currentTitle)
}

func testSiteDesignPrimaryButtonTextLastStep() throws {

// given
let creator = SiteCreator()
let siteDesignStep = SiteDesignStep(creator: creator, isLastStep: true)
let expectedPrimaryTitle = "Create Site"

// when
let siteDesignVC = try XCTUnwrap(siteDesignStep.content as? SiteDesignContentCollectionViewController)
siteDesignVC.loadViewIfNeeded()
siteDesignVC.viewDidLoad()

// then
let currentTitle = siteDesignVC.primaryActionButton.currentTitle
XCTAssertEqual(expectedPrimaryTitle, currentTitle)
}

func testSiteDesignPreviewButtonTextNotLastStep() throws {

// given
let siteDesignPreviewVC = SiteDesignPreviewViewController(
siteDesign: remoteDesign, selectedPreviewDevice: nil, createsSite: false, onDismissWithDeviceSelected: nil, completion: {design in })
let expectedPrimaryTitle = "Choose"

// when
siteDesignPreviewVC.loadViewIfNeeded()
siteDesignPreviewVC.viewDidLoad()

// then
let currentTitle = siteDesignPreviewVC.primaryActionButton.currentTitle
XCTAssertEqual(expectedPrimaryTitle, currentTitle)
}

func testSiteDesignPreviewButtonTextLastStep() throws {

// given
let siteDesignPreviewVC = SiteDesignPreviewViewController(
siteDesign: remoteDesign, selectedPreviewDevice: nil, createsSite: true, onDismissWithDeviceSelected: nil, completion: {design in })
let expectedPrimaryTitle = "Create Site"

// when
siteDesignPreviewVC.loadViewIfNeeded()
siteDesignPreviewVC.viewDidLoad()

// then
let currentTitle = siteDesignPreviewVC.primaryActionButton.currentTitle
XCTAssertEqual(expectedPrimaryTitle, currentTitle)
}
}