Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Fix snapshot transition bug #889

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/mobile/__tests__/ui/views/wallet/SnapshotTransition.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import assign from 'lodash/assign';
import noop from 'lodash/noop';
import React from 'react';
import { shallow } from 'enzyme';
import { SnapshotTransition as SnapshotTransitionComponent } from 'ui/views/wallet/SnapshotTransition';

jest.mock('react-native-is-device-rooted', () => ({
isDeviceRooted: () => true,
isDeviceLocked: () => false,
}));

jest.mock('bugsnag-react-native', () => ({
Configuration: jest.fn(),
Client: jest.fn(() => ({ leaveBreadcrumb: jest.fn() })),
}));

const getProps = (overrides) =>
assign(
{},
{
isTransitioning: false,
t: () => '',
transitionForSnapshot: noop,
transitionBalance: 0,
balanceCheckFlag: false,
theme: { body: {}, primary: { color: '#862888', body: '#FFFFFF' } },
generateAddressesAndGetBalance: noop,
transitionAddresses: [],
completeSnapshotTransition: noop,
selectedAccountName: 'foo',
selectedAccountMeta: {},
generateAlert: noop,
setSetting: noop,
addresses: [],
shouldPreventAction: false,
isAttachingToTangle: false,
password: {},
activeStepIndex: -1,
activeSteps: [],
setBalanceCheckFlag: noop,
cancelSnapshotTransition: noop,
},
overrides,
);

describe('Testing SnapshotTransition component', () => {
describe('when mounts', () => {
it('should call prop method cancelSnapshotTransition', () => {
const props = getProps({
cancelSnapshotTransition: jest.fn(),
});

shallow(<SnapshotTransitionComponent {...props} />);

expect(props.cancelSnapshotTransition).toHaveBeenCalled();
});
});
});
4 changes: 2 additions & 2 deletions src/mobile/src/ui/components/SettingsContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import LanguageSelection from 'ui/views/wallet/LanguageSelection';
import ChangePassword from 'ui/views/wallet/ChangePassword';
import ManualSyncComponent from 'ui/views/wallet/ManualSync';
import ThemeCustomisation from 'ui/views/wallet/ThemeCustomisation';
import SnapshotTransition from 'ui/views/wallet/SnapshotTransition';
import SnapshotTransitionComponent from 'ui/views/wallet/SnapshotTransition';
import SecuritySettings from 'ui/views/wallet/SecuritySettings';
import SeedVaultSettings from 'ui/views/wallet/SeedVaultSettings';
import About from 'ui/views/wallet/About';
Expand All @@ -49,7 +49,7 @@ const SETTINGS_COMPONENTS = {
changePassword: ChangePassword,
manualSync: ManualSyncComponent,
themeCustomisation: ThemeCustomisation,
snapshotTransition: SnapshotTransition,
snapshotTransition: SnapshotTransitionComponent,
securitySettings: SecuritySettings,
modeSelection: ModeSelection,
pow: ProofOfWork,
Expand Down
7 changes: 6 additions & 1 deletion src/mobile/src/ui/views/wallet/SnapshotTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const styles = StyleSheet.create({
},
});

class SnapshotTransition extends Component {
export class SnapshotTransition extends Component {
static propTypes = {
/** @ignore */
isTransitioning: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -166,6 +166,11 @@ class SnapshotTransition extends Component {

componentDidMount() {
leaveNavigationBreadcrumb('SnapshotTransition');

// Cancelling snapshot transition (i.e., navigating back to any other screen) while address generation is in progress
// will add transition addresses to redux store. Say a user swaps accounts and revist this screen, then it will mix transition addresses in redux store
// Hence, just reset transition addresses every time this screen is mounted
this.props.cancelSnapshotTransition();
}

componentWillReceiveProps(newProps) {
Expand Down