Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added async to ProposedSolution
  • Loading branch information
MicheleBertoli committed Jan 14, 2014
1 parent 34d6508 commit 295a897
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
Expand Up @@ -5,37 +5,37 @@ describe('Unicode To Htm Converter', function () {
it('should convert ampersand', function () {

var stubTextStream = a.stub(TextStream);
spyOn(stubTextStream, 'getText').andCallFake(function () { return 'Cut & Paste'; });
spyOn(stubTextStream, 'getText').andCallFake(function (callback) { return callback('Cut & Paste'); });
var target = new UnicodeFileToHtmTextConverter(stubTextStream);

var result = target.convertToHtml();

expect(result).toEqual('Cut & Paste');
target.convertToHtml(function(result) {
expect(result).toEqual('Cut & Paste');
});

});

it('should convert greate than and less than', function () {

var stubTextStream = a.stub(TextStream);
spyOn(stubTextStream, 'getText').andCallFake(function () { return '10 > 5; 5 < 10'; });
spyOn(stubTextStream, 'getText').andCallFake(function (callback) { return callback('10 > 5; 5 < 10'); });
var target = new UnicodeFileToHtmTextConverter(stubTextStream);

var result = target.convertToHtml();

expect(result).toEqual('10 &gt; 5; 5 &lt; 10');
target.convertToHtml(function(result) {
expect(result).toEqual('10 &gt; 5; 5 &lt; 10');
});

});


it('should add breakline for multiple lines', function () {

var stubTextStream = a.stub(TextStream);
spyOn(stubTextStream, 'getText').andCallFake(function () { return 'hello\nhow are you doing?\n'; });
spyOn(stubTextStream, 'getText').andCallFake(function (callback) { return callback('hello\nhow are you doing?\n'); });
var target = new UnicodeFileToHtmTextConverter(stubTextStream);

var result = target.convertToHtml();

expect(result).toEqual('hello<br />how are you doing?<br />');
target.convertToHtml(function(result) {
expect(result).toEqual('hello<br />how are you doing?<br />');
});

});
});
Expand Down
Expand Up @@ -4,16 +4,18 @@ TextStream = function (fileBlob) {

TextStream.prototype = {

getText: function () {
getText: function (callback) {

var fileReader = new FileReader();
var text;
fileReader.onload = function (evt) {
text = evt.target.result;
if (callback) {
callback(text);
}
};

fileReader.readAsText(this._fileBlob);

return text;
}

};
Expand Up @@ -9,12 +9,16 @@ UnicodeFileToHtmTextConverter.CreateFromFileBlob = function(fileBlob) {

UnicodeFileToHtmTextConverter.prototype = {

convertToHtml: function () {
convertToHtml: function (callback) {

var text = this._textStream.getText();
var htmlLines = this._basicHtmlEncode(text);

return htmlLines;
var self = this;
self._textStream.getText(function(text) {
var htmlLines = self._basicHtmlEncode(text);
if (callback) {
callback(htmlLines);
}
});

},

_basicHtmlEncode: function (source) {
Expand Down

0 comments on commit 295a897

Please sign in to comment.