text: // For authoring Nightwatch tests, see
  // http://nightwatchjs.org/guide#usage
  
  module.exports = {
    'Load mortgage page': function (browser) {
      // automatically uses dev Server port from /config.index.js
      // default: http://localhost:8080
      // see nightwatch.conf.js
      const devServer = browser.globals.devServerURL
  
      browser
        .url(devServer)
        .waitForElementVisible('#app', 5000)
        .assert.containsText('h1', 'Simulador de hipotecas')
    },
  
    'Test fixed mortgage': function (browser) {
      browser
        // fill form
        .clearValue('input#capital').setValue('input#capital', '90000')
        .clearValue('input#installments').setValue('input#installments', '30')
        .click('select#mortgageType')
        .click('select#mortgageType option[value="2"]')
        .waitForElementVisible('input#fixedRate', 1000)
        .clearValue('input#fixedRate').setValue('input#fixedRate', '2.5')
        // assertions
        .assert.containsText('#result-table div p b', '0.002083')
        .assert.containsText('#result-table div p:nth-child(3) b', '355.61')
        .assert.containsText('#result-table table td:nth-child(2)', '360')
        .assert.containsText('#result-table table td:nth-child(3)', '360')
        .assert.containsText('#result-table table td:nth-child(4)', '0')
        .assert.containsText('#result-table table tr:nth-child(2) td:nth-child(2)', '128019.17')
        .assert.containsText('#result-table table tr:nth-child(2) td:nth-child(3)', '128019.17')
        .assert.containsText('#result-table table tr:nth-child(2) td:nth-child(4)', '0.00')
        .assert.containsText('#result-table table tr:nth-child(3) td:nth-child(2)', '38019.17')
        .assert.containsText('#result-table table tr:nth-child(3) td:nth-child(3)', '38019.17')
        .assert.containsText('#result-table table tr:nth-child(3) td:nth-child(4)', '0.00')
        // first fee
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(1)', '0')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(3)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(4)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(5)', '355.61')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(6)', '187.50')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(7)', '168.11')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(8)', '89831.89')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(9)', '359')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(10)', '')
        // last fee of first year
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(1)', '11')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(3)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(4)', '12')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(5)', '355.61')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(6)', '183.61')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(7)', '172.00')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(8)', '87959.42')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(9)', '348')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(10)', '')
        // last fee
        .assert.containsText('#amortization-table table tr:nth-child(360) td:nth-child(1)', '359')
        .assert.containsText('#amortization-table table tr:nth-child(360) td:nth-child(3)', '30')
        .assert.containsText('#amortization-table table tr:nth-child(360) td:nth-child(4)', '360')
        .assert.containsText('#amortization-table table tr:nth-child(360) td:nth-child(5)', '355.61')
        .assert.containsText('#amortization-table table tr:nth-child(360) td:nth-child(6)', '0.74')
        .assert.containsText('#amortization-table table tr:nth-child(360) td:nth-child(7)', '354.87')
        .assert.containsText('#amortization-table table tr:nth-child(360) td:nth-child(8)', '0.00')
        .assert.containsText('#amortization-table table tr:nth-child(360) td:nth-child(9)', '0')
        .assert.containsText('#amortization-table table tr:nth-child(360) td:nth-child(10)', '')
    },
  
    'Test fixed mortgage with partial amortization': function (browser) {
      browser
        // fill form
        .clearValue('input#capital').setValue('input#capital', '100000')
        .clearValue('input#installments').setValue('input#installments', '25')
        .clearValue('input#fixedRate').setValue('input#fixedRate', '3')
        .clearValue('input#partialAmortizationFee').setValue('input#partialAmortizationFee', '10')
        .clearValue('input#partialAmortizationAmount').setValue('input#partialAmortizationAmount', '10000')
        .clearValue('input#partialAmortizationType').setValue('input#partialAmortizationType', '2')
        .click('button#partialAmortizationAdd')
        .clearValue('input#partialAmortizationFee').setValue('input#partialAmortizationFee', '16')
        .clearValue('input#partialAmortizationAmount').setValue('input#partialAmortizationAmount', '5000')
        .clearValue('input#partialAmortizationType').setValue('input#partialAmortizationType', '1')
        .click('button#partialAmortizationAdd')
        // assertions
        .assert.containsText('#result-table div p b', '0.002500')
        .assert.containsText('#result-table div p:nth-child(3) b', '474.21')
        .assert.containsText('#result-table table td:nth-child(2)', '300')
        .assert.containsText('#result-table table td:nth-child(3)', '259')
        .assert.containsText('#result-table table td:nth-child(4)', '41')
        .assert.containsText('#result-table table tr:nth-child(2) td:nth-child(2)', '142263.39')
        .assert.containsText('#result-table table tr:nth-child(2) td:nth-child(3)', '131024.80')
        .assert.containsText('#result-table table tr:nth-child(2) td:nth-child(4)', '11238.60')
        .assert.containsText('#result-table table tr:nth-child(3) td:nth-child(2)', '42263.39')
        .assert.containsText('#result-table table tr:nth-child(3) td:nth-child(3)', '31024.80')
        .assert.containsText('#result-table table tr:nth-child(3) td:nth-child(4)', '11238.60')
        // first fee
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(1)', '0')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(3)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(4)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(5)', '474.21')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(6)', '250.00')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(7)', '224.21')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(8)', '99775.79')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(9)', '299')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(10)', '')
        // partial amortization (reduce installments)
        .assert.containsText('#amortization-table table tr:nth-child(10) td:nth-child(1)', '9')
        .assert.containsText('#amortization-table table tr:nth-child(10) td:nth-child(3)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(10) td:nth-child(4)', '10')
        .assert.containsText('#amortization-table table tr:nth-child(10) td:nth-child(5)', '474.21')
        .assert.containsText('#amortization-table table tr:nth-child(10) td:nth-child(6)', '244.90')
        .assert.containsText('#amortization-table table tr:nth-child(10) td:nth-child(7)', '10229.31')
        .assert.containsText('#amortization-table table tr:nth-child(10) td:nth-child(8)', '87732.49')
        .assert.containsText('#amortization-table table tr:nth-child(10) td:nth-child(9)', '249')
        .assert.containsText('#amortization-table table tr:nth-child(10) td:nth-child(10)', '10000 - 2')
        .assert.containsText('#amortization-table table tr:nth-child(11) td:nth-child(1)', '51')
        .assert.containsText('#amortization-table table tr:nth-child(11) td:nth-child(3)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(11) td:nth-child(4)', '11')
        .assert.containsText('#amortization-table table tr:nth-child(11) td:nth-child(5)', '473.74')
        .assert.containsText('#amortization-table table tr:nth-child(11) td:nth-child(6)', '219.33')
        .assert.containsText('#amortization-table table tr:nth-child(11) td:nth-child(7)', '254.41')
        .assert.containsText('#amortization-table table tr:nth-child(11) td:nth-child(8)', '87478.09')
        .assert.containsText('#amortization-table table tr:nth-child(11) td:nth-child(9)', '248')
        .assert.containsText('#amortization-table table tr:nth-child(11) td:nth-child(10)', '')
        // partial amortization (reduce fee)
        .assert.containsText('#amortization-table table tr:nth-child(16) td:nth-child(1)', '56')
        .assert.containsText('#amortization-table table tr:nth-child(16) td:nth-child(3)', '2')
        .assert.containsText('#amortization-table table tr:nth-child(16) td:nth-child(4)', '16')
        .assert.containsText('#amortization-table table tr:nth-child(16) td:nth-child(5)', '473.74')
        .assert.containsText('#amortization-table table tr:nth-child(16) td:nth-child(6)', '216.14')
        .assert.containsText('#amortization-table table tr:nth-child(16) td:nth-child(7)', '5257.60')
        .assert.containsText('#amortization-table table tr:nth-child(16) td:nth-child(8)', '81196.49')
        .assert.containsText('#amortization-table table tr:nth-child(16) td:nth-child(9)', '243')
        .assert.containsText('#amortization-table table tr:nth-child(16) td:nth-child(10)', '5000 - 1')
        .assert.containsText('#amortization-table table tr:nth-child(17) td:nth-child(1)', '57')
        .assert.containsText('#amortization-table table tr:nth-child(17) td:nth-child(3)', '2')
        .assert.containsText('#amortization-table table tr:nth-child(17) td:nth-child(4)', '17')
        .assert.containsText('#amortization-table table tr:nth-child(17) td:nth-child(5)', '446.26')
        .assert.containsText('#amortization-table table tr:nth-child(17) td:nth-child(6)', '202.99')
        .assert.containsText('#amortization-table table tr:nth-child(17) td:nth-child(7)', '243.27')
        .assert.containsText('#amortization-table table tr:nth-child(17) td:nth-child(8)', '80953.23')
        .assert.containsText('#amortization-table table tr:nth-child(17) td:nth-child(9)', '242')
        .assert.containsText('#amortization-table table tr:nth-child(17) td:nth-child(10)', '')
        // last fee
        .assert.containsText('#amortization-table table tr:nth-child(259) td:nth-child(1)', '299')
        .assert.containsText('#amortization-table table tr:nth-child(259) td:nth-child(3)', '22')
        .assert.containsText('#amortization-table table tr:nth-child(259) td:nth-child(4)', '259')
        .assert.containsText('#amortization-table table tr:nth-child(259) td:nth-child(5)', '446.26')
        .assert.containsText('#amortization-table table tr:nth-child(259) td:nth-child(6)', '1.11')
        .assert.containsText('#amortization-table table tr:nth-child(259) td:nth-child(7)', '445.14')
        .assert.containsText('#amortization-table table tr:nth-child(259) td:nth-child(8)', '-0.00')
        .assert.containsText('#amortization-table table tr:nth-child(259) td:nth-child(9)', '0')
        .assert.containsText('#amortization-table table tr:nth-child(259) td:nth-child(10)', '')
    },
  
    'Test variable mortgage': function (browser) {
      browser
        // fill form
        .clearValue('input#capital').setValue('input#capital', '150000')
        .clearValue('input#installments').setValue('input#installments', '40')
        .click('select#mortgageType')
        .click('select#mortgageType option[value="1"]')
        .waitForElementVisible('input#differential', 1000)
        .clearValue('input#differential').setValue('input#differential', '0.99')
        .clearValue('input#euribor').setValue('input#euribor', '0.5')
        .click('#form table td a')
        .click('#form table td a')
        // assertions
        .assert.containsText('#result-table div p b', '0.001242')
        .assert.containsText('#result-table div p:nth-child(3) b', '415.01')
        .assert.containsText('#result-table table td:nth-child(2)', '480')
        .assert.containsText('#result-table table td:nth-child(3)', '480')
        .assert.containsText('#result-table table td:nth-child(4)', '0')
        .assert.containsText('#result-table table tr:nth-child(2) td:nth-child(2)', '199204.53')
        .assert.containsText('#result-table table tr:nth-child(2) td:nth-child(3)', '199204.53')
        .assert.containsText('#result-table table tr:nth-child(2) td:nth-child(4)', '0.00')
        .assert.containsText('#result-table table tr:nth-child(3) td:nth-child(2)', '49204.53')
        .assert.containsText('#result-table table tr:nth-child(3) td:nth-child(3)', '49204.53')
        .assert.containsText('#result-table table tr:nth-child(3) td:nth-child(4)', '0.00')
        // first fee
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(1)', '0')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(3)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(4)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(5)', '415.01')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(6)', '186.25')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(7)', '228.76')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(8)', '149771.24')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(9)', '479')
        .assert.containsText('#amortization-table table tr:nth-child(1) td:nth-child(10)', '')
        // last fee of first year
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(1)', '11')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(3)', '1')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(4)', '12')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(5)', '415.01')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(6)', '183.11')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(7)', '231.90')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(8)', '147236.06')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(9)', '468')
        .assert.containsText('#amortization-table table tr:nth-child(12) td:nth-child(10)', '')
        // last fee
        .assert.containsText('#amortization-table table tr:nth-child(480) td:nth-child(1)', '479')
        .assert.containsText('#amortization-table table tr:nth-child(480) td:nth-child(3)', '40')
        .assert.containsText('#amortization-table table tr:nth-child(480) td:nth-child(4)', '480')
        .assert.containsText('#amortization-table table tr:nth-child(480) td:nth-child(5)', '415.01')
        .assert.containsText('#amortization-table table tr:nth-child(480) td:nth-child(6)', '0.51')
        .assert.containsText('#amortization-table table tr:nth-child(480) td:nth-child(7)', '414.49')
        .assert.containsText('#amortization-table table tr:nth-child(480) td:nth-child(8)', '-0.00')
        .assert.containsText('#amortization-table table tr:nth-child(480) td:nth-child(9)', '0')
        .assert.containsText('#amortization-table table tr:nth-child(480) td:nth-child(10)', '')
  
        .end()
    },
  
    'Load & save mortgage data from/to local storage': function (browser) {
      browser
        .url(browser.globals.devServerURL)
        .waitForElementVisible('#app', 5000)
        .assert.value('input#capital', '0')
        .setValue('input#capital', '100000')
        .refresh()
        .waitForElementVisible('#app', 5000)
        .assert.value('input#capital', '100000')
        .end()
    }
  }
  