-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ced1633
commit ce7f425
Showing
10 changed files
with
1,187 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** @type {Detox.DetoxConfig} */ | ||
module.exports = { | ||
testRunner: { | ||
args: { | ||
'$0': 'jest', | ||
config: 'e2e/jest.config.js' | ||
}, | ||
jest: { | ||
setupTimeout: 120000 | ||
} | ||
}, | ||
apps: { | ||
'ios.debug': { | ||
type: 'ios.app', | ||
binaryPath: 'example/ios/build/Build/Products/Debug-iphonesimulator/SourcepointCmpExample.app', | ||
build: 'xcodebuild -workspace example/ios/SourcepointCmpExample.xcworkspace -scheme SourcepointCmpExample -configuration Debug -sdk iphonesimulator -derivedDataPath example/ios/build' | ||
}, | ||
// 'ios.release': { | ||
// type: 'ios.app', | ||
// binaryPath: 'example/ios/build/Build/Products/Release-iphonesimulator/SourcepointCmpExample.app', | ||
// build: 'xcodebuild -workspace example/ios/SourcepointCmpExample.xcworkspace -scheme SourcepointCmpExample -configuration Release -sdk iphonesimulator -derivedDataPath example/ios/build' | ||
// }, | ||
'android.debug': { | ||
type: 'android.apk', | ||
binaryPath: 'example/android/app/build/outputs/apk/debug/app-debug.apk', | ||
build: 'cd example/android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug', | ||
reversePorts: [ | ||
8081 | ||
] | ||
}, | ||
// 'android.release': { | ||
// type: 'android.apk', | ||
// binaryPath: 'example/android/app/build/outputs/apk/release/app-release.apk', | ||
// build: 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release' | ||
// } | ||
}, | ||
devices: { | ||
simulator: { | ||
type: 'ios.simulator', | ||
device: { | ||
type: 'iPhone 15' | ||
} | ||
}, | ||
// attached: { | ||
// type: 'android.attached', | ||
// device: { | ||
// adbName: '.*' | ||
// } | ||
// }, | ||
emulator: { | ||
type: 'android.emulator', | ||
device: { | ||
avdName: 'Medium_Phone_API_29' | ||
} | ||
} | ||
}, | ||
configurations: { | ||
'ios.sim.debug': { | ||
device: 'simulator', | ||
app: 'ios.debug' | ||
}, | ||
// 'ios.sim.release': { | ||
// device: 'simulator', | ||
// app: 'ios.release' | ||
// }, | ||
// 'android.att.debug': { | ||
// device: 'attached', | ||
// app: 'android.debug' | ||
// }, | ||
// 'android.att.release': { | ||
// device: 'attached', | ||
// app: 'android.release' | ||
// }, | ||
'android.emu.debug': { | ||
device: 'emulator', | ||
app: 'android.debug' | ||
}, | ||
// 'android.emu.release': { | ||
// device: 'emulator', | ||
// app: 'android.release' | ||
// } | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import jestExpect from 'expect' | ||
import { web, element, by, expect, waitFor, device } from 'detox' | ||
|
||
const app = { | ||
_timeout: 5000, //ms | ||
loadMessagesButton: element(by.text(/load messages/i)), | ||
loadGDPRPMButton: element(by.text(/load gdpr pm/i)), | ||
loadCCPAPMButton: element(by.text(/load ccpa pm/i)), | ||
clearDataButton: element(by.text(/clear all/i)), | ||
sdkElement: element(by.id('sdkStatus')), | ||
presentingStatusText: 'Presenting', | ||
finishedStatusText: 'Finished', | ||
messageTitle: web.element(by.web.cssSelector('#notice > p')), | ||
acceptAllButton: web.element(by.web.cssSelector('.sp_choice_type_11')), | ||
rejectAllButton: web.element(by.web.cssSelector('.sp_choice_type_13')), | ||
pmCancelButton: web.element(by.web.cssSelector('.sp_choice_type_CANCEL')), | ||
pmToggleOn: web.element(by.web.cssSelector('button[aria-checked=true]')), | ||
pmToggleOff: web.element(by.web.cssSelector('button[aria-checked=false]')), | ||
|
||
getGDPRUUID: async function () { | ||
return (await element(by.id('gdpr.uuid')).getAttributes()).text | ||
}, | ||
|
||
getCCPAUUID: async function () { | ||
return (await element(by.id('ccpa.uuid')).getAttributes()).text | ||
}, | ||
|
||
forSDKToBePresenting: async function () { | ||
await waitFor(this.sdkElement) | ||
.toHaveText(this.presentingStatusText) | ||
.withTimeout(this._timeout) | ||
}, | ||
|
||
forSDKToBeFinished: async function () { | ||
await waitFor(this.sdkElement) | ||
.toHaveText(this.finishedStatusText) | ||
.withTimeout(this._timeout) | ||
}, | ||
|
||
loadGDPRPM: async function () { | ||
await this.loadGDPRPMButton.tap() | ||
}, | ||
|
||
loadCCPAPM: async function () { | ||
await this.loadCCPAPMButton.tap() | ||
}, | ||
|
||
dismissPM: async function () { | ||
await this.pmCancelButton.tap() | ||
}, | ||
|
||
assertNoMessageShow: async function () { | ||
await this.reloadMessages({ clearData: false }) | ||
await this.forSDKToBeFinished() | ||
}, | ||
|
||
reloadMessages: async function ({ clearData }) { | ||
if (clearData) await this.clearDataButton.tap() | ||
await this.loadMessagesButton.tap() | ||
}, | ||
|
||
acceptAllGDPRMessage: async function (withTitle = 'GDPR Message') { | ||
await expect(app.messageTitle).toHaveText(withTitle) | ||
await app.acceptAllButton.tap() | ||
}, | ||
|
||
acceptAllCCPAMessage: async function (withTitle = 'CCPA Message') { | ||
await expect(app.messageTitle).toHaveText(withTitle) | ||
await app.acceptAllButton.tap() | ||
}, | ||
|
||
rejectAllGDPRMessage: async function (withTitle = 'GDPR Message') { | ||
await expect(app.messageTitle).toHaveText(withTitle) | ||
await app.rejectAllButton.tap() | ||
}, | ||
|
||
rejectAllCCPAMessage: async function (withTitle = 'CCPA Message') { | ||
await expect(app.messageTitle).toHaveText(withTitle) | ||
await app.rejectAllButton.tap() | ||
}, | ||
} | ||
|
||
const assertUUIDsDidntChange = async () => { | ||
const gdprUUIDBeforeReloading = app.gdprUUID | ||
const ccpaUUIDBeforeReloading = app.ccpaUUID | ||
await app.assertNoMessageShow() | ||
jestExpect(gdprUUIDBeforeReloading).toEqual(app.gdprUUID) | ||
jestExpect(ccpaUUIDBeforeReloading).toEqual(app.ccpaUUID) | ||
} | ||
|
||
const assertAllPMToggles = async (loadPMFn, { toggled, togglesCount }) => { | ||
await loadPMFn() | ||
if (toggled) { | ||
await expect(app.pmToggleOn.atIndex(togglesCount - 1)).toExist() | ||
} else { | ||
await expect(app.pmToggleOff.atIndex(togglesCount - 1)).toExist() | ||
} | ||
await app.dismissPM() | ||
} | ||
|
||
describe('SourcepointSDK', () => { | ||
beforeAll(async () => { | ||
await device.launchApp() | ||
}) | ||
|
||
it('Accepting All, works', async () => { | ||
await app.forSDKToBePresenting() | ||
await app.acceptAllGDPRMessage() | ||
await app.acceptAllCCPAMessage() | ||
await app.forSDKToBeFinished() | ||
await assertUUIDsDidntChange() | ||
await assertAllPMToggles(() => app.loadGDPRPM(), { | ||
toggled: true, | ||
togglesCount: 5, | ||
}) | ||
await assertAllPMToggles(() => app.loadCCPAPM(), { | ||
toggled: true, | ||
togglesCount: 3, | ||
}) | ||
}) | ||
|
||
it('Rejecting All, works', async () => { | ||
await app.reloadMessages({ clearData: true }) | ||
await app.forSDKToBePresenting() | ||
await app.rejectAllGDPRMessage() | ||
await app.rejectAllCCPAMessage() | ||
await app.forSDKToBeFinished() | ||
await assertUUIDsDidntChange() | ||
await assertAllPMToggles(() => app.loadGDPRPM(), { | ||
toggled: false, | ||
togglesCount: 5, | ||
}) | ||
await assertAllPMToggles(() => app.loadCCPAPM(), { | ||
toggled: false, | ||
togglesCount: 3, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** @type {import('@jest/types').Config.InitialOptions} */ | ||
module.exports = { | ||
rootDir: '..', | ||
testMatch: ['<rootDir>/e2e/**/*.test.js'], | ||
testTimeout: 120000, | ||
maxWorkers: 1, | ||
globalSetup: 'detox/runners/jest/globalSetup', | ||
globalTeardown: 'detox/runners/jest/globalTeardown', | ||
reporters: ['detox/runners/jest/reporter'], | ||
testEnvironment: 'detox/runners/jest/testEnvironment', | ||
verbose: true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
example/android/app/src/androidTest/java/com/sourcepointcmpexample/DetoxTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.sourcepointcmpexample; | ||
|
||
import com.wix.detox.Detox; | ||
import com.wix.detox.config.DetoxConfig; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.filters.LargeTest; | ||
import androidx.test.rule.ActivityTestRule; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class DetoxTest { | ||
@Rule // (2) | ||
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false); | ||
|
||
@Test | ||
public void runDetoxTests() { | ||
DetoxConfig detoxConfig = new DetoxConfig(); | ||
detoxConfig.idlePolicyConfig.masterTimeoutSec = 90; | ||
detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60; | ||
detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60); | ||
|
||
Detox.runTests(mActivityRule, detoxConfig); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
example/android/app/src/main/res/xml/network_security_config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<network-security-config> | ||
<domain-config cleartextTrafficPermitted="true"> | ||
<domain includeSubdomains="true">10.0.2.2</domain> | ||
<domain includeSubdomains="true">localhost</domain> | ||
</domain-config> | ||
</network-security-config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.