upload image to cypress fx2la code example

Example 1: upload photos cypress

it('Uploads a CSV', () => {
    cy.document().trigger('dragenter')
    // you don't need to use cy.document() that is where my event listener is. 
   //you could use cy.get('element').trigger('dragenter')
    cy.dropFile('test.csv')
})

Example 2: upload photos cypress

Cypress.Commands.add(
    'dropFile', {
        prevSubject: false
    }, (fileName) => {
        Cypress.log({
            name: 'dropFile',
        })
        return cy
            .fixture(fileName, 'base64')
            .then(Cypress.Blob.base64StringToBlob)
            .then(blob => {
                // instantiate File from `application` window, not cypress window
                return cy.window().then(win => {
                    const file = new win.File([blob], fileName)
                    const dataTransfer = new win.DataTransfer()
                    dataTransfer.items.add(file)

                    return cy.document().trigger('drop', {
                        dataTransfer,
                    })
                })
            })
    }
)