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 { mount } from 'enzyme'
|
2020-08-19 18:27:05 +02:00
|
|
|
import UnlockPage from '..'
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Unlock Page', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
let wrapper
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
history: {
|
|
|
|
push: sinon.spy(),
|
|
|
|
},
|
|
|
|
isUnlocked: false,
|
|
|
|
onImport: sinon.spy(),
|
|
|
|
onRestore: sinon.spy(),
|
|
|
|
onSubmit: sinon.spy(),
|
|
|
|
forceUpdateMetamaskState: sinon.spy(),
|
|
|
|
showOptInModal: sinon.spy(),
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = mount(<UnlockPage.WrappedComponent {...props} />, {
|
|
|
|
context: {
|
|
|
|
t: (str) => str,
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
})
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
after(function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
sinon.restore()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('renders', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
assert.equal(wrapper.length, 1)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('changes password and submits', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const passwordField = wrapper.find({ type: 'password', id: 'password' })
|
|
|
|
const loginButton = wrapper.find({ type: 'submit' }).last()
|
|
|
|
|
|
|
|
const event = { target: { value: 'password' } }
|
|
|
|
assert.equal(wrapper.instance().state.password, '')
|
|
|
|
passwordField.last().simulate('change', event)
|
|
|
|
assert.equal(wrapper.instance().state.password, 'password')
|
|
|
|
|
|
|
|
loginButton.simulate('click')
|
|
|
|
assert(props.onSubmit.calledOnce)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('clicks imports seed button', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const importSeedButton = wrapper.find('.unlock-page__link--import')
|
|
|
|
|
|
|
|
importSeedButton.simulate('click')
|
|
|
|
assert(props.onImport.calledOnce)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('clicks restore', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const restoreFromSeedButton = wrapper.find('.unlock-page__link').at(0)
|
|
|
|
restoreFromSeedButton.simulate('click')
|
|
|
|
assert(props.onRestore.calledOnce)
|
|
|
|
})
|
|
|
|
})
|