Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
karliatto committed Oct 1, 2024
1 parent 2187dc0 commit d24e263
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 2 deletions.
2 changes: 1 addition & 1 deletion suite-native/app/.detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
emulator: {
type: 'android.emulator',
device: {
avdName: 'Pixel_3a_API_31',
avdName: 'Pixel_6_API_33',
},
},
},
Expand Down
118 changes: 118 additions & 0 deletions suite-native/app/e2e/tests/deeplinkPopup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { exec } from 'child_process';
// `expect` keyword is already used by jest.
import { expect as detoxExpect } from 'detox';

import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';
import TrezorConnect from '@trezor/connect-deeplink';

import { openApp } from '../utils';
import { onOnboarding } from '../pageObjects/onboardingActions';
import { onCoinEnablingInit } from '../pageObjects/coinEnablingActions';

const TREZOR_DEVICE_LABEL = 'Trezor T - Tester';
// Contains only one BTC account with a single transaction to make the discovery as fast as possible.
const SIMPLE_SEED = 'immune enlist rule measure fan swarm mandate track point menu security fan';
const platform = device.getPlatform();

function openUriScheme(url, platform) {

Check failure on line 17 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

'platform' is already declared in the upper scope on line 15 column 7
// Construct the command dynamically using double quotes
const command = `npx uri-scheme open '${url.replace(/'/g, '')}' --${platform}`;

exec(command, (err, stdout, stderr) => {
if (err) {
console.error('Error:');
console.error(err);
console.error();
return; // Exit the function if there's an error

Check failure on line 26 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Expected blank line before this statement
}
console.log(stdout);

Check failure on line 28 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
console.error(stderr);
});
}

describe('Deeplink connect popup.', () => {
beforeAll(async () => {
if (platform === 'android') {
// Prepare Trezor device for test scenario and turn it off.
await TrezorUserEnvLink.disconnect();
await TrezorUserEnvLink.connect();
await TrezorUserEnvLink.startEmu({ wipe: true });
await TrezorUserEnvLink.setupEmu({
label: TREZOR_DEVICE_LABEL,
mnemonic: SIMPLE_SEED,
});
await TrezorUserEnvLink.startBridge();
await TrezorUserEnvLink.stopEmu();
}

await openApp({ newInstance: true });

await TrezorConnect.init({
manifest: {
email: '[email protected]',
appUrl: 'http://your.application.com',
},
deeplinkOpen: url => {
// eslint-disable-next-line no-console
console.log('deeplinkOpen', url);
openUriScheme(url, 'android');

// Android.openAsync({ uri: url });
},
deeplinkCallbackUrl: 'https://test.com/connect',
// deeplinkUrl: 'https://dev.suite.sldev.cz/connect/develop/deeplink/',
});
});

afterAll(async () => {
if (platform === 'android') {
await TrezorUserEnvLink.stopEmu();
}
await device.terminateApp();
});

it('Navigate to dashboard', async () => {
await onOnboarding.finishOnboarding();
console.log('after onboarding');

Check failure on line 76 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement

if (platform === 'android') {
console.log('platform is android');

Check failure on line 79 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
await TrezorUserEnvLink.startEmu();

await waitFor(element(by.id('@screen/CoinEnablingInit')))
.toBeVisible()
.withTimeout(10000);

console.log('before waitForBtcToBeVisible');

Check failure on line 86 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
await onCoinEnablingInit.waitForBtcToBeVisible();

console.log('before enableNetwork');

Check failure on line 89 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
await onCoinEnablingInit.enableNetwork('btc');
// TODO: I don't understand why without eth the part after does not complete.
await onCoinEnablingInit.enableNetwork('eth');

console.log('before onCoinEnablingInit.save');

Check failure on line 94 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
await onCoinEnablingInit.save();

console.log('before waitFor skip-view-only-mode');

Check failure on line 97 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
await waitFor(element(by.id('skip-view-only-mode')))
.toBeVisible()
.withTimeout(60000); // communication between connected Trezor and app takes some time.

console.log('before skip-view-only-mode tap()');

Check failure on line 102 in suite-native/app/e2e/tests/deeplinkPopup.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
await element(by.id('skip-view-only-mode')).tap();

console.log('before @home/portfolio/graph');
await detoxExpect(element(by.id('@home/portfolio/graph'))); // discovery finished and graph is visible

// TODO: At this point we should be able to call a TrezorConnect from the deeplink package,
// TODO: and check that the app opens it!!
const response = await TrezorConnect.getAddress({
path: "m/49'/0'/0'/0/0",
coin: 'btc',
});

console.log('response', response);
}
});
});
1 change: 1 addition & 0 deletions suite-native/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@suite-native/toasts": "workspace:*",
"@suite-native/transactions": "workspace:*",
"@trezor/connect": "workspace:*",
"@trezor/connect-deeplink": "workspace:^",
"@trezor/react-native-usb": "workspace:*",
"@trezor/styles": "workspace:*",
"@trezor/theme": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9598,6 +9598,7 @@ __metadata:
"@suite-native/toasts": "workspace:*"
"@suite-native/transactions": "workspace:*"
"@trezor/connect": "workspace:*"
"@trezor/connect-deeplink": "workspace:^"
"@trezor/react-native-usb": "workspace:*"
"@trezor/styles": "workspace:*"
"@trezor/theme": "workspace:*"
Expand Down Expand Up @@ -11235,7 +11236,7 @@ __metadata:
languageName: unknown
linkType: soft

"@trezor/connect-deeplink@workspace:*, @trezor/connect-deeplink@workspace:packages/connect-deeplink":
"@trezor/connect-deeplink@workspace:*, @trezor/connect-deeplink@workspace:^, @trezor/connect-deeplink@workspace:packages/connect-deeplink":
version: 0.0.0-use.local
resolution: "@trezor/connect-deeplink@workspace:packages/connect-deeplink"
dependencies:
Expand Down

0 comments on commit d24e263

Please sign in to comment.