Skip to content

Commit

Permalink
feat: Allow showing the password being typed in the new user form
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
courajs committed Jun 2, 2016
1 parent 7164a05 commit 6ee4ede
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/components/new-user/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
New user's name:
{{input value=username data-test-selector="new-user-name"}}
</label>
<label>
<label data-test-selector="new-user-password">
New user's password:
{{input type='password' value=password data-test-selector="new-user-password"}}
{{show-password-toggle value=password}}
</label>
<button {{action createUser (hash username=username password=password)}} data-test-selector='new-user-submit'>Add user</button>
</form>
9 changes: 9 additions & 0 deletions app/components/show-password-toggle/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Ember from 'ember';

const {
Component
} = Ember;

export default Component.extend({
inputType: 'password'
});
11 changes: 11 additions & 0 deletions app/components/show-password-toggle/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{input type=inputType value=value}}
{{#if (eq inputType 'password')}}
<button {{action (action (mut inputType) 'text')}} data-test-selector="password-visibility-toggle">
Show password
</button>
{{else}}
<button {{action (action (mut inputType) 'password')}} data-test-selector="password-visibility-toggle">
Hide password
</button>
{{/if}}

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@
"loader.js": "^4.0.1",
"morgan": "^1.7.0",
"semantic-release": "^6.2.2"
},
"dependencies": {
"ember-truth-helpers": "^1.2.0"
}
}
4 changes: 2 additions & 2 deletions tests/integration/components/new-user-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('it renders', function(assert) {

this.$('[data-test-selector="new-user-name"]').val(username);
this.$('[data-test-selector="new-user-name"]').trigger('change');
this.$('[data-test-selector="new-user-password"]').val(password);
this.$('[data-test-selector="new-user-password"]').trigger('change');
this.$('[data-test-selector="new-user-password"] input').val(password);
this.$('[data-test-selector="new-user-password"] input').trigger('change');
this.$('[data-test-selector="new-user-submit"]').click();
});
39 changes: 39 additions & 0 deletions tests/integration/components/show-password-toggle-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('show-password-toggle', 'Integration | Component | show password toggle', {
integration: true
});

test('it toggles input type', function(assert) {
assert.expect(2);

this.render(hbs`{{show-password-toggle}}`);

assert.equal(this.$('input').attr('type'), 'password');

this.$('[data-test-selector="password-visibility-toggle"]').click();

assert.equal(this.$('input').attr('type'), 'text');
});

test('it binds to `value` just like `{{input`', function(assert) {
assert.expect(3);

this.set('value', 'hello');

this.render(hbs`{{show-password-toggle value=value}}`);

assert.equal(this.$('input').val(), 'hello');

this.$('input').val('hello world');
this.$('input').trigger('change');

assert.equal(this.get('value'), 'hello world');

this.$('[data-test-selector="password-visibility-toggle"]').click();
this.$('input').val('hello world!');
this.$('input').trigger('change');

assert.equal(this.get('value'), 'hello world!');
});

0 comments on commit 6ee4ede

Please sign in to comment.