2021-10-08 21:50:36 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { fireEvent } from '@testing-library/react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
2021-10-20 20:55:59 +02:00
|
|
|
import {
|
|
|
|
renderWithProvider,
|
|
|
|
setBackgroundConnection,
|
|
|
|
} from '../../../../test/jest';
|
2023-08-24 12:27:42 +02:00
|
|
|
import { CHAIN_IDS } from '../../../../shared/constants/network';
|
2021-10-08 21:50:36 +02:00
|
|
|
import PrivacySettings from './privacy-settings';
|
|
|
|
|
|
|
|
describe('Privacy Settings Onboarding View', () => {
|
|
|
|
const mockStore = {
|
|
|
|
metamask: {
|
2023-03-09 22:00:28 +01:00
|
|
|
networkConfigurations: {},
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2021-10-08 21:50:36 +02:00
|
|
|
type: 'test',
|
|
|
|
},
|
2023-08-24 12:27:42 +02:00
|
|
|
incomingTransactionsPreferences: {
|
|
|
|
[CHAIN_IDS.MAINNET]: true,
|
|
|
|
[CHAIN_IDS.LINEA_MAINNET]: false,
|
|
|
|
[CHAIN_IDS.GOERLI]: false,
|
|
|
|
[CHAIN_IDS.SEPOLIA]: false,
|
|
|
|
[CHAIN_IDS.LINEA_GOERLI]: true,
|
|
|
|
},
|
2021-10-08 21:50:36 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const store = configureMockStore([thunk])(mockStore);
|
|
|
|
const setFeatureFlagStub = jest.fn();
|
|
|
|
const setUsePhishDetectStub = jest.fn();
|
2023-08-04 19:28:37 +02:00
|
|
|
const setUse4ByteResolutionStub = jest.fn();
|
2021-10-08 21:50:36 +02:00
|
|
|
const setUseTokenDetectionStub = jest.fn();
|
2023-01-17 16:23:04 +01:00
|
|
|
const setUseCurrencyRateCheckStub = jest.fn();
|
2023-03-31 04:27:36 +02:00
|
|
|
const setIpfsGatewayStub = jest.fn();
|
2021-10-20 20:55:59 +02:00
|
|
|
const completeOnboardingStub = jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve());
|
2022-12-01 22:16:04 +01:00
|
|
|
const setUseMultiAccountBalanceCheckerStub = jest.fn();
|
2023-07-28 18:21:43 +02:00
|
|
|
const setUseAddressBarEnsResolutionStub = jest.fn();
|
2023-08-24 12:27:42 +02:00
|
|
|
const setIncomingTransactionsPreferencesStub = jest.fn();
|
2021-10-08 21:50:36 +02:00
|
|
|
|
2021-10-20 20:55:59 +02:00
|
|
|
setBackgroundConnection({
|
2021-10-08 21:50:36 +02:00
|
|
|
setFeatureFlag: setFeatureFlagStub,
|
|
|
|
setUsePhishDetect: setUsePhishDetectStub,
|
2023-08-04 19:28:37 +02:00
|
|
|
setUse4ByteResolution: setUse4ByteResolutionStub,
|
2021-10-08 21:50:36 +02:00
|
|
|
setUseTokenDetection: setUseTokenDetectionStub,
|
2023-01-17 16:23:04 +01:00
|
|
|
setUseCurrencyRateCheck: setUseCurrencyRateCheckStub,
|
2023-03-31 04:27:36 +02:00
|
|
|
setIpfsGateway: setIpfsGatewayStub,
|
2021-10-20 20:55:59 +02:00
|
|
|
completeOnboarding: completeOnboardingStub,
|
2022-12-01 22:16:04 +01:00
|
|
|
setUseMultiAccountBalanceChecker: setUseMultiAccountBalanceCheckerStub,
|
2023-07-28 18:21:43 +02:00
|
|
|
setUseAddressBarEnsResolution: setUseAddressBarEnsResolutionStub,
|
2023-08-24 12:27:42 +02:00
|
|
|
setIncomingTransactionsPreferences: setIncomingTransactionsPreferencesStub,
|
2021-10-08 21:50:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should update preferences', () => {
|
|
|
|
const { container, getByText } = renderWithProvider(
|
|
|
|
<PrivacySettings />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
// All settings are initialized toggled to true
|
|
|
|
expect(setUsePhishDetectStub).toHaveBeenCalledTimes(0);
|
2023-08-04 19:28:37 +02:00
|
|
|
expect(setUse4ByteResolutionStub).toHaveBeenCalledTimes(0);
|
2021-10-08 21:50:36 +02:00
|
|
|
expect(setUseTokenDetectionStub).toHaveBeenCalledTimes(0);
|
2022-12-01 22:16:04 +01:00
|
|
|
expect(setUseMultiAccountBalanceCheckerStub).toHaveBeenCalledTimes(0);
|
2023-01-17 16:23:04 +01:00
|
|
|
expect(setUseCurrencyRateCheckStub).toHaveBeenCalledTimes(0);
|
2023-07-28 18:21:43 +02:00
|
|
|
expect(setUseAddressBarEnsResolutionStub).toHaveBeenCalledTimes(0);
|
2023-08-24 12:27:42 +02:00
|
|
|
expect(setIncomingTransactionsPreferencesStub).toHaveBeenCalledTimes(0);
|
2022-12-01 22:16:04 +01:00
|
|
|
|
2021-10-08 21:50:36 +02:00
|
|
|
const toggles = container.querySelectorAll('input[type=checkbox]');
|
|
|
|
const submitButton = getByText('Done');
|
|
|
|
// toggle to false
|
|
|
|
fireEvent.click(toggles[1]);
|
2023-08-04 19:28:37 +02:00
|
|
|
fireEvent.click(toggles[6]);
|
2023-08-24 12:27:42 +02:00
|
|
|
fireEvent.click(toggles[7]);
|
|
|
|
fireEvent.click(toggles[8]);
|
|
|
|
fireEvent.click(toggles[9]);
|
|
|
|
fireEvent.click(toggles[10]);
|
|
|
|
fireEvent.click(toggles[11]);
|
|
|
|
|
2021-10-08 21:50:36 +02:00
|
|
|
fireEvent.click(submitButton);
|
|
|
|
|
2023-08-24 12:27:42 +02:00
|
|
|
expect(setIncomingTransactionsPreferencesStub).toHaveBeenCalledTimes(1);
|
2021-10-08 21:50:36 +02:00
|
|
|
expect(setUsePhishDetectStub).toHaveBeenCalledTimes(1);
|
2023-08-04 19:28:37 +02:00
|
|
|
expect(setUse4ByteResolutionStub).toHaveBeenCalledTimes(1);
|
2021-10-08 21:50:36 +02:00
|
|
|
expect(setUseTokenDetectionStub).toHaveBeenCalledTimes(1);
|
2022-12-01 22:16:04 +01:00
|
|
|
expect(setUseMultiAccountBalanceCheckerStub).toHaveBeenCalledTimes(1);
|
2023-01-17 16:23:04 +01:00
|
|
|
expect(setUseCurrencyRateCheckStub).toHaveBeenCalledTimes(1);
|
2023-07-28 18:21:43 +02:00
|
|
|
expect(setUseAddressBarEnsResolutionStub).toHaveBeenCalledTimes(1);
|
2023-01-17 16:23:04 +01:00
|
|
|
|
2023-08-24 12:27:42 +02:00
|
|
|
expect(setIncomingTransactionsPreferencesStub).toHaveBeenCalledWith(
|
|
|
|
CHAIN_IDS.MAINNET,
|
|
|
|
false,
|
|
|
|
expect.anything(),
|
|
|
|
);
|
|
|
|
|
2021-10-08 21:50:36 +02:00
|
|
|
expect(setUsePhishDetectStub.mock.calls[0][0]).toStrictEqual(false);
|
2023-08-04 19:28:37 +02:00
|
|
|
expect(setUse4ByteResolutionStub.mock.calls[0][0]).toStrictEqual(false);
|
2021-10-08 21:50:36 +02:00
|
|
|
expect(setUseTokenDetectionStub.mock.calls[0][0]).toStrictEqual(false);
|
2022-12-01 22:16:04 +01:00
|
|
|
expect(setUseMultiAccountBalanceCheckerStub.mock.calls[0][0]).toStrictEqual(
|
|
|
|
false,
|
|
|
|
);
|
2023-01-17 16:23:04 +01:00
|
|
|
expect(setUseCurrencyRateCheckStub.mock.calls[0][0]).toStrictEqual(false);
|
2023-07-28 18:21:43 +02:00
|
|
|
expect(setUseAddressBarEnsResolutionStub.mock.calls[0][0]).toStrictEqual(
|
|
|
|
false,
|
|
|
|
);
|
2021-10-08 21:50:36 +02:00
|
|
|
});
|
2023-03-31 04:27:36 +02:00
|
|
|
|
|
|
|
describe('IPFS', () => {
|
|
|
|
it('should handle proper IPFS input', () => {
|
|
|
|
const { queryByTestId, queryByText } = renderWithProvider(
|
|
|
|
<PrivacySettings />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
const ipfsInput = queryByTestId('ipfs-input');
|
|
|
|
const ipfsEvent = {
|
|
|
|
target: {
|
|
|
|
value: 'ipfs.io',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
fireEvent.change(ipfsInput, ipfsEvent);
|
|
|
|
|
|
|
|
const validIpfsUrl = queryByText('IPFS gateway URL is valid');
|
|
|
|
expect(validIpfsUrl).toBeInTheDocument();
|
|
|
|
|
|
|
|
const submitButton = queryByText('Done');
|
|
|
|
fireEvent.click(submitButton);
|
|
|
|
|
|
|
|
expect(setIpfsGatewayStub).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error with gateway.ipfs.io IPFS input', () => {
|
|
|
|
const { queryByTestId, queryByText } = renderWithProvider(
|
|
|
|
<PrivacySettings />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
const ipfsInput = queryByTestId('ipfs-input');
|
|
|
|
const ipfsEvent = {
|
|
|
|
target: {
|
|
|
|
value: 'gateway.ipfs.io',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
fireEvent.change(ipfsInput, ipfsEvent);
|
|
|
|
|
|
|
|
const invalidErrorMsg = queryByText('Please enter a valid URL');
|
|
|
|
|
|
|
|
expect(invalidErrorMsg).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error with improper IPFS input', () => {
|
|
|
|
const { queryByTestId, queryByText } = renderWithProvider(
|
|
|
|
<PrivacySettings />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
const ipfsInput = queryByTestId('ipfs-input');
|
|
|
|
const ipfsEvent = {
|
|
|
|
target: {
|
|
|
|
value: ' ',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
fireEvent.change(ipfsInput, ipfsEvent);
|
|
|
|
|
|
|
|
const invalidErrorMsg = queryByText('Please enter a valid URL');
|
|
|
|
|
|
|
|
expect(invalidErrorMsg).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
2021-10-08 21:50:36 +02:00
|
|
|
});
|