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.
 
 
 
 
 
 

66 lines
2.1 KiB

  1. context('FileUploader', () => {
  2. before(() => {
  3. cy.login();
  4. cy.visit('/app/website');
  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. cy.get('body').click();
  16. });
  17. it('should accept dropped files', () => {
  18. open_upload_dialog();
  19. cy.fixture('example.json').then(fileContent => {
  20. cy.get_open_dialog().find('.file-upload-area').attachFile({
  21. fileContent,
  22. fileName: 'example.json',
  23. mimeType: 'application/json'
  24. }, {
  25. subjectType: 'drag-n-drop',
  26. force: true
  27. });
  28. cy.get_open_dialog().find('.file-name').should('contain', 'example.json');
  29. cy.intercept('POST', '/api/method/upload_file').as('upload_file');
  30. cy.get_open_dialog().find('.btn-modal-primary').click();
  31. cy.wait('@upload_file').its('response.statusCode').should('eq', 200);
  32. cy.get('.modal:visible').should('not.exist');
  33. });
  34. });
  35. it('should accept uploaded files', () => {
  36. open_upload_dialog();
  37. cy.get_open_dialog().find('.btn-file-upload div:contains("Library")').click();
  38. cy.get('.file-filter').type('example.json');
  39. cy.get_open_dialog().find('.tree-label:contains("example.json")').first().click();
  40. cy.intercept('POST', '/api/method/upload_file').as('upload_file');
  41. cy.get_open_dialog().find('.btn-primary').click();
  42. cy.wait('@upload_file').its('response.body.message')
  43. .should('have.property', 'file_url', '/private/files/example.json');
  44. cy.get('.modal:visible').should('not.exist');
  45. });
  46. it('should accept web links', () => {
  47. open_upload_dialog();
  48. cy.get_open_dialog().find('.btn-file-upload div:contains("Link")').click();
  49. cy.get_open_dialog().find('.file-web-link input').type('https://github.com', { delay: 100, force: true });
  50. cy.intercept('POST', '/api/method/upload_file').as('upload_file');
  51. cy.get_open_dialog().find('.btn-primary').click();
  52. cy.wait('@upload_file').its('response.body.message')
  53. .should('have.property', 'file_url', 'https://github.com');
  54. cy.get('.modal:visible').should('not.exist');
  55. });
  56. });