Skip to content

Commit

Permalink
Merge branch 'main' into use-selectors-for-tokens-controllers-state-a…
Browse files Browse the repository at this point in the history
…ccess
  • Loading branch information
Gudahtt authored Jul 12, 2023
2 parents 00b2e7b + a85bbc6 commit 1911a10
Show file tree
Hide file tree
Showing 95 changed files with 1,509 additions and 1,268 deletions.
23 changes: 20 additions & 3 deletions .detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ module.exports = {
device: 'ios.simulator',
app: 'ios.release',
},
// because e2e run on debug mode in bitrise
'android.emu.bitrise.debug': {
device: 'android.bitrise.emulator',
app: 'android.bitrise.debug',
},

'android.emu.debug': {
device: 'android.emulator',
app: 'android.debug',
},
'android.emu.release': {
device: 'android.emulator',
device: 'android.bitrise.emulator',
app: 'android.release',
},
'android.emu.release.qa': {
device: 'android.emulator',
device: 'android.bitrise.emulator',
app: 'android.qa',
},
},
Expand All @@ -39,10 +45,16 @@ module.exports = {
type: 'iPhone 12 Pro',
},
},
'android.bitrise.emulator': {
type: 'android.emulator',
device: {
avdName: 'emulator',
},
},
'android.emulator': {
type: 'android.emulator',
device: {
avdName: 'Pixel_3_API_29',
avdName: 'Pixel_5_API_30',
},
},
},
Expand All @@ -58,6 +70,11 @@ module.exports = {
'ios/build/Build/Products/Release-iphonesimulator/MetaMask.app',
build: "METAMASK_ENVIRONMENT='production' yarn build:ios:release:e2e",
},
'android.bitrise.debug': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/prod/debug/app-prod-debug.apk',
build: 'yarn start:android:e2e',
},
'android.debug': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/prod/debug/app-prod-debug.apk',
Expand Down
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,23 @@ yarn test:unit

##### Platforms

E2E test are currently using a combination of Detox for iOS (e2e folder) and Appium for Android (wdio folder).
Work is in progress to have both platforms using Detox.
For both iOS and Android platforms, our chosen E2E test framework is Detox. We also utilize Appium for Android (wdio folder).

##### Test wallet

E2E tests use a wallet able to access testnet and mainnet.
On Bitrise CI, the wallet is created using the secret recovery phrase from secret env var.
For local testing, the wallet is created using the secret recovery phrase from the `.e2e.env` file.

##### iOS
##### Detox
All tests live within the e2e/specs folder.

