Skip to content

Commit

Permalink
Merge remote branch 'colin/FLUID-4143'
Browse files Browse the repository at this point in the history
* colin/FLUID-4143:
  FLUID-4143: Revived the HTML5Strategy tests.
  FLUID-4143: DemoRemote test is now working happily again.
  FLUID-4143: Revived FileQueueView's unit tests and improved event binding code.
  • Loading branch information
colinbdclark committed Mar 17, 2011
2 parents a06ef22 + fe0b3c3 commit 47a843e
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 129 deletions.
52 changes: 28 additions & 24 deletions src/webapp/components/uploader/js/FileQueueView.js
Expand Up @@ -294,23 +294,10 @@ var fluid_1_4 = fluid_1_4 || {};
that.rowProgressorTemplate = that.locate("rowProgressorTemplate", that.options.uploaderContainer).remove();
};

// TODO: Delete this when we have a viable way of declaratively registering listeners.
var bindModelEvents = function (that) {
that.events.afterFileQueued.addListener(that.addFile);
that.events.onUploadStart.addListener(that.prepareForUpload);
that.events.onFileStart.addListener(that.showFileProgress);
that.events.onFileProgress.addListener(that.updateFileProgress);
that.events.onFileSuccess.addListener(that.markFileComplete);
that.events.onFileError.addListener(that.showErrorForFile);
that.events.afterFileComplete.addListener(that.hideFileProgress);
that.events.afterUploadComplete.addListener(that.refreshAfterUpload);
};

var setupFileQueue = function (that) {
fluid.initDependents(that);
prepareTemplateElements(that);
addKeyboardNavigation(that);
bindModelEvents(that);
};

/**
Expand Down Expand Up @@ -383,6 +370,10 @@ var fluid_1_4 = fluid_1_4 || {};
components: {
scroller: {
type: "fluid.scrollableTable"
},

eventBinder: {
type: "fluid.uploader.fileQueueView.eventBinder"
}
},

Expand Down Expand Up @@ -435,24 +426,37 @@ var fluid_1_4 = fluid_1_4 || {};

events: {
onFileRemoved: "{multiFileUploader}.events.onFileRemoved",

// TODO: FileQueueView only listens for these events. Move them
// somewhere more sensible when such a place exists.
afterFileQueued: "{multiFileUploader}.events.afterFileQueued",
onUploadStart: "{multiFileUploader}.events.onUploadStart",
onFileStart: "{multiFileUploader}.events.onFileStart",
onFileProgress: "{multiFileUploader}.events.onFileProgress",
onFileSuccess: "{multiFileUploader}.events.onFileSuccess",
onFileError: "{multiFileUploader}.events.onFileError",
afterFileComplete: "{multiFileUploader}.events.afterFileComplete",
afterUploadComplete: "{multiFileUploader}.events.afterUploadComplete"
},

mergePolicy: {
model: "preserve"
}
});

/**
* EventBinder declaratively binds FileQueueView's methods as listeners to Uploader events using IoC.
*/
fluid.defaults("fluid.uploader.fileQueueView.eventBinder", {
gradeNames: ["fluid.eventedComponent", "autoInit"]
});

fluid.demands("fluid.uploader.fileQueueView.eventBinder", [
"fluid.uploader.multiFileUploader",
"fluid.uploader.fileQueueView"
], {
options: {
listeners: {
"{multiFileUploader}.events.afterFileQueued": "{fileQueueView}.addFile",
"{multiFileUploader}.events.onUploadStart": "{fileQueueView}.prepareForUpload",
"{multiFileUploader}.events.onFileStart": "{fileQueueView}.showFileProgress",
"{multiFileUploader}.events.onFileProgress": "{fileQueueView}.updateFileProgress",
"{multiFileUploader}.events.onFileSuccess": "{fileQueueView}.markFileComplete",
"{multiFileUploader}.events.onFileError": "{fileQueueView}.showErrorForFile",
"{multiFileUploader}.events.afterFileComplete": "{fileQueueView}.hideFileProgress",
"{multiFileUploader}.events.afterUploadComplete": "{fileQueueView}.refreshAfterUpload"
}
}
});

