<commit_before>'use strict';

var util = require('util');
var common = require('../modules/common-functions');
var constants = require('../modules/constants');

var OUTGOINGS_QUESTIONS = constants.OUTGOINGS_QUESTIONS;
var OUTGOINGS_QUESTION_ERRORS = {
  'rent': 'Enter 0 if you don’t pay rent',
  'maintenance': 'Enter 0 if this doesn’t apply to you',
  'childcare': 'Please provide an amount'
};

module.exports = {
  'Start page': function(client) {
    client.startService();
  },

  'Scope diagnosis': function(client) {
    client.scopeDiagnosis(constants.SCOPE_PATHS.debtInScope);
  },

  'Interstitial page': function(client) {
    client.interstitialPage();
  },

  'About you': function(client) {
    client.aboutSetAllToNo(true);
  },

  'Income': function(client) {
    client
      .waitForElementVisible('input[name="your_income-other_income-per_interval_value"]', 5000)
      .assert.urlContains('/income')
      .assert.containsText('h1', 'Your money coming in')
      .setValue('input[name="your_income-maintenance-per_interval_value"]', 0)
      .setValue('input[name="your_income-pension-per_interval_value"]', 0)
      .setValue('input[name="your_income-other_income-per_interval_value"]', 0)
      .submitForm('form')
    ;
  },

  'Outgoings': function(client) {
    client
      .waitForElementVisible('input[name="income_contribution"]', 5000)
      .assert.urlContains('/outgoings')
      .assert.containsText('h1', 'Your outgoings')
    ;
  },

  'Childcare fields': function(client) {
    client
      .back()
      .waitForElementPresent('input[name="your_income-other_income-per_interval_value"]', 5000)
      .back()
      .waitForElementPresent('input[name="have_partner"]', 5000)
      .setYesNoFields('have_children', 1)
      .setValue('input[name="num_children"]', 1)
      .submitForm('form')
      .waitForElementVisible('input[name="your_income-other_income-per_interval_value"]', 5000)
      .clearValue('input[name="your_income-maintenance-per_interval_value"]')
      .clearValue('input[name="your_income-pension-per_interval_value"]')
      .clearValue('input[name="your_income-other_income-per_interval_value"]')
      .setValue('input[name="your_income-child_tax_credit-per_interval_value"]', 0)
      .setValue('input[name="your_income-maintenance-per_interval_value"]', 0)
      .setValue('input[name="your_income-pension-per_interval_value"]', 0)
      .setValue('input[name="your_income-other_income-per_interval_value"]', 0)
      .submitForm('form')
      .waitForElementVisible('input[name="income_contribution"]', 5000)
      .assert.visible('input[name="childcare-per_interval_value"]')
      .assert.visible('select[name="childcare-interval_period"]')
    ;
  },

  'Context-dependent text for partner': function(client) {
    client
      .assert.containsText('body', 'Money you pay your landlord')
      .assert.containsText('body', 'Money you pay to an ex-partner for their living costs')
      .assert.containsText('body', 'Money you pay per month towards your criminal legal aid')
      .assert.containsText('body', 'Money you pay for your child to be looked after while you work or study')
      .back()
      .waitForElementVisible('input[name="your_income-other_income-per_interval_value"]', 5000)
      .back()
      .waitForElementPresent('input[name="have_partner"]', 5000)
      .setYesNoFields('have_partner', 1)
      .pause(200)
      .setYesNoFields(['in_dispute', 'partner_is_employed', 'partner_is_self_employed'], 0)
      .submitForm('form')

      .fillInIncome(true, true, true)

      .assert.urlContains('/outgoings')
      .waitForElementPresent('input[name="income_contribution"]', 5000)
      .assert.containsText('h1', 'You and your partner’s outgoings')
      .assert.containsText('body', 'Money you and your partner pay your landlord')
      .assert.containsText('body', 'Money you and/or your partner pay to an ex-partner for their living costs')
      .assert.containsText('body', 'Money you and/or your partner pay per month towards your criminal legal aid')
      .assert.containsText('body', 'Money you and your partner pay for your child to be looked after while you work or study')
    ;
  },

  'Validation': function(client) {
    OUTGOINGS_QUESTIONS.forEach(function(item) {
      client.setValue(util.format('input[name=%s-per_interval_value]', item), '500');
      common.submitAndCheckForFieldError(client, [{
        name: item + '-per_interval_value',
        errorText: 'Please select a time period from the drop down'
      }]);
      client.clearValue(util.format('input[name=%s-per_interval_value]', item));
      common.setDropdownValue(client, item + '-interval_period', 'per_month');
      common.submitAndCheckForFieldError(client, [{
        name: item + '-per_interval_value',
        errorText: OUTGOINGS_QUESTION_ERRORS[item]
      }]);
    });

    common.submitAndCheckForFieldError(client, [{
      name: 'income_contribution',
      errorText: 'Enter 0 if this doesn’t apply to you'
    }]);

    OUTGOINGS_QUESTIONS.forEach(function(item) {
      client.setValue(util.format('input[name=%s-per_interval_value]', item), '500');
    });
    client
      .setValue('input[name="income_contribution"]', 0)
      .submitForm('form')
      .waitForElementVisible('.answers-summary', 5000)
      .submitForm('form')
      .waitForElementPresent('input[name="callback-contact_number"]', 5000)
      .assert.urlContains('/result/eligible')
    ;

    client.end();
  }

};
<commit_msg>TESTS: possibly more reliable outgoings-page spec<commit_after>'use strict';

var util = require('util');
var common = require('../modules/common-functions');
var constants = require('../modules/constants');

