2020-01-30 20:34:45 +01:00
|
|
|
import assert from 'assert'
|
2020-08-18 21:18:25 +02:00
|
|
|
import React from 'react'
|
2020-01-30 20:34:45 +01:00
|
|
|
import sinon from 'sinon'
|
|
|
|
import { mountWithRouter } from '../../../../../test/lib/render-helpers'
|
2020-08-19 18:27:05 +02:00
|
|
|
import Lock from '..'
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Lock', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('replaces history with default route when isUnlocked false', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
isUnlocked: false,
|
|
|
|
history: {
|
|
|
|
replace: sinon.spy(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
mountWithRouter(
|
2020-07-14 17:20:41 +02:00
|
|
|
<Lock.WrappedComponent {...props} />,
|
2020-01-30 20:34:45 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
assert.equal(props.history.replace.getCall(0).args[0], '/')
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('locks and pushes history with default route when isUnlocked true', function (done) {
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
isUnlocked: true,
|
|
|
|
lockMetamask: sinon.stub(),
|
|
|
|
history: {
|
|
|
|
push: sinon.spy(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
props.lockMetamask.resolves()
|
|
|
|
|
|
|
|
mountWithRouter(
|
2020-07-14 17:20:41 +02:00
|
|
|
<Lock.WrappedComponent {...props} />,
|
2020-01-30 20:34:45 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
assert(props.lockMetamask.calledOnce)
|
|
|
|
setImmediate(() => {
|
|
|
|
assert.equal(props.history.push.getCall(0).args[0], '/')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|