From 2a239bb0feafd37d75414e446df72069541064d6 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Mon, 18 Jul 2016 22:04:49 -0400 Subject: [PATCH] Setup test helpers and additional test to verify pickadate functionality Reference issue #44 --- app/templates/components/ember-tabular.hbs | 2 +- tests/.jshintrc | 4 +- tests/acceptance/basic-test.js | 53 ++++++++++++++++++++++ tests/dummy/app/styles/app.css | 4 ++ tests/helpers/util.js | 8 ++++ 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/app/templates/components/ember-tabular.hbs b/app/templates/components/ember-tabular.hbs index ce47e29..f98d2b5 100644 --- a/app/templates/components/ember-tabular.hbs +++ b/app/templates/components/ember-tabular.hbs @@ -43,7 +43,7 @@ {{/each}} {{#if isColumnFilters}} - + {{#each columns as |header|}} {{#if header.property}} {{ember-tabular-filter modelName=modelName columns=columns property=header.property record=record query=query filter=filter header=header}} diff --git a/tests/.jshintrc b/tests/.jshintrc index da2a020..4916140 100644 --- a/tests/.jshintrc +++ b/tests/.jshintrc @@ -28,7 +28,9 @@ "getPretenderRequestBody", "assertIn", "selectChoose", - "selectSearch" + "selectSearch", + "disableDatePicker", + "setDatePicker" ], "node": false, "browser": false, diff --git a/tests/acceptance/basic-test.js b/tests/acceptance/basic-test.js index 3818e6b..7701b11 100644 --- a/tests/acceptance/basic-test.js +++ b/tests/acceptance/basic-test.js @@ -12,6 +12,8 @@ test('Check table pagination - 0 pages', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + let cells = find('.table-default table tbody tr').eq(0).find('td'); assert.equal(find('.table-default table tbody tr').length, 1, 'Check for 1 items in table'); @@ -27,6 +29,8 @@ test('Check table pagination - 5 pages', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + assert.equal(find('.table-default table tbody tr').length, 10, 'Check for 10 items in table'); assert.equal(find('.table-default .pagination > *').length, 7, 'Pagination is 5 pages'); }); @@ -39,6 +43,8 @@ test('Check for expected content', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + let cells = find('.table-default table tbody tr').eq(0).find('td'); assert.equal(cells.eq(0).html(), 'AnakinSkywalker9', 'Check for username'); @@ -70,6 +76,8 @@ test('Check for error handling', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + assertIn(assert, find('.alert').text(), 'Error', 'Check for general error message.'); }); }); @@ -80,6 +88,7 @@ test('Check table rendering for no data or loading', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); }); let store = this.application.__container__.lookup('service:store'); @@ -100,6 +109,9 @@ test('Check table rendering for pagination', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + + disableDatePicker(); + // Transition to the next page click('.table-default .pagination .next a'); }); @@ -125,6 +137,8 @@ test('Check for expected content sorting', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + click('table th:contains("Last Name") .btn-sort'); }); @@ -157,6 +171,8 @@ test('Check for disabled sorting', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + click('.table-default table th:contains("Last Updated")'); }); @@ -191,6 +207,8 @@ test('Check for expected content filter', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + click('.table-default table .btn-toggle-filter:eq(0)'); fillIn('.table-default table thead tr:eq(1) th:eq(3) input', 'McClane'); find('.table-default table thead tr:eq(1) th:eq(3) input').trigger('keyup'); @@ -225,6 +243,8 @@ test('Check for expected content multiple filters', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + click('.table-default table .btn-toggle-filter:eq(0)'); fillIn('.table-default table thead tr:eq(1) th:eq(2) input', 'John'); find('.table-default table thead tr:eq(1) th:eq(2) input').trigger('keyup'); @@ -261,6 +281,8 @@ test('Check for expected content sort/filter', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + click('.table-default table th:contains("Last Name") .btn-sort'); }); @@ -299,6 +321,8 @@ test('Check for expected content dropdown filter', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + click('.table-default table .btn-toggle-filter:eq(0)'); selectChoose('.table-default .ember-tabular-ember-power-select:eq(0)', 'Yes'); }); @@ -319,6 +343,8 @@ test('Check table-default for dropdown clear success', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); + click('.table-default .btn-toggle-filter:eq(0)'); }); @@ -343,12 +369,35 @@ test('Check table-default for dropdown clear success', function(assert) { }); }); +test('Check for expected content date picker', function(assert) { + server.loadFixtures('users'); + visit('/'); + + andThen(function() { + assert.equal(currentPath(), 'index'); + + click('.table-default table .btn-toggle-filter:eq(0)'); + click('.table-default table #filter-updatedAt input'); + // due to bug within pickadate 1 month is being added + setDatePicker('#filter-updatedAt input', [2017, 0, 2]); + }); + + andThen(function() { + var request = getPretenderRequest(server, 'GET', 'users')[0]; + + assert.equal(request.status, 200); + assert.equal(request.method, 'GET'); + assert.equal(request.url, '/users?filter%5Bupdated-at%5D=2017-01-02&page%5Blimit%5D=10&page%5Boffset%5D=0&sort=username', 'Expected query params in URL'); + }); +}); + test('Check table-basic-global-filter for expected content after filtering', function(assert) { server.loadFixtures('users'); visit('/'); andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); }); andThen(function() { @@ -383,6 +432,7 @@ test('Check for clearFilter action success', function(assert) { andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); }); andThen(function() { @@ -410,6 +460,7 @@ test('Check table-basic-global-filter for clearFilter action success', function( andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); }); andThen(function() { @@ -436,6 +487,7 @@ test('Check table-basic-global-date-filter to filter by date and is-admin', func andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); }); andThen(function() { @@ -462,6 +514,7 @@ test('Check table-basic-global-date-filter for date clearFilter action success', andThen(function() { assert.equal(currentPath(), 'index'); + disableDatePicker(); }); andThen(function() { diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.css index d852da7..6f7f930 100644 --- a/tests/dummy/app/styles/app.css +++ b/tests/dummy/app/styles/app.css @@ -19,3 +19,7 @@ .ember-tabular .table-responsive { overflow-x:inherit; } + +.form-control.picker__input{ + background-color:inherit; +} diff --git a/tests/helpers/util.js b/tests/helpers/util.js index 280e412..e3ad51b 100644 --- a/tests/helpers/util.js +++ b/tests/helpers/util.js @@ -40,4 +40,12 @@ export default function() { Ember.Test.registerHelper('assertIn', function(app, assert, subject, value, description) { return assert.equal(subject.indexOf(value) > -1, true, description); }); + + Ember.Test.registerHelper('disableDatePicker', function() { + find('.picker__input').pickadate('picker').stop(); + }); + + Ember.Test.registerHelper('setDatePicker', function(app, selector, date) { + find(selector).pickadate('picker').set('select', date).close(); + }); }