-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9cbd9a
commit 8eea42a
Showing
8 changed files
with
212 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<link rel="import" href="../../../bower_components/polymer/polymer-element.html"> | ||
<link rel="import" href="../lib/redux-mixin.html"> | ||
<link rel="import" href="./unlock-view.html"> | ||
|
||
<dom-module id="unlock-container"> | ||
<template> | ||
<unlock-view | ||
id="view" | ||
pending="[[pending]]" | ||
has-error="[[hasError]]" | ||
error-text="[[errorText]]" | ||
on-unlock="_unlock" | ||
></unlock-view> | ||
</template> | ||
|
||
<script> | ||
class UnlockContainer extends Polymer.ReduxMixin(Polymer.Element) { | ||
static get is() { | ||
return 'unlock-container'; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
is: { | ||
type: String, | ||
value: UnlockContainer.is, | ||
}, | ||
hasError: { | ||
type: Boolean, | ||
statePath: app.unlock.hasError, | ||
}, | ||
errorText: { | ||
type: String, | ||
statePath: app.unlock.getErrorText, | ||
}, | ||
complete: { | ||
type: Boolean, | ||
statePath: app.unlock.isComplete, | ||
}, | ||
settings: { | ||
type: Object, | ||
statePath: app.unlock.getSettings, | ||
}, | ||
}; | ||
} | ||
|
||
static get actions() { | ||
return { | ||
submit: app.unlock.submit, | ||
complete: app.completeUnlock, | ||
}; | ||
} | ||
|
||
ready() { | ||
super.ready(); | ||
this.addEventListener('state-changed', () => this._stateChanged()); | ||
} | ||
|
||
_stateChanged() { | ||
if (this.complete) { | ||
this.$.view.reset(); | ||
this.dispatch('complete', { | ||
settings: this.settings, | ||
}); | ||
} | ||
} | ||
|
||
_unlock(event) { | ||
this.dispatch('submit', event.detail.passphrase); | ||
} | ||
} | ||
window.customElements.define(UnlockContainer.is, UnlockContainer); | ||
</script> | ||
</dom-module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes"> | ||
|
||
<title>unlock-container</title> | ||
|
||
<script src="../../../../bower_components/webcomponentsjs/webcomponents-lite.js"></script> | ||
<script src="../../../../bower_components/web-component-tester/browser.js"></script> | ||
|
||
<link rel="import" href="../../helpers/common.html"> | ||
<link rel="import" href="../../../src/unlock/unlock-container.html"> | ||
</head> | ||
<body> | ||
<test-fixture id="defaultAttributes"> | ||
<template> | ||
<unlock-container></unlock-container> | ||
</template> | ||
</test-fixture> | ||
|
||
<script> | ||
let unlockContainer; | ||
describe('unlock-container', function() { | ||
beforeEach(function() { | ||
app.helpers.reset(); | ||
unlockContainer = fixture('defaultAttributes'); | ||
}); | ||
|
||
it('should have the correct type', function() { | ||
unlockContainer.is.should.eql('unlock-container'); | ||
}); | ||
|
||
it('should contain a view element', function() { | ||
unlockContainer.$.view.is.should.eql('unlock-view'); | ||
}); | ||
|
||
it('should set the default view attributes', function() { | ||
unlockContainer.$.view.hasError.should.be.false; | ||
unlockContainer.$.view.errorText.should.eql(''); | ||
}); | ||
|
||
it('should set the view error attributes', function() { | ||
app.unlock.hasError.value = true; | ||
app.unlock.getErrorText.value = 'FAIL'; | ||
app.helpers.notifyStateChange(); | ||
unlockContainer.$.view.hasError.should.be.true; | ||
unlockContainer.$.view.errorText.should.eql('FAIL'); | ||
}); | ||
|
||
describe('on an unlock event', function() { | ||
beforeEach(function() { | ||
unlockContainer.$.view.dispatchEvent(new CustomEvent('unlock', { | ||
detail: { | ||
passphrase: 'passphrase', | ||
}, | ||
})); | ||
}); | ||
|
||
it('should unlock the settings', function() { | ||
app.unlock.submit.should.have.been.calledWith( | ||
'passphrase' | ||
); | ||
app.store.dispatch.should.have.been.calledWith( | ||
app.unlock.submit.value | ||
); | ||
}); | ||
}); | ||
|
||
describe('on complete', function() { | ||
beforeEach(function() { | ||
sinon.spy(unlockContainer.$.view, 'reset'); | ||
app.unlock.getSettings.value = {}; | ||
app.unlock.isComplete.value = true; | ||
app.helpers.notifyStateChange(); | ||
}); | ||
|
||
it('should reset the view', function() { | ||
unlockContainer.$.view.reset.should.have.been.calledOnce; | ||
}); | ||
|
||
it('should complete the unlock', function() { | ||
app.completeUnlock.should.have.been.calledWith({ | ||
settings: {}, | ||
}); | ||
app.store.dispatch.should.have.been.calledWith( | ||
app.completeUnlock.value | ||
); | ||
}); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters