test: Add UI test for FileUploader

This commit is contained in:
Faris Ansari 2019-04-13 15:29:32 +05:30
parent 04be929a90
commit a5c6dbf3ed
4 changed files with 74 additions and 1 deletions

View file

@ -0,0 +1,58 @@
context('FileUploader', () => {
before(() => {
cy.login('Administrator', 'qwe');
cy.visit('/desk');
});
function open_upload_dialog() {
cy.window().its('frappe').then(frappe => {
new frappe.ui.FileUploader()
});
}
it('upload dialog api works', () => {
open_upload_dialog();
cy.get_open_dialog().should('contain', 'Drag and drop files');
cy.hide_dialog();
});
it('should accept dropped files', () => {
open_upload_dialog();
cy.fixture('example.json').then(fileContent => {
cy.get_open_dialog().find('.file-upload-area').upload(
{ fileContent, fileName: 'example.json', mimeType: 'application/json' },
{ subjectType: 'drag-n-drop' },
);
cy.get_open_dialog().find('.file-info').should('contain', 'example.json');
cy.server();
cy.route('POST', '/api/method/upload_file').as('upload_file');
cy.get_open_dialog().find('.btn-primary').click();
cy.wait('@upload_file').its('status').should('be', 200);
});
});
it('should accept uploaded files', () => {
open_upload_dialog();
cy.get_open_dialog().find('a:contains("uploaded file")').click();
cy.get_open_dialog().find('.tree-label:contains("example.json")').first().click();
cy.server();
cy.route('POST', '/api/method/upload_file').as('upload_file');
cy.get_open_dialog().find('.btn-primary').click();
cy.wait('@upload_file').its('response.body.message')
.should('have.property', 'file_url', '/private/files/example.json');
});
it('should accept web links', () => {
open_upload_dialog();
cy.get_open_dialog().find('a:contains("web link")').click();
cy.get_open_dialog().find('.file-web-link input').type('https://github.com');
cy.server();
cy.route('POST', '/api/method/upload_file').as('upload_file');
cy.get_open_dialog().find('.btn-primary').click();
cy.wait('@upload_file').its('response.body.message')
.should('have.property', 'file_url', 'https://github.com');
});
});

View file

@ -1,3 +1,4 @@
import 'cypress-file-upload'
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
@ -75,3 +76,12 @@ Cypress.Commands.add('dialog', (title, fields) => {
return d;
});
});
Cypress.Commands.add('get_open_dialog', () => {
return cy.get('.modal:visible').last();
});
Cypress.Commands.add('hide_dialog', () => {
cy.get_open_dialog().find('.btn-modal-close').click();
cy.get('.modal:visible').should('not.exist');
});

View file

@ -44,6 +44,7 @@
"babel-runtime": "^6.26.0",
"chalk": "^2.3.2",
"cypress": "^3.1.1",
"cypress-file-upload": "^3.1.0",
"less": "^3.0.4",
"node-sass": "^4.11.0",
"rollup": "^1.2.2",

View file

@ -1124,6 +1124,11 @@ currently-unhandled@^0.4.1:
dependencies:
array-find-index "^1.0.1"
cypress-file-upload@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/cypress-file-upload/-/cypress-file-upload-3.1.0.tgz#9da7ed60619631231bd2caaf9844874e7cec6f69"
integrity sha512-zJh6Qwh+BZz6j3oCxMgRmfSsHJ+vSm2FrsZ1j/hG3s1O+6UPhOCDGeJucMUGBivWb1IsHrLKJP4LfgHSooPZHw==
cypress@^3.1.1:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-3.1.5.tgz#5227b2ce9306c47236d29e703bad9055d7218042"
@ -1715,7 +1720,6 @@ forwarded@~0.1.2:
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"
integrity sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=
fragment-cache@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19"