/**************
* Scrollable *
Expand Down
Expand Up @@ -81,7 +81,6 @@ https://source.fluidproject.org/svn/LICENSE.txt
var emptyFunction = function () {};

var listeners = {
onUploadStart: emptyFunction,
onFileStart: emptyFunction,
onFileProgress: emptyFunction,
onFileSuccess: emptyFunction,
Expand All @@ -102,20 +101,26 @@ https://source.fluidproject.org/svn/LICENSE.txt

var uploadFilesAndTest = function (files, testBody) {
var tracker = eventTracker(testBody);
fluid.mergeListeners(events, tracker.listeners);

var queue = fluid.uploader.fileQueue();
queue.files = files;

var demoEngine = fluid.uploader.demoRemote(queue, events);

// TODO: Major problem. This code is from the implementation of Uploader.start(), but is required
// before calling an engine's start() method.
var demo = fluid.uploader.demoRemote(queue, {
events: {
onFileProgress: null,
afterFileComplete: null,
afterUploadComplete: null,
onFileSuccess: null,
onFileStart: null,
onFileError: null,
onUploadStop: null
},

listeners: tracker.listeners
});

queue.start();
events.onUploadStart.fire(queue.currentBatch.files);
//

demoEngine.uploadNextFile();
demo.uploadNextFile();

tracker.transcript.files = files;
return tracker.transcript;
Expand Down Expand Up @@ -170,14 +175,8 @@ https://source.fluidproject.org/svn/LICENSE.txt
demoUploadTests.asyncTest("Simulated upload flow: sequence of events.", function () {
// Test with just one file.
uploadFirstFileAndTest(function (transcript) {
jqUnit.assertEquals("We should have received seven upload events.", 7, transcript.length);

jqUnit.assertEquals("The first event of a batch should be onUploadStart.",
"onUploadStart", transcript[0].name);
jqUnit.assertDeepEq("The argument to onUploadStart should be an array containing the current batch.",
transcript.files, transcript[0].args[0]);

checkEventSequenceForFile(transcript.slice(1, transcript.length - 1), file1);
jqUnit.assertEquals("We should have received seven upload events.", 6, transcript.length);
checkEventSequenceForFile(transcript.slice(0, transcript.length - 1), file1);
jqUnit.assertEquals("The last event of a batch should be afterUploadComplete.",
"afterUploadComplete", transcript[transcript.length - 1].name);
jqUnit.assertDeepEq("The argument to afterUploadComplete should be an array containing the current batch.",
Expand All @@ -190,20 +189,16 @@ https://source.fluidproject.org/svn/LICENSE.txt
demoUploadTests.asyncTest("Simulated upload flow: sequence of events for multiple files.", function () {
// Upload three files.
uploadAllFilesAndTest(function (transcript) {
jqUnit.assertEquals("We should have received twenty upload events.", 20, transcript.length);
jqUnit.assertEquals("The first event of a batch should be onUploadStart.",
"onUploadStart", transcript[0].name);
jqUnit.assertDeepEq("The argument to onUploadStart should be an array containing the current batch.",
transcript.files, transcript[0].args[0]);
jqUnit.assertEquals("We should have received nineteen upload events.", 19, transcript.length);

// The first file is 400000 bytes, so it should have 2 progress events, for a total of 5 events.
checkEventSequenceForFile(transcript.slice(1, 6), file1);
checkEventSequenceForFile(transcript.slice(0, 5), file1);

// The second file is 600000 bytes, so it should have 3 progress events, for a total of 6 events.
checkEventSequenceForFile(transcript.slice(6, 12), file2);
checkEventSequenceForFile(transcript.slice(5, 11), file2);

// The second file is 800000 bytes, so it should have 4 progress events, for a total of 7 events.
checkEventSequenceForFile(transcript.slice(12, 19), file3);
checkEventSequenceForFile(transcript.slice(11, transcript.length - 1), file3);

jqUnit.assertEquals("The last event of a batch should be afterUploadComplete.",
"afterUploadComplete", transcript[transcript.length - 1].name);
Expand All @@ -217,13 +212,13 @@ https://source.fluidproject.org/svn/LICENSE.txt
uploadFirstFileAndTest(function (transcript) {
// Check that we're getting valid progress data for the onFileProgress events.
jqUnit.assertEquals("The first onFileProgress event should have 200000 bytes complete.",
200000, transcript[2].args[1]);
200000, transcript[1].args[1]);
jqUnit.assertEquals("The first onFileProgress event should have 400000 bytes in total.",
400000, transcript[2].args[2]);
400000, transcript[1].args[2]);
jqUnit.assertEquals("The first onFileProgress event should have 400000 bytes complete.",
400000, transcript[3].args[1]);
400000, transcript[2].args[1]);
jqUnit.assertEquals("The first onFileProgress event should have 400000 bytes in total.",
400000, transcript[3].args[2]);
400000, transcript[2].args[2]);
start();
});
});
Expand All @@ -232,9 +227,9 @@ https://source.fluidproject.org/svn/LICENSE.txt
uploadSmallFileAndTest(function (transcript) {
// Check that we're getting valid progress data for the onFileProgress events.
jqUnit.assertEquals("The only onFileProgress event should have 165432 bytes complete.",
165432, transcript[2].args[1]);
165432, transcript[1].args[1]);
jqUnit.assertEquals("The only onFileProgress event should have 165432 bytes in total.",
165432, transcript[2].args[2]);
165432, transcript[1].args[2]);
jqUnit.assertNotEquals("There is only one onFileProgress event in the transcript.",
"onFileProgress", transcript[3].name);
start();
Expand All @@ -245,15 +240,15 @@ https://source.fluidproject.org/svn/LICENSE.txt
uploadNotMultipleFileAndTest(function (transcript) {
// Check that we're getting valid progress data for the onFileProgress events.
jqUnit.assertEquals("The first onFileProgress event should have 200000 bytes complete.",
200000, transcript[2].args[1]);
200000, transcript[1].args[1]);
jqUnit.assertEquals("The second onFileProgress event should have 200000 more bytes complete.",
400000, transcript[3].args[1]);
400000, transcript[2].args[1]);
jqUnit.assertEquals("The third onFileProgress event should have 200000 more bytes complete.",
600000, transcript[4].args[1]);
600000, transcript[3].args[1]);
jqUnit.assertEquals("The fourth onFileProgress event should have 200000 more bytes complete.",
800000, transcript[5].args[1]);
800000, transcript[4].args[1]);
jqUnit.assertEquals("The last onFileProgress event should have 12345 more bytes complete.",
812345, transcript[6].args[1]);
812345, transcript[5].args[1]);
start();
});
});
Expand Down

0 comments on commit 47a843e

Please sign in to comment.