Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
tommasini committed Oct 15, 2024
2 parents a0a820b + adfc755 commit cfeab8d
Show file tree
Hide file tree
Showing 35 changed files with 752 additions and 1,119 deletions.
1 change: 0 additions & 1 deletion .depcheckrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
ignores:
- '@metamask/oss-attribution-generator'
- 'webpack-cli'
- '@react-native-community/datetimepicker'
- '@react-native-community/slider'
- 'patch-package'
- '@lavamoat/allow-scripts'
Expand Down
28 changes: 8 additions & 20 deletions .detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
configurations: {
'ios.sim.apiSpecs': {
device: 'ios.simulator',
app: 'ios.debug',
app: 'ios.qa',
testRunner: {
args: {
"$0": "node e2e/api-specs/run-api-spec-tests.js",
Expand All @@ -41,10 +41,9 @@ 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',
'ios.sim.qa': {
device: 'ios.simulator',
app: 'ios.qa',
},

'android.emu.debug': {
Expand Down Expand Up @@ -86,32 +85,21 @@ module.exports = {
binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/MetaMask.app',
build: 'yarn start:ios:e2e',
},
'ios.release': {
'ios.qa': {
type: 'ios.app',
binaryPath:
'ios/build/Build/Products/Release-iphonesimulator/MetaMask.app',
build: "METAMASK_BUILD_TYPE='main' 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',
'ios/build/Build/Products/Release-iphonesimulator/MetaMask-QA.app',
build: "METAMASK_BUILD_TYPE='main' METAMASK_ENVIRONMENT='qa' yarn build:ios:qa",
},
'android.debug': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/prod/debug/app-prod-debug.apk',
build: 'yarn start:android:e2e',
},
'android.release': {
type: 'android.apk',
binaryPath:
'android/app/build/outputs/apk/prod/release/app-prod-release.apk',
build: "METAMASK_BUILD_TYPE='main' METAMASK_ENVIRONMENT='production' yarn build:android:release:e2e",
},
'android.qa': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/qa/release/app-qa-release.apk',
build: "METAMASK_BUILD_TYPE='main' METAMASK_ENVIRONMENT='qa' yarn build:android:qa:e2e",
build: "METAMASK_BUILD_TYPE='main' METAMASK_ENVIRONMENT='qa' yarn build:android:qa",
},
},
};
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ android {
release {
manifestPlaceholders.isDebug = false
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro", "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro", "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules.pro"
}
}

Expand Down
1 change: 0 additions & 1 deletion app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ const MainFlow = () => (
mode={'modal'}
screenOptions={{
headerShown: false,
cardStyle: { backgroundColor: importedColors.transparent },
}}
>
<Stack.Screen name={'Main'} component={ConnectedMain} />
Expand Down
14 changes: 12 additions & 2 deletions app/components/UI/Name/Name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ const UnknownEthereumAddress: React.FC<{ address: string }> = ({ address }) => {
);
};

const Name: React.FC<NameProperties> = ({ type, value }) => {
const Name: React.FC<NameProperties> = ({
chainId,
preferContractSymbol,
type,
value,
}) => {
if (type !== NameType.EthereumAddress) {
throw new Error('Unsupported NameType: ' + type);
}
const displayName = useDisplayName(type, value);
const displayName = useDisplayName(
type,
value,
chainId,
preferContractSymbol,
);
const { styles } = useStyles(styleSheet, {
displayNameVariant: displayName.variant,
});
Expand Down
3 changes: 3 additions & 0 deletions app/components/UI/Name/Name.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ViewProps } from 'react-native';
import { Hex } from '@metamask/utils';

/**
* The name types supported by the NameController.
Expand All @@ -11,6 +12,8 @@ export enum NameType {
}

export interface NameProperties extends ViewProps {
chainId?: Hex;
preferContractSymbol?: boolean;
type: NameType;
value: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import NotificationContent from './Content';

describe('NotificationContent', () => {
const title = 'Welcome to the new Test!';
const createdAt = '2024-04-26T16:35:03.147606Z';
const yesterday = new Date().setDate(new Date().getDate() - 1);
const createdAt = new Date(yesterday).toISOString(); // Relative date: one day before current date
const description = {
start:
'We are excited to announce the launch of our brand new website and app!',
end: 'Ethereum',
};

it('renders correctly', () => {
it('render matches snapshot', () => {
const { toJSON } = renderWithProvider(
<NotificationContent
title={title}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`NotificationContent renders correctly 1`] = `
exports[`NotificationContent render matches snapshot 1`] = `
<View
style={
{
Expand Down Expand Up @@ -47,7 +47,7 @@ exports[`NotificationContent renders correctly 1`] = `
}
}
>
6 months ago
Yesterday
</Text>
</View>
<View
Expand Down
3 changes: 2 additions & 1 deletion app/components/UI/SimulationDetails/AssetPill/AssetPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ const AssetPill: React.FC<AssetPillProperties> = ({ asset }) => {
<NativeAssetPill />
) : (
<Name
preferContractSymbol
testID="simulation-details-asset-pill-name"
type={NameType.EthereumAddress}
value={asset.address as Hex}
value={asset.address as Hex}
/>
)}
</View>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`NotificationsSettings should render correctly 1`] = `
exports[`NotificationsSettings render matches snapshot 1`] = `
<RCTScrollView
style={
{
Expand Down
150 changes: 3 additions & 147 deletions app/components/Views/Settings/NotificationsSettings/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import React, { useCallback } from 'react';
import { renderHook, act } from '@testing-library/react-hooks';

import React from 'react';
import renderWithProvider from '../../../../util/test/renderWithProvider';
import NotificationsService from '../../../../util/notifications/services/NotificationService';
import { backgroundState } from '../../../../util/test/initial-root-state';
import NotificationsSettings from '.';

import Routes from '../../../../constants/navigation/Routes';
import { Props } from './NotificationsSettings.types';
import { MOCK_ACCOUNTS_CONTROLLER_STATE } from '../../../../util/test/accountsControllerTestUtils';
import { MetaMetricsEvents } from '../../../../core/Analytics/MetaMetrics.events';
import { NavigationProp, ParamListBase } from '@react-navigation/native';

// Mock store.getState

let mockGetState: jest.Mock;
jest.mock('../../../../store', () => {
mockGetState = jest.fn();
Expand Down Expand Up @@ -57,130 +50,10 @@ jest.mock('../../../../util/notifications/services/NotificationService', () => (
getAllPermissions: jest.fn(),
}));

jest.mock('../../../../core/Analytics/MetaMetrics.events', () => ({
MetaMetricsEvents: {
NOTIFICATIONS_SETTINGS_UPDATED: 'NOTIFICATIONS_SETTINGS_UPDATED',
},
}));

const mockDisableNotifications = jest.fn();
const mockEnableNotifications = jest.fn();
const mockSetUiNotificationStatus = jest.fn();
const mockTrackEvent = jest.fn();

const mockNavigation = {
navigate: jest.fn(),
} as unknown as NavigationProp<ParamListBase>;

const setOptions = jest.fn();

describe('toggleNotificationsEnabled', () => {
beforeEach(() => {
jest.clearAllMocks();
});

const setup = (basicFunctionalityEnabled: boolean, isMetamaskNotificationsEnabled: boolean, isProfileSyncingEnabled: boolean) => renderHook(() =>
useCallback(async () => {
if (!basicFunctionalityEnabled) {
mockNavigation.navigate(Routes.MODAL.ROOT_MODAL_FLOW, {
screen: Routes.SHEET.BASIC_FUNCTIONALITY,
params: {
caller: Routes.SETTINGS.NOTIFICATIONS,
},
});
} else if (isMetamaskNotificationsEnabled) {
mockDisableNotifications();
mockSetUiNotificationStatus(false);
} else {
const { permission } = await NotificationsService.getAllPermissions(false);
if (permission !== 'authorized') {
return;
}

mockEnableNotifications();
mockSetUiNotificationStatus(true);
}
mockTrackEvent(MetaMetricsEvents.NOTIFICATIONS_SETTINGS_UPDATED, {
settings_type: 'notifications',
old_value: isMetamaskNotificationsEnabled,
new_value: !isMetamaskNotificationsEnabled,
was_profile_syncing_on: isMetamaskNotificationsEnabled ? true : isProfileSyncingEnabled,
});
}, [])
);

it('should navigate to basic functionality screen if basicFunctionalityEnabled is false', async () => {
const { result } = setup(false, false, false);

await act(async () => {
await result.current();
});

expect(mockNavigation.navigate).toHaveBeenCalledWith(Routes.MODAL.ROOT_MODAL_FLOW, {
screen: Routes.SHEET.BASIC_FUNCTIONALITY,
params: {
caller: Routes.SETTINGS.NOTIFICATIONS,
},
});
});

it('should disable notifications if isMetamaskNotificationsEnabled is true', async () => {
const { result } = setup(true, true, false);

await act(async () => {
await result.current();
});

expect(mockDisableNotifications).toHaveBeenCalled();
expect(mockSetUiNotificationStatus).toHaveBeenCalledWith(false);
});

it('should enable notifications if isMetamaskNotificationsEnabled is false and permission is authorized', async () => {
(NotificationsService.getAllPermissions as jest.Mock).mockResolvedValue({ permission: 'authorized' });

const { result } = setup(true, false, false);

await act(async () => {
await result.current();
});

expect(mockEnableNotifications).toHaveBeenCalled();
expect(mockSetUiNotificationStatus).toHaveBeenCalledWith(true);
});

it('should not enable notifications if permission is not authorized', async () => {
(NotificationsService.getAllPermissions as jest.Mock).mockResolvedValue({ permission: 'denied' });

const { result } = setup(true, false, false);

await act(async () => {
await result.current();
});

expect(mockEnableNotifications).not.toHaveBeenCalled();
expect(mockSetUiNotificationStatus).not.toHaveBeenCalled();
});

it('should track event when notifications settings are updated', async () => {
(NotificationsService.getAllPermissions as jest.Mock).mockResolvedValue({ permission: 'authorized' });

const { result } = setup(true, false, true);

await act(async () => {
await result.current();
});

expect(mockTrackEvent).toHaveBeenCalledWith(MetaMetricsEvents.NOTIFICATIONS_SETTINGS_UPDATED, {
settings_type: 'notifications',
old_value: false,
new_value: true,
was_profile_syncing_on: true,
});
});
});

describe('NotificationsSettings', () => {
it('should render correctly', () => {
it('render matches snapshot', () => {
mockGetState.mockImplementation(() => ({
notifications: {},
}));
Expand All @@ -199,21 +72,4 @@ describe('NotificationsSettings', () => {
);
expect(toJSON()).toMatchSnapshot();
});

it('should toggle notifications and handle permission correctly', async () => {
const isMetamaskNotificationsEnabled = true;
const basicFunctionalityEnabled = true;
const isProfileSyncingEnabled = true;

const toggleNotificationsEnabledImpl = jest.fn(() => Promise.resolve({
isMetamaskNotificationsEnabled,
basicFunctionalityEnabled,
isProfileSyncingEnabled,
}));

await toggleNotificationsEnabledImpl();

expect(NotificationsService.getAllPermissions).toHaveBeenCalledTimes(1);
expect(NotificationsService.getAllPermissions).toHaveBeenCalledWith(false);
});
});
Loading

0 comments on commit cfeab8d

Please sign in to comment.