1

I have to write the test cases for validating whether all the uploading media and document files are valid or not in the File Upload form on ReactJS.

Valid extenstions: Media: Audio(mp3, ogg), Video(mp4, ogg) & Image(png, jpg, jpeg, bmp) Document: PDF, TXT, DOC, DOCX, XLS, XLSX, CSV, PPT, PPTX, XML, JSON

Sample Source Code for extension checker:

//For Valid File Path:
const mediaMode = 'valid';
const filepath = 'fixtures/valid/sample.jpg';
const filename = 'sample.jpg';

//For In-Valid File Path:
/*const mediaMode = 'invalid';
const filepath = 'fixtures/invalid/sample.ico';
const filename = 'sample.ico';
*/

const field = 'input[type="file"]';
const mimetypes = ['image/png', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/svg+xml', 'video/mp4', 'audio/mp4', 'application/xml', 'application/pdf', 'text/plain'];

cy.get(field).attachFile({filePath: filepath, fileName: filename, encoding: 'utf-8'} );

cy.get(field).then((input) => {
    if (mediaMode == 'valid') {
        expect(input[0].files[0].type).to.be.oneOf(mimetypes);
    } else {
        expect(input[0].files[0].type).not.be.oneOf(mimetypes);
    }
});

Objective: To restrict the media file rename with a valid extension. Ex: sample.flv/ico/wmv changed into sample.mp4/jpg/mp3/docx

I used "image-size" npm plugin for validating image as valid.

I want to implement the same for Audios, Videos, and Documents extensions.

Anyone can share the npm plugins for validating the files with the mentioned Audios, Videos, and Documents extensions. I preferred the single plugin that is good for Audio & Video and the same for documents also. If it has individual plugins is also good.

Note: NPM Plugin should be commercial usage.

How to implement the plugins in Cypress? Ex: https://www.npmjs.com/package/music-metadata

Thanks!

0 Answers0