github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/themes/wind/static/libs/vue-1.0.24/test/e2e/grid.js (about)

     1  casper.test.begin('grid', 73, function (test) {
     2    casper
     3    .start('examples/grid/index.html')
     4    .then(function () {
     5      // headers
     6      test.assertElementCount('th', 2)
     7      test.assertElementCount('th.active', 0)
     8      test.assertSelectorHasText('th:nth-child(1)', 'Name')
     9      test.assertSelectorHasText('th:nth-child(2)', 'Power')
    10      assertTable(test, ['name', 'power'], [
    11        { name: 'Chuck Norris', power: Infinity },
    12        { name: 'Bruce Lee', power: 9000 },
    13        { name: 'Jackie Chan', power: 7000 },
    14        { name: 'Jet Li', power: 8000 }
    15      ])
    16    })
    17    // test sorting
    18    .thenClick('th:nth-child(1)', function () {
    19      test.assertElementCount('th.active:nth-child(1)', 1)
    20      test.assertElementCount('th.active:nth-child(2)', 0)
    21      test.assertElementCount('th:nth-child(1) .arrow.dsc', 1)
    22      test.assertElementCount('th:nth-child(2) .arrow.dsc', 0)
    23      assertTable(test, ['name', 'power'], [
    24        { name: 'Jet Li', power: 8000 },
    25        { name: 'Jackie Chan', power: 7000 },
    26        { name: 'Chuck Norris', power: Infinity },
    27        { name: 'Bruce Lee', power: 9000 }
    28      ])
    29    })
    30    .thenClick('th:nth-child(2)', function () {
    31      test.assertElementCount('th.active:nth-child(1)', 0)
    32      test.assertElementCount('th.active:nth-child(2)', 1)
    33      test.assertElementCount('th:nth-child(1) .arrow.dsc', 1)
    34      test.assertElementCount('th:nth-child(2) .arrow.dsc', 1)
    35      assertTable(test, ['name', 'power'], [
    36        { name: 'Chuck Norris', power: Infinity },
    37        { name: 'Bruce Lee', power: 9000 },
    38        { name: 'Jet Li', power: 8000 },
    39        { name: 'Jackie Chan', power: 7000 }
    40      ])
    41    })
    42    .thenClick('th:nth-child(2)', function () {
    43      test.assertElementCount('th.active:nth-child(1)', 0)
    44      test.assertElementCount('th.active:nth-child(2)', 1)
    45      test.assertElementCount('th:nth-child(1) .arrow.dsc', 1)
    46      test.assertElementCount('th:nth-child(2) .arrow.asc', 1)
    47      assertTable(test, ['name', 'power'], [
    48        { name: 'Jackie Chan', power: 7000 },
    49        { name: 'Jet Li', power: 8000 },
    50        { name: 'Bruce Lee', power: 9000 },
    51        { name: 'Chuck Norris', power: Infinity }
    52      ])
    53    })
    54    .thenClick('th:nth-child(1)', function () {
    55      test.assertElementCount('th.active:nth-child(1)', 1)
    56      test.assertElementCount('th.active:nth-child(2)', 0)
    57      test.assertElementCount('th:nth-child(1) .arrow.asc', 1)
    58      test.assertElementCount('th:nth-child(2) .arrow.asc', 1)
    59      assertTable(test, ['name', 'power'], [
    60        { name: 'Bruce Lee', power: 9000 },
    61        { name: 'Chuck Norris', power: Infinity },
    62        { name: 'Jackie Chan', power: 7000 },
    63        { name: 'Jet Li', power: 8000 }
    64      ])
    65    })
    66    // test search
    67    .then(function () {
    68      this.fill('#search', {
    69        query: 'j'
    70      })
    71    })
    72    .then(function () {
    73      assertTable(test, ['name', 'power'], [
    74        { name: 'Jackie Chan', power: 7000 },
    75        { name: 'Jet Li', power: 8000 }
    76      ])
    77    })
    78    .then(function () {
    79      this.fill('#search', {
    80        query: 'infinity'
    81      })
    82    })
    83    .then(function () {
    84      assertTable(test, ['name', 'power'], [
    85        { name: 'Chuck Norris', power: Infinity }
    86      ])
    87    })
    88    // run
    89    .run(function () {
    90      test.done()
    91    })
    92  
    93    /**
    94     * Helper to assert the table data is rendered correctly.
    95     *
    96     * @param {CasperTester} test
    97     * @param {Array} columns
    98     * @param {Array} data
    99     */
   100  
   101    function assertTable (test, columns, data) {
   102      test.assertElementCount('td', data.length * columns.length)
   103      for (var i = 0; i < data.length; i++) {
   104        for (var j = 0; j < columns.length; j++) {
   105          test.assertSelectorHasText(
   106            'tr:nth-child(' + (i + 1) + ') td:nth-child(' + (j + 1) + ')',
   107            data[i][columns[j]]
   108          )
   109        }
   110      }
   111    }
   112  })