Merge pull request #18809 from owncloud/fix-tags-fileinfomodel

Tags in FileInfo map must be an array
This commit is contained in:
Robin Appelman 2015-09-03 14:08:00 +02:00
commit e9e42fff61
2 changed files with 22 additions and 1 deletions

View File

@ -150,7 +150,13 @@
var oldElementToFile = fileList.elementToFile;
fileList.elementToFile = function($el) {
var fileInfo = oldElementToFile.apply(this, arguments);
fileInfo.tags = $el.attr('data-tags') || [];
var tags = $el.attr('data-tags');
if (_.isUndefined(tags)) {
tags = '';
}
tags = tags.split('|');
tags = _.without(tags, '');
fileInfo.tags = tags;
return fileInfo;
};
},

View File

@ -112,4 +112,19 @@ describe('OCA.Files.TagsPlugin tests', function() {
expect($action.find('img').attr('src')).toEqual(OC.imagePath('core', 'actions/star'));
});
});
describe('elementToFile', function() {
it('returns tags', function() {
fileList.setFiles(testFiles);
var $tr = fileList.findFileEl('One.txt');
var data = fileList.elementToFile($tr);
expect(data.tags).toEqual(['tag1', 'tag2']);
});
it('returns empty array when no tags present', function() {
delete testFiles[0].tags;
fileList.setFiles(testFiles);
var $tr = fileList.findFileEl('One.txt');
var data = fileList.elementToFile($tr);
expect(data.tags).toEqual([]);
});
});
});