2014-11-18 20:53:45 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
describe('OCA.Files.TagsPlugin tests', function() {
|
|
|
|
var fileList;
|
|
|
|
var testFiles;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
var $content = $('<div id="content"></div>');
|
|
|
|
$('#testArea').append($content);
|
|
|
|
// dummy file list
|
|
|
|
var $div = $(
|
|
|
|
'<div>' +
|
|
|
|
'<table id="filestable">' +
|
|
|
|
'<thead></thead>' +
|
|
|
|
'<tbody id="fileList"></tbody>' +
|
|
|
|
'</table>' +
|
|
|
|
'</div>');
|
|
|
|
$('#content').append($div);
|
|
|
|
|
|
|
|
fileList = new OCA.Files.FileList($div);
|
|
|
|
OCA.Files.TagsPlugin.attach(fileList);
|
|
|
|
|
|
|
|
testFiles = [{
|
|
|
|
id: 1,
|
|
|
|
type: 'file',
|
|
|
|
name: 'One.txt',
|
|
|
|
path: '/subdir',
|
|
|
|
mimetype: 'text/plain',
|
|
|
|
size: 12,
|
|
|
|
permissions: OC.PERMISSION_ALL,
|
|
|
|
etag: 'abc',
|
|
|
|
shareOwner: 'User One',
|
|
|
|
isShareMountPoint: false,
|
|
|
|
tags: ['tag1', 'tag2']
|
|
|
|
}];
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
fileList.destroy();
|
|
|
|
fileList = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Favorites icon', function() {
|
|
|
|
it('renders favorite icon and extra data', function() {
|
2017-09-27 13:39:59 +03:00
|
|
|
var $favoriteMark, $tr;
|
2014-11-18 20:53:45 +03:00
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
2017-09-27 13:39:59 +03:00
|
|
|
$favoriteMark = $tr.find('.favorite-mark');
|
|
|
|
expect($favoriteMark.length).toEqual(1);
|
|
|
|
expect($favoriteMark.hasClass('permanent')).toEqual(false);
|
2014-11-18 20:53:45 +03:00
|
|
|
|
|
|
|
expect($tr.attr('data-tags').split('|')).toEqual(['tag1', 'tag2']);
|
|
|
|
expect($tr.attr('data-favorite')).not.toBeDefined();
|
|
|
|
});
|
|
|
|
it('renders permanent favorite icon and extra data', function() {
|
2017-09-27 13:39:59 +03:00
|
|
|
var $favoriteMark, $tr;
|
2014-11-18 20:53:45 +03:00
|
|
|
testFiles[0].tags.push(OC.TAG_FAVORITE);
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
$tr = fileList.$el.find('tbody tr:first');
|
2017-09-27 13:39:59 +03:00
|
|
|
$favoriteMark = $tr.find('.favorite-mark');
|
|
|
|
expect($favoriteMark.length).toEqual(1);
|
|
|
|
expect($favoriteMark.hasClass('permanent')).toEqual(true);
|
2014-11-18 20:53:45 +03:00
|
|
|
|
|
|
|
expect($tr.attr('data-tags').split('|')).toEqual(['tag1', 'tag2', OC.TAG_FAVORITE]);
|
|
|
|
expect($tr.attr('data-favorite')).toEqual('true');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Applying tags', function() {
|
2020-11-10 11:50:46 +03:00
|
|
|
it('through FileActionsMenu sends request to server and updates icon', function(done) {
|
2017-09-27 09:07:20 +03:00
|
|
|
var request;
|
|
|
|
fileList.setFiles(testFiles);
|
|
|
|
var $tr = fileList.findFileEl('One.txt');
|
2017-09-27 13:39:59 +03:00
|
|
|
var $favoriteMark = $tr.find('.favorite-mark');
|
2017-09-27 09:07:20 +03:00
|
|
|
var $showMenuAction = $tr.find('.action-menu');
|
|
|
|
$showMenuAction.click();
|
|
|
|
var $favoriteActionInMenu = $tr.find('.fileActionsMenu .action-favorite');
|
|
|
|
$favoriteActionInMenu.click();
|
|
|
|
|
|
|
|
expect(fakeServer.requests.length).toEqual(1);
|
|
|
|
request = fakeServer.requests[0];
|
|
|
|
expect(JSON.parse(request.requestBody)).toEqual({
|
|
|
|
tags: ['tag1', 'tag2', OC.TAG_FAVORITE]
|
|
|
|
});
|
|
|
|
request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({
|
|
|
|
tags: ['tag1', 'tag2', 'tag3', OC.TAG_FAVORITE]
|
|
|
|
}));
|
|
|
|
|
2020-11-10 11:50:46 +03:00
|
|
|
setTimeout(function () {
|
|
|
|
// re-read the element as it was re-inserted
|
|
|
|
$tr = fileList.findFileEl('One.txt');
|
|
|
|
$favoriteMark = $tr.find('.favorite-mark');
|
|
|
|
$showMenuAction = $tr.find('.action-menu');
|
2017-09-27 09:07:20 +03:00
|
|
|
|
2020-11-10 11:50:46 +03:00
|
|
|
expect($tr.attr('data-favorite')).toEqual('true');
|
|
|
|
expect($tr.attr('data-tags').split('|')).toEqual(['tag1', 'tag2', 'tag3', OC.TAG_FAVORITE]);
|
|
|
|
expect(fileList.files[0].tags).toEqual(['tag1', 'tag2', 'tag3', OC.TAG_FAVORITE]);
|
|
|
|
expect($favoriteMark.find('.icon').hasClass('icon-star')).toEqual(false);
|
|
|
|
expect($favoriteMark.find('.icon').hasClass('icon-starred')).toEqual(true);
|
2017-09-27 09:07:20 +03:00
|
|
|
|
2020-11-10 11:50:46 +03:00
|
|
|
// show again the menu and get the new action, as the menu was
|
|
|
|
// closed and removed (and with it, the previous action) when that
|
|
|
|
// action was clicked
|
|
|
|
$showMenuAction.click();
|
|
|
|
$favoriteActionInMenu = $tr.find('.fileActionsMenu .action-favorite');
|
|
|
|
$favoriteActionInMenu.click();
|
2015-01-12 19:54:35 +03:00
|
|
|
|
2020-11-10 11:50:46 +03:00
|
|
|
setTimeout(function() {
|
|
|
|
expect(fakeServer.requests.length).toEqual(2);
|
|
|
|
request = fakeServer.requests[1];
|
|
|
|
expect(JSON.parse(request.requestBody)).toEqual({
|
|
|
|
tags: ['tag1', 'tag2', 'tag3']
|
|
|
|
});
|
|
|
|
|
|
|
|
request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({
|
|
|
|
tags: ['tag1', 'tag2', 'tag3']
|
|
|
|
}));
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
// re-read the element as it was re-inserted
|
|
|
|
$tr = fileList.findFileEl('One.txt');
|
|
|
|
$favoriteMark = $tr.find('.favorite-mark');
|
|
|
|
|
|
|
|
expect($tr.attr('data-favorite')).toBeFalsy();
|
|
|
|
expect($tr.attr('data-tags').split('|')).toEqual(['tag1', 'tag2', 'tag3']);
|
|
|
|
expect(fileList.files[0].tags).toEqual(['tag1', 'tag2', 'tag3']);
|
|
|
|
expect($favoriteMark.find('.icon').hasClass('icon-star')).toEqual(true);
|
|
|
|
expect($favoriteMark.find('.icon').hasClass('icon-starred')).toEqual(false);
|
2015-09-01 20:29:55 +03:00
|
|
|
|
2020-11-10 11:50:46 +03:00
|
|
|
done();
|
|
|
|
}, 1);
|
|
|
|
}, 1);
|
|
|
|
}, 1);
|
2014-11-18 20:53:45 +03:00
|
|
|
});
|
|
|
|
});
|
2015-09-02 20:02:06 +03:00
|
|
|
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([]);
|
|
|
|
});
|
|
|
|
});
|
2014-11-18 20:53:45 +03:00
|
|
|
});
|