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 Creation] Pass a boolean to determine Site Design primary button titles #18400

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
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 @@ -100,13 +100,10 @@ class TemplatePreviewViewController: UIViewController, NoResultsViewHost, UIPopo
}

private func styleButtons() {
let isLastSiteCreationStep = ABTest.siteNameV1.variation == .treatment(nil) && FeatureFlag.siteName.enabled
let mainButtonTitle = isLastSiteCreationStep ? NSLocalizedString("Create site", comment: "Title for the button to progress with creating the site with the selected design")
: NSLocalizedString("Choose", comment: "Title for the button to progress with the selected site homepage design")
primaryActionButton.titleLabel?.font = WPStyleGuide.fontForTextStyle(.body, fontWeight: .medium)
primaryActionButton.backgroundColor = accentColor
primaryActionButton.layer.cornerRadius = 8
primaryActionButton.setTitle(mainButtonTitle, for: .normal)
primaryActionButton.setTitle(NSLocalizedString("Choose", comment: "Title for the button to progress with the selected site homepage design"), for: .normal)
}

private func configurePreviewDeviceButton() {
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,21 +56,27 @@ class SiteDesignContentCollectionViewController: FilterableCategoriesViewControl
return sections[sectionIndex].designs[position]
}

init(_ completion: @escaping SiteDesignStep.SiteDesignSelection) {
init(createsSite: Bool, _ completion: @escaping SiteDesignStep.SiteDesignSelection) {
self.completion = completion
let isLastSiteCreationStep = ABTest.siteNameV1.variation == .treatment(nil) && FeatureFlag.siteName.enabled
let primaryButtonTitle = isLastSiteCreationStep ? NSLocalizedString("Create site", comment: "Title for the button to progress with creating the site with the selected design")
: NSLocalizedString("Choose", comment: "Title for the button to progress with the selected site homepage design")
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: primaryButtonTitle,
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
)
}

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.")
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down Expand Up @@ -154,7 +161,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 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)
}
}