Skip to content

Commit

Permalink
Merge branch 'develop' into 17191/onboarding-unit-tests-add-network-m…
Browse files Browse the repository at this point in the history
…odal
  • Loading branch information
tmashuang authored Mar 31, 2023
2 parents 060a402 + 00e6471 commit 1811325
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}}
Expand Down
68 changes: 68 additions & 0 deletions ui/pages/onboarding-flow/privacy-settings/privacy-settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -33,6 +34,7 @@ describe('Privacy Settings Onboarding View', () => {
setUsePhishDetect: setUsePhishDetectStub,
setUseTokenDetection: setUseTokenDetectionStub,
setUseCurrencyRateCheck: setUseCurrencyRateCheckStub,
setIpfsGateway: setIpfsGatewayStub,
completeOnboarding: completeOnboardingStub,
setUseMultiAccountBalanceChecker: setUseMultiAccountBalanceCheckerStub,
});
Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit 1811325

Please sign in to comment.