You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

62 lines
2.0 KiB

  1. context('FileUploader', () => {
  2. before(() => {
  3. cy.login();
  4. cy.visit('/desk');
  5. });
  6. function open_upload_dialog() {
  7. cy.window().its('frappe').then(frappe => {
  8. new frappe.ui.FileUploader();
  9. });
  10. }
  11. it('upload dialog api works', () => {
  12. open_upload_dialog();
  13. cy.get_open_dialog().should('contain', 'Drag and drop files');
  14. cy.hide_dialog();
  15. });
  16. it('should accept dropped files', () => {
  17. open_upload_dialog();
  18. cy.fixture('example.json').then(fileContent => {
  19. cy.get_open_dialog().find('.file-upload-area').upload(
  20. { fileContent, fileName: 'example.json', mimeType: 'application/json' },
  21. { subjectType: 'drag-n-drop' },
  22. );
  23. cy.get_open_dialog().find('.file-info').should('contain', 'example.json');
  24. cy.server();
  25. cy.route('POST', '/api/method/upload_file').as('upload_file');
  26. cy.get_open_dialog().find('.btn-primary').click();
  27. cy.wait('@upload_file').its('status').should('be', 200);
  28. cy.get('.modal:visible').should('not.exist');
  29. });
  30. });
  31. it('should accept uploaded files', () => {
  32. open_upload_dialog();
  33. cy.get_open_dialog().find('a:contains("uploaded file")').click();
  34. cy.get_open_dialog().find('.tree-label:contains("example.json")').first().click();
  35. cy.server();
  36. cy.route('POST', '/api/method/upload_file').as('upload_file');
  37. cy.get_open_dialog().find('.btn-primary').click();
  38. cy.wait('@upload_file').its('response.body.message')
  39. .should('have.property', 'file_url', '/private/files/example.json');
  40. cy.get('.modal:visible').should('not.exist');
  41. });
  42. it('should accept web links', () => {
  43. open_upload_dialog();
  44. cy.get_open_dialog().find('a:contains("web link")').click();
  45. cy.get_open_dialog().find('.file-web-link input').type('https://github.com');
  46. cy.server();
  47. cy.route('POST', '/api/method/upload_file').as('upload_file');
  48. cy.get_open_dialog().find('.btn-primary').click();
  49. cy.wait('@upload_file').its('response.body.message')
  50. .should('have.property', 'file_url', 'https://github.com');
  51. cy.get('.modal:visible').should('not.exist');
  52. });
  53. });