Skip to content

Instantly share code, notes, and snippets.

@jherdman
Created November 9, 2016 19:51
Show Gist options
  • Select an option

  • Save jherdman/d3b50f67c5771490c41eaaa7fb66bd40 to your computer and use it in GitHub Desktop.

Select an option

Save jherdman/d3b50f67c5771490c41eaaa7fb66bd40 to your computer and use it in GitHub Desktop.

Revisions

  1. jherdman created this gist Nov 9, 2016.
    36 changes: 36 additions & 0 deletions register-upload-file.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    /* global Blob */

    // put in tests/helpers

    import Ember from 'ember';

    const {
    Test: {
    registerAsyncHelper,
    },
    } = Ember;

    function createFile(content = ['test'], options = {}) {
    const {
    name,
    type
    } = options;

    const file = new Blob(content, { type : type ? type : 'text/plain' });
    file.name = name ? name : 'test.txt';

    return file;
    }


    export default function() {
    registerAsyncHelper('uploadFile', function(app, selector, content, options, eventType = 'change') {
    const file = createFile(content, options);

    return triggerEvent(
    selector,
    eventType,
    { testingFiles: [file] }
    );
    });
    }
    3 changes: 3 additions & 0 deletions some-acceptance-test.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    andThen(function() {
    uploadFile(domSelector, ['fake-file-contents'], { name: 'foo.jpg', type: 'image/jpeg' });
    });