test-formhandler-datafilter.html 3.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<!DOCTYPE html>
<html>

<head>
  <title>formhandler tests</title>
  <link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="../node_modules/font-awesome/css/font-awesome.min.css">
  <style>
    .position-relative {
      position: relative;
    }

    .pos-cc {
      position: absolute;
      top: 45%;
      left: 45%;
    }

    .d-none {
      display: none !important;
    }
  </style>
  <script src="../node_modules/jquery/dist/jquery.min.js"></script>
  <script src="../node_modules/popper.js/dist/umd/popper.min.js"></script>
  <script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
  <script src="../node_modules/lodash/lodash.min.js"></script>
  <script src="../node_modules/moment/min/moment.min.js"></script>
  <script src="../node_modules/numeral/min/numeral.min.js"></script>
  <script src="../node_modules/d3/build/d3.js"></script>
  <script src="../node_modules/d3-scale-chromatic/dist/d3-scale-chromatic.js"></script>
  <script src="../dist/formhandler.min.js"></script>
  <script src="tape.js"></script>

</head>

<body>
  <script>
    tape.onFinish(function () { window.renderComplete = true })
  </script>
  <div class="external-api"></div>
  <div class="external-api2"></div>

  <script>
  $.ajax('/formhandler-data').done(function(response) {
    tape('$().formhandler() datafilter external api test', function(test) {
      $('.external-api')
      .on('load', function () {
48
        test.equal($('.external-api .count').text().trim(), '196 rows')
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        test.ok($('.external-api ul.pagination .page-item:nth-of-type(2)').has("disabled"))
        test.ok($('.external-api ul.pagination .page-item:nth-of-type(2)').hasClass("active"))

        test.equal($('.external-api ul.pagination .page-item:nth-of-type(3) a').attr('href'), '?_offset=' + 100 , 'fdsa')
        test.equal($('.external-api ul.pagination .page-item:nth-of-type(4) a').attr('href'), '?_offset=' + 100 , 'fdsa3')

        test.equal($('.external-api table tbody tr').length, 100)
        test.equal(g1.url.parse(location.href).hash, '')

        test.equal($('.external-api table tbody tr').length, 100)
        // test edit: option is not valid for external api
        test.equal($('.external-api .edit').children().length, 0)

        // TODO: write test case when filtering with boolean/number values. No results return
        // Fix it and make sure  it returns results


        //
        test.end()
      })
      .formhandler({
        data: response,
        edit: true,
        pagesize: 100,
        columns: [
          {
            name: '*'
          }
        ]
        })
      })

    tape('$().formhandler() datafilter external api test with options & data overrides src', function (test) {
      $('.external-api2')
        .on('load', function () {
84
          test.equal($('.external-api2 .count').text().trim(), '196 rows')
85 86 87 88 89 90 91 92 93 94
          test.ok($('.external-api2 ul.pagination .page-item:nth-of-type(2)').has("disabled"))
          test.ok($('.external-api2 ul.pagination .page-item:nth-of-type(2)').hasClass("active"))
          test.equal($('.external-api2 ul.pagination').children().length, 7)
          test.equal($('.external-api2 table tbody tr').length, 10)
          // test edit: option is not valid for external api
          test.equal($('.external-api2 .edit').children().length, 0)
          test.end()
        })
        .formhandler({
          data: response,
95
          src: './formhandler_csv.json',
96 97 98 99 100 101 102 103 104 105
          edit: true,
          pageSize: 10
        })
    })

  })

  </script>
</body>
</html>