Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing test for selectFiles on Acceptance. #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tests/acceptance/usage-in-acceptance-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
import { visit, click, find, fillIn, waitUntil, currentURL, currentRouteName } from 'ember-native-dom-helpers';
import { visit, click, find, fillIn, waitUntil, currentURL, currentRouteName, selectFiles } from 'ember-native-dom-helpers';

moduleForAcceptance('Acceptance | usage in acceptance', {
beforeEach() {
Expand Down Expand Up @@ -55,3 +55,14 @@ test('Usage using `waitUntil` to test unsettled state', async function(assert) {
assert.equal(currentRouteName(), 'dashboard-example', 'The currentRouteName has updated');
assert.ok(find('.dashboard-example-header'), 'We are on the dashboard now');
});

test('Usage `selectFiles`', async function(assert) {
await visit('/signup-example');

let blob = new Blob(['foo', 'bar'], { type: 'text/plain' });
let file = new File([blob], 'avatar.png');

selectFiles('.signup-example-form__avatar', file);
assert.equal(find('.signup-example-form__avatar-file-name').innerText, 'avatar.png', 'The file name is showed');
});

8 changes: 7 additions & 1 deletion tests/dummy/app/controllers/signup-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import Controller from '@ember/controller';
import { getProperties, set } from '@ember/object';
import fetch from 'fetch';

export default Controller.extend({
export default Ember.Controller.extend({
avatarFileName: null,

actions: {
onFileSelected(event) {
let files = event.target.files;
this.set('avatarFileName', files[0].name);
},
signup() {
set(this, 'isSaving', true);
let data = JSON.stringify(getProperties(this, 'email', 'password', 'passwordConfirmation'));
Expand Down
4 changes: 4 additions & 0 deletions tests/dummy/app/templates/signup-example.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<h1>Signup example</h1>

<form class="signup-example-form" {{action "signup" on="submit"}}>
<p>
Avatar File: <span class="signup-example-form__avatar-file-name" >{{avatarFileName}}</span>
<input type="file" class="signup-example-form__avatar" onchange={{action "onFileSelected"}} />
</p>
<p>
Email:
<input type="text" class="signup-example-form__email" onchange={{action (mut email) value="target.value"}}>
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5154,7 +5154,7 @@ read@1, read@~1.0.1, read@~1.0.7:
dependencies:
mute-stream "~0.0.4"

"readable-stream@1 || 2", readable-stream@^2.0.2, readable-stream@~2.0.5:
"readable-stream@1 || 2", readable-stream@^2, "readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.2, readable-stream@~2.0.5:
version "2.0.6"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e"
dependencies:
Expand All @@ -5165,7 +5165,7 @@ read@1, read@~1.0.1, read@~1.0.7:
string_decoder "~0.10.x"
util-deprecate "~1.0.1"

readable-stream@^2, "readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.1.4, readable-stream@^2.2.2:
readable-stream@^2.1.4, readable-stream@^2.2.2:
version "2.2.9"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.9.tgz#cf78ec6f4a6d1eb43d26488cac97f042e74b7fc8"
dependencies:
Expand Down Expand Up @@ -5612,13 +5612,13 @@ signal-exit@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"

silent-error@^1.0.0, silent-error@^1.0.1:
silent-error@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/silent-error/-/silent-error-1.0.1.tgz#71b7d503d1c6f94882b51b56be879b113cb4822c"
dependencies:
debug "^2.2.0"

silent-error@^1.1.0:
silent-error@^1.0.1, silent-error@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/silent-error/-/silent-error-1.1.0.tgz#2209706f1c850a9f1d10d0d840918b46f26e1bc9"
dependencies:
Expand Down