<commit_before><!doctype html>

<html>
<head>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
  <title>test DSA CALCULATION</title>

  <script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <script src="../../bower_components/web-component-tester/browser.js"></script>

  <link rel="import" href="../../t2f/app-elements/api-elements/outbound-data.html">
  <link rel="import" href="../../t2f/app-elements/fieldset-elements/travel-deductions.html">

  <link rel="import" href="./data/case-1.html">
</head>
<body>

<test-fixture id="el">
  <template>
    <et2f-outbound-data postData="true" id="api"></et2f-outbound-data>
    <travel-deductions id="deductions"></travel-deductions>
  </template>
</test-fixture>

<script>

  /* global define, suite, setup, fixture, test, caseScenarios, expect */
  suite('dsa-test', function() {

    var el = null;
    var dom = null;
    var deductions = null;
    var deductionsItems = null;
    var api = null;
    var data = caseScenarios;
    var deDom = null;

    setup(function() {

      el = fixture('el');
      dom = Polymer.dom(el.root);

      deductions = dom.querySelector('#deductions');
      deductionsItems = function() {
        return deductions.$.deductions_list.items;
      };

      api = dom.querySelector('#api');
      dom.flush();
    });

    function fillData(JSONset, newOne, resetDeductions) {

      deductions.itinerary = data[JSONset].itinerary;
      if (resetDeductions) {
        deductions.deductions = [];
        data[JSONset].deductions = deductions.deductions;
      }

      if (newOne) api.travelId = -1;

      api.data = JSON.parse(JSON.stringify(data[JSONset]));
    }

    test('Andras\'s EXAMPLE CASE 1. (validated by Kidus)', function(done) {

      fillData('CASE1', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('80.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('20.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 1.5 (one destination, less than 8 hours stay on one day)', function(done) {

      fillData('CASE1', true, false);

      api.data.itinerary[0].departure_date = new Date('2017-01-01T02:00:00.499Z');
      api.data.itinerary[0].arrival_date = new Date('2017-01-01T05:00:00.511Z');

      api.data.itinerary[1].departure_date = new Date('2017-01-01T09:00:00.499Z');
      api.data.itinerary[1].arrival_date = new Date('2017-01-01T10:00:00.511Z');

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('80.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('20.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 2. (validated by Kidus)', function(done) {

      fillData('CASE2', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('1160.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('460.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 3. (validated by Kidus)', function(done) {

      fillData('CASE3', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('520.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('25.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 4. (validated by Kidus)', function(done) {

      fillData('CASE4', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('12708.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('93.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 5. (validated by Kidus)', function(done) {

      fillData('CASE5', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('480.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('10.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Example case for last day totally deducted, (CASE4 modified)', function(done) {

      fillData('CASE4', true, false);
      api.data.deductions[65].no_dsa = true;

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('12708.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('141.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

  });
</script>

</body>
</html>
<commit_msg>frontend DSA tests aligned to flowchart and business needs<commit_after><!doctype html>

<html>
<head>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
  <title>test DSA CALCULATION</title>

  <script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <script src="../../bower_components/web-component-tester/browser.js"></script>

  <link rel="import" href="../../t2f/app-elements/api-elements/outbound-data.html">
  <link rel="import" href="../../t2f/app-elements/fieldset-elements/travel-deductions.html">

  <link rel="import" href="./data/case-1.html">
</head>
<body>

<test-fixture id="el">
  <template>
    <et2f-outbound-data postData="true" id="api"></et2f-outbound-data>
    <travel-deductions id="deductions"></travel-deductions>
  </template>
</test-fixture>

<script>

  /* global define, suite, setup, fixture, test, caseScenarios, expect */
  suite('dsa-test', function() {

    var el = null;
    var dom = null;
    var deductions = null;
    var deductionsItems = null;
    var api = null;
    var data = caseScenarios;
    var deDom = null;

    setup(function() {

      el = fixture('el');
      dom = Polymer.dom(el.root);

      deductions = dom.querySelector('#deductions');
      deductionsItems = function() {
        return deductions.$.deductions_list.items;
      };

      api = dom.querySelector('#api');
      dom.flush();
    });

    function fillData(JSONset, newOne, resetDeductions) {

      deductions.itinerary = data[JSONset].itinerary;
      if (resetDeductions) {
        deductions.deductions = [];
        data[JSONset].deductions = deductions.deductions;
      }

      if (newOne) api.travelId = -1;

      api.data = JSON.parse(JSON.stringify(data[JSONset]));
    }

    test('Andras\'s EXAMPLE CASE 1. (validated by Kidus)', function(done) {

      fillData('CASE1', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('80.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('20.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 1.5 (one destination, less than 8 hours stay on one day)', function(done) {

      fillData('CASE1', true, false);

      api.data.itinerary[0].departure_date = new Date('2017-01-01T02:00:00.499Z');
      api.data.itinerary[0].arrival_date = new Date('2017-01-01T05:00:00.511Z');

      api.data.itinerary[1].departure_date = new Date('2017-01-01T09:00:00.499Z');
      api.data.itinerary[1].arrival_date = new Date('2017-01-01T10:00:00.511Z');

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('0.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('0.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 2. (validated by Kidus)', function(done) {

      fillData('CASE2', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('1160.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('460.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 3. (validated by Kidus)', function(done) {

      fillData('CASE3', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('480.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('20.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 4. (validated by Kidus)', function(done) {

      fillData('CASE4', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('12708.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('93.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Andras\'s EXAMPLE CASE 5. (validated by Kidus)', function(done) {

      fillData('CASE5', true, false);

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('480.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('10.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

    test('Example case for last day totally deducted, (CASE4 modified)', function(done) {

      fillData('CASE4', true, false);
      api.data.deductions[65].no_dsa = true;

      api._handlePostSuccess = function(e, data) {

        // console.log('cost summary', data.cost_summary);

        var baseDSAokay = expect(data.cost_summary.dsa_total).to.equal('12708.00');
        var deductionsOkay = expect(data.cost_summary.deductions_total).to.equal('141.00');
        if (baseDSAokay && deductionsOkay) console.log('✅');
        done();
      }

      api.doRequest({endPoint: 'save'});
    });

  });
</script>

</body>
</html>

{'fraction_non_alphanumeric': 0.16651387615634636, 'fraction_numerical': 0.027835652971080923, 'mean_word_length': 3.0997608472839087, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, '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': '5909503', 'n_tokens_mistral': 4318, 'n_tokens_neox': 3947, 'n_words': 682}