1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

IPFS unit test for onboarding privacy setting (#18252)

This commit is contained in:
Thomas Huang 2023-03-31 10:27:36 +08:00 committed by GitHub
parent ed3cc404f2
commit 00e6471d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 0 deletions

View File

@ -246,6 +246,7 @@ export default function PrivacySettings() {
<Box paddingTop={2}>
<TextField
style={{ width: '100%' }}
inputProps={{ 'data-testid': 'ipfs-input' }}
onChange={(e) => {
handleIPFSChange(e.target.value);
}}

View File

@ -23,6 +23,7 @@ describe('Privacy Settings Onboarding View', () => {
const setUsePhishDetectStub = jest.fn();
const setUseTokenDetectionStub = jest.fn();
const setUseCurrencyRateCheckStub = jest.fn();
const setIpfsGatewayStub = jest.fn();
const completeOnboardingStub = jest
.fn()
.mockImplementation(() => Promise.resolve());
@ -33,6 +34,7 @@ describe('Privacy Settings Onboarding View', () => {
setUsePhishDetect: setUsePhishDetectStub,
setUseTokenDetection: setUseTokenDetectionStub,
setUseCurrencyRateCheck: setUseCurrencyRateCheckStub,
setIpfsGateway: setIpfsGatewayStub,
completeOnboarding: completeOnboardingStub,
setUseMultiAccountBalanceChecker: setUseMultiAccountBalanceCheckerStub,
});
@ -95,4 +97,70 @@ describe('Privacy Settings Onboarding View', () => {
);
expect(setUseCurrencyRateCheckStub.mock.calls[1][0]).toStrictEqual(true);
});
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();
});
});
});