2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { mountWithRouter } from '../../../test/lib/render-helpers';
|
2021-03-16 22:00:08 +01:00
|
|
|
import Lock from './lock.container';
|
2020-11-09 14:50:24 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Lock', () => {
|
|
|
|
it('replaces history with default route when isUnlocked false', () => {
|
2020-11-09 14:50:24 +01:00
|
|
|
const props = {
|
|
|
|
isUnlocked: false,
|
|
|
|
history: {
|
|
|
|
replace: sinon.spy(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-09 14:50:24 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
mountWithRouter(<Lock.WrappedComponent {...props} />);
|
2020-11-09 14:50:24 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.history.replace.getCall(0).args[0]).toStrictEqual('/');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-11-09 14:50:24 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('locks and pushes history with default route when isUnlocked true', async () => {
|
2020-11-09 14:50:24 +01:00
|
|
|
const props = {
|
|
|
|
isUnlocked: true,
|
|
|
|
lockMetamask: sinon.stub(),
|
|
|
|
history: {
|
|
|
|
push: sinon.spy(),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-09 14:50:24 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
props.lockMetamask.resolves();
|
2020-11-09 14:50:24 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
mountWithRouter(<Lock.WrappedComponent {...props} />);
|
2020-11-09 14:50:24 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(await props.lockMetamask.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.history.push.getCall(0).args[0]).toStrictEqual('/');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|