Skip to content

Commit

Permalink
Setup test helpers and additional test to verify pickadate functionality
Browse files Browse the repository at this point in the history
Reference issue #44
  • Loading branch information
aaronfischer committed Jul 19, 2016
1 parent eb5b699 commit 2a239bb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/templates/components/ember-tabular.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{{/each}}
</tr>
{{#if isColumnFilters}}
<tr class="{{if showFilterRow 'showFilterRow' 'hideFilterRow'}}">
<tr class="{{if showFilterRow 'showFilterRow' 'hideFilterRow'}} ember-tabular-filters">
{{#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}}
Expand Down
4 changes: 3 additions & 1 deletion tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"getPretenderRequestBody",
"assertIn",
"selectChoose",
"selectSearch"
"selectSearch",
"disableDatePicker",
"setDatePicker"
],
"node": false,
"browser": false,
Expand Down
53 changes: 53 additions & 0 deletions tests/acceptance/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
});
Expand All @@ -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');
Expand Down Expand Up @@ -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.');
});
});
Expand All @@ -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');
Expand All @@ -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');
});
Expand All @@ -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');
});

Expand Down Expand Up @@ -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")');
});

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
});

Expand Down Expand Up @@ -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');
});
Expand All @@ -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)');
});

Expand All @@ -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() {
Expand Down Expand Up @@ -383,6 +432,7 @@ test('Check for clearFilter action success', function(assert) {

andThen(function() {
assert.equal(currentPath(), 'index');
disableDatePicker();
});

andThen(function() {
Expand Down Expand Up @@ -410,6 +460,7 @@ test('Check table-basic-global-filter for clearFilter action success', function(

andThen(function() {
assert.equal(currentPath(), 'index');
disableDatePicker();
});

andThen(function() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions tests/dummy/app/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@
.ember-tabular .table-responsive {
overflow-x:inherit;
}

.form-control.picker__input{
background-color:inherit;
}
8 changes: 8 additions & 0 deletions tests/helpers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

0 comments on commit 2a239bb

Please sign in to comment.