985c20b03c47dc42fccfb4be8e9f79c410d13814
[friendica-addons.git/.git] / js_upload / file-uploader / tests / test-acceptance.htm
1 <!DOCTYPE HTML>
2 <html>
3 <head>  
4     <script src="jquery-1.4.2.min.js" type="text/javascript"></script>
5     
6     <!-- test iwth jquery ui dialog -->
7     <link href="jquery-ui/ui-lightness/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css" media="screen" />
8     <script src="jquery-ui/jquery-ui-1.8.4.custom.min.js" type="text/javascript"></script>
9
10     <link href="qunit/qunit/qunit.css" rel="stylesheet" type="text/css" media="screen" />
11     <script src="qunit/qunit/qunit.js" type="text/javascript"></script>
12     
13     <link href="../client/fileuploader.css" rel="stylesheet" type="text/css"> 
14     <script src="../client/fileuploader.js" type="text/javascript" ></script>
15     <script>
16
17 jQuery(function(){    
18     $("#dialog").dialog();
19         
20     asyncTest("qq.FileUploader", function() {
21         expect(10);
22         
23         var submitFileName, submitId;
24                
25         var uploader = new qq.FileUploader({
26             element: document.getElementById('file-uploader'),
27             action: 'action-acceptance.php',
28             params: {
29                 one: 'value1',
30                 two: 'value2'
31             },
32             allowedExtensions: ['txt', 'val', 'webm'], 
33             sizeLimit: 9 * 1024, 
34             minSizeLimit: 10,
35             onSubmit: function(id, fileName){
36                 if (fileName == '5text.txt'){
37                     submitId = id;
38                     submitFileName = fileName; 
39                 } else if (fileName == '6text.txt'){
40                     uploader.setParams({'new':'newvalue'});  
41                     
42                     same(uploader.getInProgress(), 0, 'getFilesInProgress');                    
43                     
44                     setTimeout(function(){
45                         same(uploader.getInProgress(), 1, 'getFilesInProgress');
46                     }, 1);                                                                                                                   
47                 } else if (fileName == '8text.txt'){
48                     
49                     setTimeout(function(){
50                         same(uploader.getInProgress(), 0, 'all uploads should have finished');
51                         start(); // check test results    
52                     }, 1000);
53                     
54                     return false;
55                 }
56             },
57             onComplete: function(id, fileName, responseJSON){
58
59                 if (fileName == '4text.txt'){
60                     same(responseJSON, {}, 'should be empty if server returned malformed json');
61                 } else if (fileName == '5text.txt'){
62                     same(submitId, id, "id in both callbacks match");
63                     same(submitFileName, fileName, "filename in both callbacks match");    
64                     ok(responseJSON.one === 'value1' && responseJSON.two === 'value2', "server received default params");
65                     same(responseJSON.fileName, fileName, "filename in onComplete correct");
66                 } else if (fileName == '6text.txt'){                    
67                     ok(responseJSON['new'] === 'newvalue' && responseJSON.one == null, "server received new params");                    
68                     same(uploader.getInProgress(), 0, 'upload should have finished');                                                            
69                 } else if (fileName == '8text.txt'){
70                     ok(false, "upload should be cancelled by returning false in onSubmit");                    
71                 }                                                                                
72             }
73         });           
74     });
75 });
76     </script>  
77 </head>
78 <body> 
79     <h1 id="qunit-header">File uploader tests</h1> 
80     <h2 id="qunit-banner"></h2> 
81     <h2 id="qunit-userAgent"></h2> 
82     <ol id="qunit-tests"></ol>
83
84     <p>select files in sample-files dir, following order</p>
85     <ol>
86         <li>select 1imagelong...long.gif, invalid ext error should appear</li>        
87         <li>select 2larger.txt, invalid size message should appear (in FF3.6+,Safari4+,Chrome without doing request)</li>
88         <li>select 3empty.txt, invalid size message should appear (in FF3.6+,Safari4+,Chrome without doing request)</li>
89         <li>select 4text.txt, uploaded file should be marked as failed (server returns jsgkdfgu4eyij)</li>             
90         <li>select 5text.txt, callback argument tests</li>        
91         <li>select 6text.txt, setParams, isUploading</li>
92         <li>select 7small.txt, too small size message should appear (in FF3.6+,Safari4+,Chrome without doing request)</li>
93         <li>select 8text.txt, returning false in onSubmit cancells upload, file should not be added to list</li>        
94         <li>
95             In FF,Chrome, select all files using drag-and-drop, only 1 error should appear.            
96         </li>
97     </ol>
98     
99     <div id="dialog" title="Basic dialog">
100         File uploader inside a dialog
101         <div id="file-uploader"></div>        
102     </div>               
103 </body> 
104 </html>
105
106