### iOS
Prerequisites for running tests:
- Make sure to install `detox-cli` by referring to the instructions mentioned [here](https://wix.github.io/Detox/docs/introduction/getting-started/#detox-prerequisites).
- Additionally, install `applesimutils` by following the guidelines provided [here](https://github.com/wix/AppleSimulatorUtils).
- Before running any tests, it's recommended to refer to the `iOS section` above and check the latest simulator device specified under `Install the correct simulator`.
- The default device for iOS is the iPhone 12 Pro and Android the Pixel 5. Ensure you have these set up.
- Make sure that Metro is running. Use this command to launch the metro server:

```bash
Expand All @@ -232,29 +233,55 @@ You can trigger the tests against a `release` or `debug` build. It recommended t

To trigger the tests on a debug build run this command:

For iOS
```bash
yarn test:e2e:ios:debug
```
and on Android:
```bash
yarn test:e2e:android:debug
```

If you choose to run tests against a release build, you can do so by running this command:

For iOS

```bash
yarn test:e2e:ios
```
and on Android:
```bash
yarn test:e2e:android
```

If you have already built the application for Detox and want to run a specific test from the test folder, you can use this command:

For iOS

```bash
yarn test:e2e:ios:debug:single e2e/specs/TEST_NAME.spec.js
```

and on Android:

```bash
yarn test:e2e:android:debug:single e2e/specs/TEST_NAME.spec.js
```

To run tests associated with a certain tag, you can do so using the `--testNamePattern` flag. For example:

```bash
yarn test:e2e:ios:debug --testNamePattern="Smoke"
```
```bash
yarn test:e2e:android:debug --testNamePattern="Smoke"
```

This runs all tests that are tagged "Smoke"
##### Android
All android tests live within the wdio/feature folder.

##### Appium

The appium tests lives within the wdio/feature folder.

By default the tests use an avd named `Android 11 - Pixel 4a API 31`, with API `Level 30` (Android 11). You can modify the emulator and platform version by navigating to `wdio/config/android.config.debug.js` and adjusting the values of `deviceName` to match your emulator's name, and `platformVersion` to match your operating system's version. Make sure to verify that the config file accurately represents your emulator settings before executing any tests.

Expand Down
4 changes: 4 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ dependencies {
} else {
implementation jscFlavor
}
androidTestImplementation('com.wix:detox:+') {
exclude module: "protobuf-lite"
}
androidTestImplementation ('androidx.test.espresso:espresso-contrib:3.4.0')
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
6 changes: 6 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }

# kotlin

-keep class kotlin.** { *; }

-keep class kotlin.Metadata { *; }
21 changes: 13 additions & 8 deletions android/app/src/androidTest/java/com/metamask/DetoxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;

import com.wix.detox.config.DetoxConfig;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class DetoxTest {

@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
@Rule
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);

@Test
public void runDetoxTests() {
Detox.runTests(mActivityRule);
}
}
Detox.runTests(mActivityRule, detoxConfig);
}
}
8 changes: 7 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath("com.facebook.react:react-native-gradle-plugin")
}
allprojects {
repositories {
maven {
url("$rootDir/../node_modules/detox/Detox-android")
}
}
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// eslint-disable-next-line import/prefer-default-export
export const ACCORDION_EXPAND_TRANSITION_DURATION = 150;
// External dependencies.
import { AnimationDuration } from '../../../constants/animation.constants';
import { SAMPLE_ACCORDIONHEADER_TITLE } from './foundation/AccordionHeader/AccordionHeader.constants';

export const ACCORDION_TEST_ID = 'accordion';
export const ACCORDION_CONTENT_TEST_ID = 'accordion-content';
// Test IDs
export const TESTID_ACCORDION = 'accordion';
export const TESTID_ACCORDION_CONTENT = 'accordion-content';

// Defaults
export const DEFAULT_ACCORDION_EXPANDDURATION = AnimationDuration.Promptly;

// Samples
export const SAMPLE_ACCORDION_TITLE = SAMPLE_ACCORDIONHEADER_TITLE;
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
import React from 'react';
import { View } from 'react-native';
import { storiesOf } from '@storybook/react-native';
import { boolean, text } from '@storybook/addon-knobs';

// External dependencies.
import { mockTheme } from '../../../../util/theme';
import Text, { TextVariant } from '../../Texts/Text';
import {
getAccordionHeaderStoryProps,
AccordionHeaderStory,
} from './foundation/AccordionHeader/AccordionHeader.stories';

// Internal dependencies.
import Accordion from './Accordion';
import { TEST_ACCORDION_HEADER_TITLE } from './foundation/AccordionHeader/AccordionHeader.constants';
import { AccordionProps } from './Accordion.types';

storiesOf('Component Library / Accordion', module).add('Default', () => {
const groupId = 'Props';
const titleText = text('title', TEST_ACCORDION_HEADER_TITLE, groupId);
const isExpanded = boolean('isExpanded', false, groupId);
return (
<Accordion title={titleText} isExpanded={isExpanded}>
<View
style={{
backgroundColor: mockTheme.colors.background.alternative,
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text variant={TextVariant.BodySM}>{'Wrapped Content'}</Text>
</View>
</Accordion>
);
export const getAccordionStoryProps = (): AccordionProps => ({
...getAccordionHeaderStoryProps(),
children: (
<View
style={{
backgroundColor: mockTheme.colors.background.alternative,
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text variant={TextVariant.BodySM}>{'Wrapped Content'}</Text>
</View>
),
});

const AccordionStory = () => <Accordion {...getAccordionStoryProps()} />;

storiesOf('Component Library / Accordions', module)
.add('Accordion', AccordionStory)
.add('foundation / AccordionHeader', AccordionHeaderStory);

export default AccordionStory;
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@ import React from 'react';
import { shallow } from 'enzyme';
import { View } from 'react-native';

// External dependencies.
import { TEST_ACCORDION_HEADER_TITLE } from './foundation/AccordionHeader/AccordionHeader.constants';

// Internal dependencies.
import Accordion from './Accordion';
import {
ACCORDION_TEST_ID,
ACCORDION_CONTENT_TEST_ID,
TESTID_ACCORDION,
TESTID_ACCORDION_CONTENT,
SAMPLE_ACCORDION_TITLE,
} from './Accordion.constants';

describe('Accordion - Snapshot', () => {
it('should render default settings correctly', () => {
const wrapper = shallow(
<Accordion title={TEST_ACCORDION_HEADER_TITLE}>
<Accordion title={SAMPLE_ACCORDION_TITLE}>
<View />
</Accordion>,
);
expect(wrapper).toMatchSnapshot();
});
it('should render a proper expanded state', () => {
const wrapper = shallow(
<Accordion title={TEST_ACCORDION_HEADER_TITLE} isExpanded>
<Accordion title={SAMPLE_ACCORDION_TITLE} isExpanded>
<View />
</Accordion>,
);
Expand All @@ -35,36 +33,36 @@ describe('Accordion - Snapshot', () => {
describe('Accordion', () => {
it('should render Accordion', () => {
const wrapper = shallow(
<Accordion title={TEST_ACCORDION_HEADER_TITLE}>
<Accordion title={SAMPLE_ACCORDION_TITLE}>
<View />
</Accordion>,
);
const AccordionComponent = wrapper.findWhere(
(node) => node.prop('testID') === ACCORDION_TEST_ID,
(node) => node.prop('testID') === TESTID_ACCORDION,
);
expect(AccordionComponent.exists()).toBe(true);
});

it('should render Accordion content if isExpanded = true', () => {
const wrapper = shallow(
<Accordion title={TEST_ACCORDION_HEADER_TITLE} isExpanded>
<Accordion title={SAMPLE_ACCORDION_TITLE} isExpanded>
<View />
</Accordion>,
);
const AccordionContentComponent = wrapper.findWhere(
(node) => node.prop('testID') === ACCORDION_CONTENT_TEST_ID,
(node) => node.prop('testID') === TESTID_ACCORDION_CONTENT,
);
expect(AccordionContentComponent.exists()).toBe(true);
});

it('should NOT render Accordion content if isExpanded = false', () => {
const wrapper = shallow(
<Accordion title={TEST_ACCORDION_HEADER_TITLE}>
<Accordion title={SAMPLE_ACCORDION_TITLE}>
<View />
</Accordion>,
);
const AccordionContentComponent = wrapper.findWhere(
(node) => node.prop('testID') === ACCORDION_CONTENT_TEST_ID,
(node) => node.prop('testID') === TESTID_ACCORDION_CONTENT,
);
expect(AccordionContentComponent.exists()).toBe(false);
});
Expand Down
Loading

0 comments on commit 1911a10

Please sign in to comment.