No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

79 líneas
2.8 KiB

  1. context('FileUploader', () => {
  2. before(() => {
  3. cy.login();
  4. cy.visit('/app');
  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.get_open_dialog().find('.file-upload-area').attachFile('example.json', {
  19. subjectType: 'drag-n-drop',
  20. });
  21. cy.get_open_dialog().find('.file-name').should('contain', 'example.json');
  22. cy.intercept('POST', '/api/method/upload_file').as('upload_file');
  23. cy.get_open_dialog().findByRole('button', {name: 'Upload'}).click();
  24. cy.wait('@upload_file').its('response.statusCode').should('eq', 200);
  25. cy.get('.modal:visible').should('not.exist');
  26. });
  27. it('should accept uploaded files', () => {
  28. open_upload_dialog();
  29. cy.get_open_dialog().findByRole('button', {name: 'Library'}).click();
  30. cy.findByPlaceholderText('Search by filename or extension').type('example.json');
  31. cy.get_open_dialog().findAllByText('example.json').first().click();
  32. cy.intercept('POST', '/api/method/upload_file').as('upload_file');
  33. cy.get_open_dialog().findByRole('button', {name: 'Upload'}).click();
  34. cy.wait('@upload_file').its('response.body.message')
  35. .should('have.property', 'file_name', 'example.json');
  36. cy.get('.modal:visible').should('not.exist');
  37. });
  38. it('should accept web links', () => {
  39. open_upload_dialog();
  40. cy.get_open_dialog().findByRole('button', {name: 'Link'}).click();
  41. cy.get_open_dialog()
  42. .findByPlaceholderText('Attach a web link')
  43. .type('https://github.com', { delay: 100, force: true });
  44. cy.intercept('POST', '/api/method/upload_file').as('upload_file');
  45. cy.get_open_dialog().findByRole('button', {name: 'Upload'}).click();
  46. cy.wait('@upload_file').its('response.body.message')
  47. .should('have.property', 'file_url', 'https://github.com');
  48. cy.get('.modal:visible').should('not.exist');
  49. });
  50. it('should allow cropping and optimization for valid images', () => {
  51. open_upload_dialog();
  52. cy.get_open_dialog().find('.file-upload-area').attachFile('sample_image.jpg', {
  53. subjectType: 'drag-n-drop',
  54. });
  55. cy.get_open_dialog().findAllByText('sample_image.jpg').should('exist');
  56. cy.get_open_dialog().find('.btn-crop').first().click();
  57. cy.get_open_dialog().findByRole('button', {name: 'Crop'}).click();
  58. cy.get_open_dialog().findAllByRole('checkbox', {name: 'Optimize'}).should('exist');
  59. cy.get_open_dialog().findAllByLabelText('Optimize').first().click();
  60. cy.intercept('POST', '/api/method/upload_file').as('upload_file');
  61. cy.get_open_dialog().findByRole('button', {name: 'Upload'}).click();
  62. cy.wait('@upload_file').its('response.statusCode').should('eq', 200);
  63. cy.get('.modal:visible').should('not.exist');
  64. });
  65. });