


const {ipcRenderer} = require('electron')

const dragFileLink = document.getElementById('drag-file-link')

dragFileLink.addEventListener('dragstart', (event) => {
  event.preventDefault()
  ipcRenderer.send('ondragstart', __filename)
})


describe('Asynchronous validation', function() {
  before(() => {
    cy.loadStory(['Validation', 'Asynchronous validation', 'Field async rule'])
  })

  it('Bypasses async validation for empty optional field with async rule', () => {
    cy.getField('fieldOne')
      .focus()
      .blur({ force: true })
      .valid(false)
      .invalid(false)
  })

  it('Rejects empty required field with unsatisfied async rule', () => {
    cy.getField('fieldTwo')
      .focus()
      .blur({ force: true })
      .expected(false)
  })

  it('Resolves field that satisfies async rule', () => {
    cy.getField('fieldOne')
      .typeIn('expected value')
      .blur({ force: true })
      .wait(500)
      .expected()
  })

  it('Rejects field that does not satisfy async rule', () => {
    cy.getField('fieldOne')
      .clear()
      .typeIn('foo')
      .blur({ force: true })
      .wait(500)
      .expected(false)
  })

  it('Cancels pending async validation on field change', () => {
    cy.getField('fieldFour')
      .typeIn('foo')
      .blur({ force: true })
      .wait(200)
      .clear()
      .typeIn('bar')
      .wait(300)
      .should('not.have.class', 'is-invalid')
      .blur({ force: true })
      .wait(500)
      .expected()
  })
})


# ==============================================================================
# Copyright (c) 2016-2020 Proton Technologies AG (Switzerland)
# Email: contact@protonvpn.com
#
# The MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to perm