var OUTGOINGS_QUESTIONS = constants.OUTGOINGS_QUESTIONS;
var OUTGOINGS_QUESTION_ERRORS = {
  'rent': 'Enter 0 if you don’t pay rent',
  'maintenance': 'Enter 0 if this doesn’t apply to you',
  'childcare': 'Please provide an amount'
};

module.exports = {
  'Start page': function(client) {
    client.startService();
  },

  'Scope diagnosis': function(client) {
    client.scopeDiagnosis(constants.SCOPE_PATHS.debtInScope);
  },

  'Interstitial page': function(client) {
    client.interstitialPage();
  },

  'About you': function(client) {
    client.aboutSetAllToNo(true);
  },

  'Income': function(client) {
    client
      .waitForElementVisible('input[name="your_income-other_income-per_interval_value"]', 5000)
      .assert.urlContains('/income')
      .assert.containsText('h1', 'Your money coming in')
      .setValue('input[name="your_income-maintenance-per_interval_value"]', 0)
      .setValue('input[name="your_income-pension-per_interval_value"]', 0)
      .setValue('input[name="your_income-other_income-per_interval_value"]', 0)
      .submitForm('form')
    ;
  },

  'Outgoings': function(client) {
    client
      .waitForElementVisible('input[name="income_contribution"]', 5000)
      .assert.urlContains('/outgoings')
      .assert.containsText('h1', 'Your outgoings')
    ;
  },

  'Childcare fields': function(client) {
    client
      .back()
      .waitForElementPresent('input[name="your_income-other_income-per_interval_value"]', 5000)
      .back()
      .waitForElementPresent('input[name="have_partner"]', 5000)
      .setYesNoFields('have_children', 1)
      .setValue('input[name="num_children"]', 1)
      .submitForm('form')
      .waitForElementVisible('input[name="your_income-other_income-per_interval_value"]', 5000)
      .clearValue('input[name="your_income-maintenance-per_interval_value"]')
      .clearValue('input[name="your_income-pension-per_interval_value"]')
      .clearValue('input[name="your_income-other_income-per_interval_value"]')
      .setValue('input[name="your_income-child_tax_credit-per_interval_value"]', 0)
      .setValue('input[name="your_income-maintenance-per_interval_value"]', 0)
      .setValue('input[name="your_income-pension-per_interval_value"]', 0)
      .setValue('input[name="your_income-other_income-per_interval_value"]', 0)
      .submitForm('form')
      .waitForElementVisible('input[name="income_contribution"]', 5000)
      .assert.visible('input[name="childcare-per_interval_value"]')
      .assert.visible('select[name="childcare-interval_period"]')
    ;
  },

  'Context-dependent text for partner': function(client) {
    client
      .assert.containsText('body', 'Money you pay your landlord')
      .assert.containsText('body', 'Money you pay to an ex-partner for their living costs')
      .assert.containsText('body', 'Money you pay per month towards your criminal legal aid')
      .assert.containsText('body', 'Money you pay for your child to be looked after while you work or study')
      .back()
      .waitForElementVisible('input[name="your_income-other_income-per_interval_value"]', 5000)
      .back()
      .waitForElementPresent('input[name="have_partner"]', 5000)
      .setYesNoFields('have_partner', 1)
      .pause(200)
      .setYesNoFields(['in_dispute', 'partner_is_employed', 'partner_is_self_employed'], 0)
      .submitForm('form')

      .pause(200)
      .fillInIncome(true, true, true)

      .assert.urlContains('/outgoings')
      .waitForElementPresent('input[name="income_contribution"]', 5000)
      .assert.containsText('h1', 'You and your partner’s outgoings')
      .assert.containsText('body', 'Money you and your partner pay your landlord')
      .assert.containsText('body', 'Money you and/or your partner pay to an ex-partner for their living costs')
      .assert.containsText('body', 'Money you and/or your partner pay per month towards your criminal legal aid')
      .assert.containsText('body', 'Money you and your partner pay for your child to be looked after while you work or study')
    ;
  },

  'Validation': function(client) {
    OUTGOINGS_QUESTIONS.forEach(function(item) {
      client.setValue(util.format('input[name=%s-per_interval_value]', item), '500');
      common.submitAndCheckForFieldError(client, [{
        name: item + '-per_interval_value',
        errorText: 'Please select a time period from the drop down'
      }]);
      client.clearValue(util.format('input[name=%s-per_interval_value]', item));
      common.setDropdownValue(client, item + '-interval_period', 'per_month');
      common.submitAndCheckForFieldError(client, [{
        name: item + '-per_interval_value',
        errorText: OUTGOINGS_QUESTION_ERRORS[item]
      }]);
    });

    common.submitAndCheckForFieldError(client, [{
      name: 'income_contribution',
      errorText: 'Enter 0 if this doesn’t apply to you'
    }]);

    OUTGOINGS_QUESTIONS.forEach(function(item) {
      client.setValue(util.format('input[name=%s-per_interval_value]', item), '500');
    });
    client
      .setValue('input[name="income_contribution"]', 0)
      .submitForm('form')
      .waitForElementVisible('.answers-summary', 5000)
      .submitForm('form')
      .waitForElementPresent('input[name="callback-contact_number"]', 5000)
      .assert.urlContains('/result/eligible')
    ;

    client.end();
  }

};

{'fraction_non_alphanumeric': 0.1461580282711127, 'fraction_numerical': 0.013138818412468285, 'mean_word_length': 4.131101813110181, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '356013', 'n_tokens_mistral': 3629, 'n_tokens_neox': 3366, 'n_words': 618}