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

DIA-1678 / DIA-1837 add support to tvOS and translation logic #436

Merged
merged 5 commits into from
May 9, 2023
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
26 changes: 13 additions & 13 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ jobs:
name: Upload ConsentViewController tests results
with:
path: /Users/runner/Library/Developer/Xcode/DerivedData/**/*.xcresult
# NativePMExampleApp:
# runs-on: macos-12
# steps:
# - uses: actions/checkout@v2
# - name: Select Xcode version 14.0.1
# run: sudo xcode-select -s '/Applications/Xcode_14.0.1.app/Contents/Developer'
# - name: ConsentViewController testing -> iPhone 14 Pro (iOS 16.0)
# run: xcodebuild test -scheme NativePMExampleApp -workspace ConsentViewController.xcworkspace -destination 'platform=tvOS Simulator,name=Apple TV,OS=16.1'
# - uses: actions/upload-artifact@v2
# if: failure()
# name: Upload NativePMExampleApp tests results
# with:
# path: /Users/runner/Library/Developer/Xcode/DerivedData/**/*.xcresult
NativePMExampleApp:
runs-on: macos-12
steps:
- uses: actions/checkout@v2
- name: Select Xcode version 14.0.1
run: sudo xcode-select -s '/Applications/Xcode_14.0.1.app/Contents/Developer'
- name: ConsentViewController testing -> Apple TV (tvOS 16.1)
run: xcodebuild test -scheme NativePMExampleApp -workspace ConsentViewController.xcworkspace -destination 'platform=tvOS Simulator,name=Apple TV,OS=16.1'
- uses: actions/upload-artifact@v2
if: failure()
name: Upload NativePMExampleApp tests results
with:
path: /Users/runner/Library/Developer/Xcode/DerivedData/**/*.xcresult
# MetaApp:
# runs-on: macos-12
# steps:
Expand Down
4 changes: 2 additions & 2 deletions ConsentViewController/Classes/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct Constants {
static let additionalData: String = "scriptType=ios&scriptVersion=\(SPConsentManager.VERSION)"
static let SP_ROOT = URL(string: prod ? "https://cdn.privacy-mgmt.com/" : "https://preprod-cdn.privacy-mgmt.com/")!
static let WRAPPER_API = URL(string: "./wrapper/?env=\(envParam)", relativeTo: SP_ROOT)!
static let GDPR_MESSAGE_URL = URL(string: "./v2/message/gdpr?\(additionalData)", relativeTo: WRAPPER_API)!
static let CCPA_MESSAGE_URL = URL(string: "./v2/message/ccpa?\(additionalData)", relativeTo: WRAPPER_API)!
static let GDPR_MESSAGE_URL = URL(string: "./v2/message/v2/gdpr?\(additionalData)", relativeTo: WRAPPER_API)!
static let CCPA_MESSAGE_URL = URL(string: "./v2/message/v2/ccpa?\(additionalData)", relativeTo: WRAPPER_API)!
static let ERROR_METRIS_URL = URL(string: "./metrics/v1/custom-metrics?\(additionalData)", relativeTo: WRAPPER_API)!
static let GDPR_CONSENT_URL = URL(string: "./v2/messages/choice/gdpr/?\(additionalData)", relativeTo: WRAPPER_API)!
static let CCPA_CONSENT_URL = URL(string: "./v2/messages/choice/ccpa/?\(additionalData)", relativeTo: WRAPPER_API)!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct GDPRChoiceBody: Encodable, Equatable {
let sampleRate: Float?
let idfaStatus: SPIDFAStatus?
let granularStatus: ConsentStatus.GranularStatus?
let includeData = IncludeData.dictionary
let includeData = IncludeData()
}

struct CCPAChoiceBody: Encodable, Equatable {
Expand All @@ -26,5 +26,5 @@ struct CCPAChoiceBody: Encodable, Equatable {
let sendPVData: Bool
let propertyId: Int
let sampleRate: Float?
let includeData = IncludeData.dictionary
let includeData = IncludeData()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct GDPRConsentRequest: Encodable, Equatable {
let pmSaveAndExitVariables: SPJson?
let pubData: SPPublisherData
let requestUUID: UUID
let includeData = IncludeData.dictionary
let includeData = IncludeData()
}

struct CCPAConsentRequest: Encodable, Equatable {
Expand All @@ -23,7 +23,7 @@ struct CCPAConsentRequest: Encodable, Equatable {
let pubData: SPPublisherData
let pmSaveAndExitVariables: SPJson?
let requestUUID: UUID
let includeData = IncludeData.dictionary
let includeData = IncludeData()
}

struct ConsentResponse: Decodable & Equatable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
// Created by Andre Herculano on 18.04.23.
//

// swiftlint:disable line_length

import Foundation

struct IncludeData {
static let dictionary = [
"localState": ["type": "RecordString"],
"TCData": ["type": "RecordString"],
"webConsentPayload": ["type": "string"]
]
struct IncludeData: Encodable, Equatable {
static let string = "{\"TCData\":{\"type\":\"RecordString\"},\"webConsentPayload\":{\"type\":\"string\"},\"localState\":{\"type\":\"RecordString\"},\"categories\":true,\"translateMessage\":true}"

static let string = "{\"TCData\":{\"type\":\"RecordString\"},\"webConsentPayload\":{\"type\":\"string\"},\"localState\":{\"type\":\"RecordString\"}}"
let localState = ["type": "RecordString"]
let TCData = ["type": "RecordString"]
let webConsentPayload = ["type": "string"]
let categories = true
let translateMessage = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ struct MessageRequest: Equatable, Encodable {
let consentLanguage: SPMessageLanguage
let campaigns: CampaignsRequest
let pubData: SPPublisherData
let includeData = IncludeData.dictionary
let includeData = IncludeData()
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct MessagesRequest: QueryParamEncodable {
let hasCSP = true
let campaignEnv: SPCampaignEnv?
let idfaStatus: SPIDFAStatus?
let includeData = IncludeData.string
let includeData = IncludeData()
}

struct MetaData: QueryParamEncodable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SPPMHeader: UIView {
var spTitleText: SPNativeText? {
didSet {
titleLabel.setup(from: spTitleText)
titleLabel.text = titleLabel.text?.trimmingCharacters(in: .newlines)
}
}

Expand Down Expand Up @@ -82,7 +83,9 @@ class SPPMHeader: UIView {
let nib = UINib(nibName: "SPPMHeader", bundle: Bundle.framework)
nib.instantiate(withOwner: self, options: nil)
contentView.frame = bounds
titleLabel.accessibilityIdentifier = "Header Title"
titleLabel.isAccessibilityElement = true
backButton.accessibilityIdentifier = "Back Button"
backButton.isAccessibilityElement = true
addSubview(contentView)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protocol SPNativePrivacyManagerHome {

override func viewDidLoad() {
super.viewDidLoad()
view.accessibilityIdentifier = "GDPR Message"
setHeader()
loadTextView(forComponentId: "PublisherDescription", textView: descriptionTextView, bounces: false)
descriptionTextView.flashScrollIndicators()
Expand All @@ -53,6 +54,7 @@ protocol SPNativePrivacyManagerHome {
loadButton(forComponentId: "NavPrivacyPolicyButton", button: privacyPolicyButton)
loadImage(forComponentId: "LogoImage", imageView: logoImageView)
setFocusGuidesForButtons()
categoryTableView.accessibilityIdentifier = "Categories List"
categoryTableView.allowsSelection = false
categoryTableView.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier)
categoryTableView.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class UnmockedSourcepointClientSpec: QuickSpec {

it("should contain all query params") {
let url = client.consentStatusURLWithParams(propertyId: propertyId, metadata: emptyMetaData, authId: nil)
let paramsRaw = "env=\(Constants.Urls.envParam)&scriptType=ios&scriptVersion=\(SPConsentManager.VERSION)&hasCsp=true&includeData={\"TCData\":{\"type\":\"RecordString\"},\"webConsentPayload\":{\"type\":\"string\"},\"localState\":{\"type\":\"RecordString\"}}&metadata={}&propertyId=17801&withSiteActions=false"
let paramsRaw = "env=\(Constants.Urls.envParam)&scriptType=ios&scriptVersion=\(SPConsentManager.VERSION)&hasCsp=true&includeData={\"TCData\":{\"type\":\"RecordString\"},\"webConsentPayload\":{\"type\":\"string\"},\"localState\":{\"type\":\"RecordString\"},\"categories\":true,\"translateMessage\":true}&metadata={}&propertyId=17801&withSiteActions=false"
expect(url?.query) == paramsRaw.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
}
}
Expand Down
4 changes: 4 additions & 0 deletions Example/NativePMExampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
UserDefaults.standard.set(CommandLine.arguments.contains("-gdpr"), forKey: "app.campaigns.gdpr")
UserDefaults.standard.set(CommandLine.arguments.contains("-ccpa"), forKey: "app.campaigns.ccpa")
let language = CommandLine.arguments
.first(where: { $0.starts(with: "-lang=")})?
.replacingOccurrences(of: "-lang=", with: "")
UserDefaults.standard.set(language, forKey: "app.lang")
return true
}

Expand Down
7 changes: 4 additions & 3 deletions Example/NativePMExampleApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ class ViewController: UIViewController {
lazy var consentManager: SPSDK = {
SPConsentManager(
accountId: 22,
propertyId: 21927,
propertyId: 17935,
// swiftlint:disable:next force_try
propertyName: try! SPPropertyName("appletv.demo"),
campaigns: campaigns,
language: SPMessageLanguage(rawValue: UserDefaults.standard.string(forKey: "app.lang") ?? "")!,
delegate: self
)
}()
Expand All @@ -50,11 +51,11 @@ class ViewController: UIViewController {
}

@IBAction func onGDPRTap(_ sender: Any) {
consentManager.loadGDPRPrivacyManager(withId: "713324")
consentManager.loadGDPRPrivacyManager(withId: "529561")
}

@IBAction func onCCPATap(_ sender: Any) {
consentManager.loadCCPAPrivacyManager(withId: "753814")
consentManager.loadCCPAPrivacyManager(withId: "753802")
}
}

Expand Down
70 changes: 38 additions & 32 deletions Example/NativePMExampleAppUITests/NativePMApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

import Nimble
import XCTest
import ConsentViewController

protocol App {
func launch()
func terminate()
func relaunch(clean: Bool, gdpr: Bool, ccpa: Bool)
func relaunch(clean: Bool, gdpr: Bool, ccpa: Bool, language: SPMessageLanguage)
}

extension XCUIApplication: App {
Expand All @@ -22,27 +23,34 @@ extension XCUIApplication: App {
launchArguments.removeAll { $0 == "-\(name)" }
}

func relaunch(clean: Bool = false, gdpr: Bool = true, ccpa: Bool = true) {
func setArgument(_ name: String, _ value: String) {
launchArguments.removeAll { $0.starts(with: "-\(name)=") }
launchArguments.append("-\(name)=\(value)")
}

func relaunch(clean: Bool = false, gdpr: Bool = true, ccpa: Bool = true, language: SPMessageLanguage = .BrowserDefault) {
UserDefaults.standard.synchronize()
self.terminate()
setArgument("cleanAppsData", clean)
setArgument("gdpr", gdpr)
setArgument("ccpa", ccpa)
setArgument("lang", language.rawValue)
launch()
}
}

class NativePMApp: XCUIApplication {
class GDPRMessage: XCUIApplication {
var container: XCUIElement {
windows.containing(.staticText, identifier: "GDPR Message").firstMatch
otherElements["GDPR Message"]
}

var headerTitle: XCUIElement { container.staticTexts["Header Title"] }
var acceptAllButton: XCUIElement { container.buttons["Accept"].firstMatch }
var rejectAllButton: XCUIElement { container.buttons["Reject All"].firstMatch }
var categoriesDetailsButton: XCUIElement { container.buttons["Manage Preferences"].firstMatch }
var vendorsDetailsButton: XCUIElement { container.buttons["Our Partners"].firstMatch }
var privacyPolicyButton: XCUIElement { container.buttons["Privacy Policy"].firstMatch }
var rejectAllButton: XCUIElement { container.buttons["Reject All"] }
var categoriesDetailsButton: XCUIElement { container.buttons["Manage Preferences"] }
var vendorsDetailsButton: XCUIElement { container.buttons["Our Partners"] }
var privacyPolicyButton: XCUIElement { container.buttons["Privacy Policy"] }
var categoriesList: XCUIElement { container.tables["Categories List"] }
}

class CCPAMessage: XCUIApplication {
Expand All @@ -53,12 +61,12 @@ class NativePMApp: XCUIApplication {
var doNotSellMyInfoButton: XCUIElement {
container.cells.containing(.staticText, identifier: "Do Not Sell My Personal Data").firstMatch
}
var acceptAllButton: XCUIElement { container.buttons["Accept"].firstMatch }
var rejectAllButton: XCUIElement { container.buttons["Reject All"].firstMatch }
var saveAndExitButton: XCUIElement { container.buttons["Save and Exit"].firstMatch }
var categoriesDetailsButton: XCUIElement { container.buttons["Manage Preferences"].firstMatch }
var vendorsDetailsButton: XCUIElement { container.buttons["Our Partners"].firstMatch }
var privacyPolicyButton: XCUIElement { container.buttons["Privacy Policy"].firstMatch }
var acceptAllButton: XCUIElement { container.buttons["Accept"] }
var rejectAllButton: XCUIElement { container.buttons["Reject All"] }
var saveAndExitButton: XCUIElement { container.buttons["Save and Exit"] }
var categoriesDetailsButton: XCUIElement { container.buttons["Manage Preferences"] }
var vendorsDetailsButton: XCUIElement { container.buttons["Our Partners"] }
var privacyPolicyButton: XCUIElement { container.buttons["Privacy Policy"] }
}

let gdprMessage = GDPRMessage()
Expand Down Expand Up @@ -109,67 +117,67 @@ class NativePMApp: XCUIApplication {
}

var acceptButton: XCUIElement {
buttons["Accept"].firstMatch
buttons["Accept"]
}

var acceptAllButton: XCUIElement {
buttons["Accept All"].firstMatch
buttons["Accept All"]
}

var managePreferencesButton: XCUIElement {
buttons["Manage Preferences"].firstMatch
buttons["Manage Preferences"]
}

var rejectAllButton: XCUIElement {
buttons["Reject All"].firstMatch
buttons["Reject All"]
}

var saveAndExitButton: XCUIElement {
buttons["Save and Exit"].firstMatch
buttons["Save and Exit"]
}

var saveAndExitInternalButton: XCUIElement {
buttons["Save & Exit"].firstMatch
buttons["Save & Exit"]
}

var homeButton: XCUIElement {
buttons["Home"].firstMatch
buttons["Home"]
}

var backButton: XCUIElement {
buttons["Back"].firstMatch
buttons["Back"]
}

var onButton: XCUIElement {
buttons["On"].firstMatch
buttons["On"]
}

var offButton: XCUIElement {
buttons["Off"].firstMatch
buttons["Off"]
}

var privacyPolicyButton: XCUIElement {
buttons["Privacy Policy"].firstMatch
buttons["Privacy Policy"]
}

var consentButton: XCUIElement {
buttons["CONSENT"].firstMatch
buttons["CONSENT"]
}

var legitimateInterestButton: XCUIElement {
buttons["LEGITIMATE INTEREST"].firstMatch
buttons["LEGITIMATE INTEREST"]
}

var ourPartnersButton: XCUIElement {
buttons["Our Partners"].firstMatch
buttons["Our Partners"]
}

var gdprPrivacyManagerButton: XCUIElement {
buttons["GDPR Privacy Manager"].firstMatch
buttons["GDPR Privacy Manager"]
}

var ccpaPrivacyManagerButton: XCUIElement {
buttons["CCPA Privacy Manager"].firstMatch
buttons["CCPA Privacy Manager"]
}

var sdkStatusLabel: XCUIElement {
Expand All @@ -181,8 +189,6 @@ class NativePMApp: XCUIApplication {
extension NativePMApp {
func pressDoNotSellButton() {
remote.press(.right)
// expectedMessageShowUP(element: doNotSellMyPersonalInformation)
// previous line is commented since appletv.demo "Do Not Sell" button has blank text
remote.press(.select)
remote.press(.left)
}
Expand Down
Loading