2014-01-12 21:57:53 +04:00
/ * *
* ownCloud
*
* @ author Vincent Petry
* @ copyright 2014 Vincent Petry < pvince81 @ owncloud . com >
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation ; either
* version 3 of the License , or any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details .
*
* You should have received a copy of the GNU Affero General Public
* License along with this library . If not , see < http : //www.gnu.org/licenses/>.
*
* /
2014-01-30 13:41:04 +04:00
/* global OC, FileList */
2014-01-12 21:57:53 +04:00
describe ( 'FileList tests' , function ( ) {
beforeEach ( function ( ) {
// init horrible parameters
2014-01-24 16:19:44 +04:00
var $body = $ ( 'body' ) ;
$body . append ( '<input type="hidden" id="dir" value="/subdir"></input>' ) ;
$body . append ( '<input type="hidden" id="permissions" value="31"></input>' ) ;
// dummy files table
$body . append ( '<table id="filestable"></table>' ) ;
2014-01-12 21:57:53 +04:00
} ) ;
afterEach ( function ( ) {
2014-01-24 16:19:44 +04:00
$ ( '#dir, #permissions, #filestable' ) . remove ( ) ;
2014-01-12 21:57:53 +04:00
} ) ;
it ( 'generates file element with correct attributes when calling addFile' , function ( ) {
var lastMod = new Date ( 10000 ) ;
2014-01-24 16:32:31 +04:00
// note: download_url is actually the link target, not the actual download URL...
2014-01-12 21:57:53 +04:00
var $tr = FileList . addFile ( 'testName.txt' , 1234 , lastMod , false , false , { download _url : 'test/download/url' } ) ;
expect ( $tr ) . toBeDefined ( ) ;
expect ( $tr [ 0 ] . tagName . toLowerCase ( ) ) . toEqual ( 'tr' ) ;
2014-01-24 16:32:31 +04:00
expect ( $tr . find ( 'a:first' ) . attr ( 'href' ) ) . toEqual ( 'test/download/url' ) ;
2014-01-12 21:57:53 +04:00
expect ( $tr . attr ( 'data-type' ) ) . toEqual ( 'file' ) ;
expect ( $tr . attr ( 'data-file' ) ) . toEqual ( 'testName.txt' ) ;
expect ( $tr . attr ( 'data-size' ) ) . toEqual ( '1234' ) ;
2014-01-24 16:19:44 +04:00
expect ( $tr . attr ( 'data-permissions' ) ) . toEqual ( '31' ) ;
2014-01-12 21:57:53 +04:00
//expect($tr.attr('data-mime')).toEqual('plain/text');
} ) ;
it ( 'generates dir element with correct attributes when calling addDir' , function ( ) {
var lastMod = new Date ( 10000 ) ;
var $tr = FileList . addDir ( 'testFolder' , 1234 , lastMod , false ) ;
expect ( $tr ) . toBeDefined ( ) ;
expect ( $tr [ 0 ] . tagName . toLowerCase ( ) ) . toEqual ( 'tr' ) ;
expect ( $tr . attr ( 'data-type' ) ) . toEqual ( 'dir' ) ;
expect ( $tr . attr ( 'data-file' ) ) . toEqual ( 'testFolder' ) ;
expect ( $tr . attr ( 'data-size' ) ) . toEqual ( '1234' ) ;
2014-01-24 16:19:44 +04:00
expect ( $tr . attr ( 'data-permissions' ) ) . toEqual ( '31' ) ;
2014-01-12 21:57:53 +04:00
//expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
} ) ;
2014-02-13 23:20:00 +04:00
describe ( 'Download Url' , function ( ) {
it ( 'returns correct download URL for single files' , function ( ) {
expect ( FileList . getDownloadUrl ( 'some file.txt' ) ) . toEqual ( OC . webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=some%20file.txt' ) ;
expect ( FileList . getDownloadUrl ( 'some file.txt' , '/anotherpath/abc' ) ) . toEqual ( OC . webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fanotherpath%2Fabc&files=some%20file.txt' ) ;
$ ( '#dir' ) . val ( '/' ) ;
expect ( FileList . getDownloadUrl ( 'some file.txt' ) ) . toEqual ( OC . webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=some%20file.txt' ) ;
} ) ;
it ( 'returns correct download URL for multiple files' , function ( ) {
expect ( FileList . getDownloadUrl ( [ 'a b c.txt' , 'd e f.txt' ] ) ) . toEqual ( OC . webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=%5B%22a%20b%20c.txt%22%2C%22d%20e%20f.txt%22%5D' ) ;
} ) ;
2014-01-24 16:32:31 +04:00
} ) ;
2014-01-12 21:57:53 +04:00
} ) ;