Skip to content

Commit

Permalink
Merge pull request #544 from SourcePointUSA/DIA-3478_fix_pm_not_showi…
Browse files Browse the repository at this point in the history
…ng_gdpr_consent

DIA-3478 fix PM not showing GDPR consent
  • Loading branch information
andresilveirah authored Jan 25, 2024
2 parents 9d2955e + a2e6d6f commit 37121f0
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 14 deletions.
4 changes: 3 additions & 1 deletion ConsentViewController/Classes/SPConsentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ import UIKit
func genericPMUrl(
_ specificUrl: URL?,
pmId: String,
uuidName: String = "uuid",
uuidName: String,
uuidValue: String?,
propertyId: Int,
tab: SPPrivacyManagerTab = .Default,
Expand All @@ -351,6 +351,7 @@ import UIKit
genericPMUrl(
Constants.Urls.GDPR_PM_URL,
pmId: usedId,
uuidName: "consentUUID",
uuidValue: uuid,
propertyId: propertyId,
consentLanguage: messageLanguage
Expand Down Expand Up @@ -458,6 +459,7 @@ import UIKit
genericPMUrl(
Constants.Urls.USNAT_PM_URL,
pmId: usedId,
uuidName: "uuid",
uuidValue: uuid,
propertyId: propertyId,
consentLanguage: messageLanguage
Expand Down
5 changes: 3 additions & 2 deletions Example/ConsentViewController/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<accessibilityOverrides/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="Stack View standard spacing" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand Down Expand Up @@ -50,6 +50,7 @@
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="-" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Gpu-Yh-muK">
<rect key="frame" x="144.5" y="0.0" width="12.5" height="67"/>
<accessibility key="accessibilityConfiguration" identifier="customVendorLabel"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func renderingAppMock(messageReadyDelayInSeconds: Int) -> String {
class FaultyRenderingAppMock: WKWebView {
override func load(_ request: URLRequest) -> WKNavigation? {
loadHTMLString(
renderingAppMock(messageReadyDelayInSeconds: 3),
renderingAppMock(messageReadyDelayInSeconds: 7),
baseURL: URL(string: "https://example.com")!
)
}
Expand All @@ -45,7 +45,7 @@ class FaultyRenderingAppMock: WKWebView {
class RenderingAppMock: WKWebView {
override func load(_ request: URLRequest) -> WKNavigation? {
loadHTMLString(
renderingAppMock(messageReadyDelayInSeconds: 0),
renderingAppMock(messageReadyDelayInSeconds: 2),
baseURL: URL(string: "https://example.com")!
)
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func loadMessage(
messageId: "",
contents: Data(),
campaignType: campaignType,
timeout: 2.0,
timeout: 5.0,
delegate: delegate,
consentUUID: uuid
)
Expand All @@ -95,15 +95,15 @@ class GenericWebMessageViewControllerSpec: QuickSpec {

it("calls loaded when the rendering app dispatches a sp.showMessage event") {
loadMessage(with: RenderingAppMock.self, delegate: self.delegate)
after(.seconds(4)) {
after(.seconds(6)) {
expect(self.delegate.loadedWasCalled).to(beTrue())
expect(self.delegate.onErrorWasCalled).to(beFalse())
}
}

it("calls onError if .loaded() is not called on the delegate before the timeout") {
loadMessage(with: FaultyRenderingAppMock.self, delegate: self.delegate)
after(.seconds(4)) {
after(.seconds(6)) {
expect(self.delegate.loadedWasCalled).to(beFalse())
expect(self.delegate.onErrorWasCalled).to(beTrue())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public func containQueryParam(_ name: String, withValue value: String) -> Predic
guard let actual = try actual.evaluate(),
let params = actual.queryParams
else {
return PredicateResult(bool: false, message: .fail("could not get query params from URL"))
return PredicateResult(bool: false, message: .fail("could not get query params from URL(\(try? actual.evaluate()?.absoluteString))"))
}
var pass = false
var message = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SPConsentManagerSpec: QuickSpec {
describe("when there's uuid") {
it("includes the uuid query param") {
expect(manager.buildGDPRPmUrl(usedId: usedId, uuid: "gdprUUID")?.absoluteString)
.to(equal("https://\(self.wrapperHost)/privacy-manager/index.html?consentLanguage=ES&idfaStatus=\(idfaStatus)&message_id=1&pmTab=&site_id=\(propertyId)&uuid=gdprUUID"))
.to(equal("https://\(self.wrapperHost)/privacy-manager/index.html?consentLanguage=ES&consentUUID=gdprUUID&idfaStatus=\(idfaStatus)&message_id=1&pmTab=&site_id=\(propertyId)"))
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Example/SPGDPRExampleAppUITests/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class ExampleApp: XCUIApplication {
staticTexts.containing(NSPredicate(format: "label CONTAINS[cd] 'PURPOSES'")).firstMatch
}

var purposeToggles: [XCUIElement] {
(0..<container.switches.count).map {
container.switches.element(boundBy: $0)
}
}

var acceptAllButton: XCUIElement {
container.buttons["Accept All"].firstMatch
}
Expand Down
16 changes: 16 additions & 0 deletions Example/SPGDPRExampleAppUITests/Helpers/CustomMatchers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,19 @@ public func beDisabled() -> Predicate<XCUIElement> {
return PredicateStatus(bool: !actual.isEnabled)
}
}

/// A Nimble matcher that succeeds when an XCUIElement is disabled
public func beToggledOn() -> Predicate<XCUIElement> {
Predicate.simple("beToggledOn") { actualExpression in
guard let actual = try actualExpression.evaluate() else { return .fail }
return PredicateStatus(bool: actual.value as? String == "1")
}
}

/// A Nimble matcher that succeeds when an XCUIElement is disabled
public func beToggledOff() -> Predicate<XCUIElement> {
Predicate.simple("beToggledOff") { actualExpression in
guard let actual = try actualExpression.evaluate() else { return .fail }
return PredicateStatus(bool: actual.value as? String != "1")
}
}
34 changes: 30 additions & 4 deletions Example/SPGDPRExampleAppUITests/SPGDPRExampleAppUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SPGDPRExampleAppUITests: QuickSpec {
self.continueAfterFailure = false
self.app = ExampleApp()
Nimble.AsyncDefaults.timeout = .seconds(30)
Nimble.AsyncDefaults.pollInterval = .milliseconds(100)
Nimble.AsyncDefaults.pollInterval = .milliseconds(300)
}

afterSuite {
Expand All @@ -75,12 +75,31 @@ class SPGDPRExampleAppUITests: QuickSpec {
expect(self.app.sdkStatusLabel).toEventually(containText("Finished"))
}

it("Accepting All toggles all toggles on PM") {
self.app.relaunch(clean: true, resetAtt: false, args: ["ccpa": false, "att": false])
self.acceptGDPRMessage()

expect(self.app.gdprPrivacyManagerButton).toEventually(showUp())
expect(self.app.sdkStatusLabel).toEventually(containText("Finished"))
self.app.gdprPrivacyManagerButton.tap()
expect(self.app.gdprPM).toEventually(showUp())
expect(self.app.gdprPM.purposeToggles).toEventually(allPass(beToggledOn()))

self.app.gdprPM.rejectAllButton.tap()
expect(self.app.gdprPrivacyManagerButton).toEventually(showUp())
expect(self.app.sdkStatusLabel).toEventually(containText("Finished"))
self.app.gdprPrivacyManagerButton.tap()
expect(self.app.gdprPM).toEventually(showUp())
expect(self.app.gdprPM.purposeToggles).toEventually(allPass(beToggledOff()))
}

it("Accept all through 2nd layer") {
self.app.relaunch(clean: true, resetAtt: true, args: ["att": false])
self.app.relaunch(clean: true, resetAtt: true, args: [
"att": false,
"ccpa": false
])
self.showGDPRPMViaFirstLayerMessage()
self.app.gdprPM.acceptAllButton.tap()
self.acceptCCPAMessage()
expect(self.app.gdprPrivacyManagerButton).toEventually(showUp())
expect(self.app.sdkStatusLabel).toEventually(containText("Finished"))
self.app.relaunch()
expect(self.app.sdkStatusLabel).toEventually(containText("Finished"))
Expand All @@ -103,8 +122,11 @@ class SPGDPRExampleAppUITests: QuickSpec {
])
self.acceptGDPRMessage()

expect(self.app.sdkStatusLabel).toEventually(containText("Finished"))
expect(self.app.deleteCustomVendorsButton).toEventually(beEnabled())
expect(self.app.customVendorLabel).toEventually(containText("Accepted"))
self.app.deleteCustomVendorsButton.tap()
expect(self.app.customVendorLabel).toEventually(containText("Rejected"))

self.app.relaunch(args: ["att": false, "ccpa": false])

Expand All @@ -113,6 +135,7 @@ class SPGDPRExampleAppUITests: QuickSpec {
expect(self.app.customVendorLabel).toEventually(containText("Rejected"))

self.app.acceptCustomVendorsButton.tap()
expect(self.app.customVendorLabel).toEventually(containText("Accepted"))

self.app.relaunch(args: ["att": false, "ccpa": false])

Expand All @@ -124,8 +147,11 @@ class SPGDPRExampleAppUITests: QuickSpec {
it("Shows a translated message") {
self.app.relaunch(clean: true, resetAtt: false, args: [
"att": false,
"ccpa": false,
"usnat": false,
"language": SPMessageLanguage.Spanish.rawValue
])
expect(self.app.sdkStatusLabel).toEventually(containText("Running"))
expect(self.app.gdprMessage.spanishMessageTitle).toEventually(showUp())
}
}
Expand Down

0 comments on commit 37121f0

Please sign in to comment.