From 7303af44f2d2fb3e51d742fab800c5afd46de57e Mon Sep 17 00:00:00 2001 From: Martin Adler Date: Thu, 20 Dec 2018 14:34:16 +0100 Subject: [PATCH 1/5] Enable integration tests --- .../components/bs-datetimepicker-test.js | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tests/integration/components/bs-datetimepicker-test.js b/tests/integration/components/bs-datetimepicker-test.js index e294f08..afe3f4a 100644 --- a/tests/integration/components/bs-datetimepicker-test.js +++ b/tests/integration/components/bs-datetimepicker-test.js @@ -1,23 +1,30 @@ -// import { moduleForComponent, test } from 'ember-qunit'; -// import hbs from 'htmlbars-inline-precompile'; +import { moduleForComponent, test, todo } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; -// moduleForComponent('bs-datetimepicker', 'Integration | Component | bs datetimepicker', { -// integration: true -// }); +moduleForComponent('bs-datetimepicker', 'Integration | Component | bs datetimepicker', { + integration: true +}); -// test('it renders iconClasses and iconText', function(assert) { -// assert.expect(2); +todo('it renders iconClasses and iconText', function(assert) { + assert.expect(2); -// this.render(hbs`{{bs-datetimepicker date='01/01/2016' iconClasses='material-icons' iconText='date-range'}}`); + this.render( + hbs`{{bs-datetimepicker date='2016-01-01' iconClasses='material-icons' iconText='date-range'}}` + ); -// assert.equal(this.$('.input-group-addon i').attr('class'), 'material-icons'); -// assert.equal(this.$('.input-group-addon i').text().trim(), 'date-range'); -// }); + assert.equal(this.$('.input-group-addon i').attr('class'), 'material-icons'); + assert.equal( + this.$('.input-group-addon i') + .text() + .trim(), + 'date-range' + ); +}); -// test('it renders with default icon classes', function(assert) { -// assert.expect(1); +test('it renders with default icon classes', function(assert) { + assert.expect(1); -// this.render(hbs`{{bs-datetimepicker date='01/01/2016'}}`); + this.render(hbs`{{bs-datetimepicker date='2016-01-01'}}`); -// assert.equal(this.$('.input-group-addon i').attr('class'), 'glyphicon glyphicon-calendar'); -// }); + assert.equal(this.$('.input-group-addon i').attr('class'), 'glyphicon glyphicon-calendar'); +}); From 8afbab929b89f96b8a5782f0b3bb3033294f789e Mon Sep 17 00:00:00 2001 From: Martin Adler Date: Fri, 21 Dec 2018 00:32:30 +0100 Subject: [PATCH 2/5] Apply ember codemods on tests --- .../components/bs-datetimepicker-test.js | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/tests/integration/components/bs-datetimepicker-test.js b/tests/integration/components/bs-datetimepicker-test.js index afe3f4a..8721c77 100644 --- a/tests/integration/components/bs-datetimepicker-test.js +++ b/tests/integration/components/bs-datetimepicker-test.js @@ -1,30 +1,25 @@ -import { moduleForComponent, test, todo } from 'ember-qunit'; +import { module, test, todo } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; -moduleForComponent('bs-datetimepicker', 'Integration | Component | bs datetimepicker', { - integration: true -}); +module('Integration | Component | bs datetimepicker', function(hooks) { + setupRenderingTest(hooks); -todo('it renders iconClasses and iconText', function(assert) { - assert.expect(2); + todo('it renders iconClasses and iconText', async function(assert) { + assert.expect(2); - this.render( - hbs`{{bs-datetimepicker date='2016-01-01' iconClasses='material-icons' iconText='date-range'}}` - ); + await render(hbs`{{bs-datetimepicker date='2016-01-01' iconClasses='material-icons' iconText='date-range'}}`); - assert.equal(this.$('.input-group-addon i').attr('class'), 'material-icons'); - assert.equal( - this.$('.input-group-addon i') - .text() - .trim(), - 'date-range' - ); -}); + assert.dom('.input-group-addon i').hasAttribute('class', 'material-icons'); + assert.dom('.input-group-addon i').hasText('date-range'); + }); -test('it renders with default icon classes', function(assert) { - assert.expect(1); + test('it renders with default icon classes', async function(assert) { + assert.expect(1); - this.render(hbs`{{bs-datetimepicker date='2016-01-01'}}`); + await render(hbs`{{bs-datetimepicker date='2016-01-01'}}`); - assert.equal(this.$('.input-group-addon i').attr('class'), 'glyphicon glyphicon-calendar'); + assert.dom('.input-group-addon i').hasAttribute('class', 'glyphicon glyphicon-calendar'); + }); }); From a19a7650ff450c1f4d4732a1ca6f986934375f30 Mon Sep 17 00:00:00 2001 From: Martin Adler Date: Sat, 22 Dec 2018 01:29:52 +0100 Subject: [PATCH 3/5] Add more tests --- .../components/bs-datetimepicker-test.js | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/tests/integration/components/bs-datetimepicker-test.js b/tests/integration/components/bs-datetimepicker-test.js index 8721c77..47a9660 100644 --- a/tests/integration/components/bs-datetimepicker-test.js +++ b/tests/integration/components/bs-datetimepicker-test.js @@ -1,25 +1,56 @@ -import { module, test, todo } from 'qunit'; +import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import { render } from '@ember/test-helpers'; +import { render, focus } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; module('Integration | Component | bs datetimepicker', function(hooks) { setupRenderingTest(hooks); - todo('it renders iconClasses and iconText', async function(assert) { - assert.expect(2); - - await render(hbs`{{bs-datetimepicker date='2016-01-01' iconClasses='material-icons' iconText='date-range'}}`); + test('it renders basic input', async function(assert) { + assert.expect(1); - assert.dom('.input-group-addon i').hasAttribute('class', 'material-icons'); - assert.dom('.input-group-addon i').hasText('date-range'); + await render(hbs`{{bs-datetimepicker date='2016-01-01'}}`); + assert.dom('input').hasValue('01/01/2016 12:00 AM'); }); test('it renders with default icon classes', async function(assert) { assert.expect(1); await render(hbs`{{bs-datetimepicker date='2016-01-01'}}`); + assert.dom('.input-group-addon i').hasAttribute('class', 'glyphicon glyphicon-calendar'); + }); + + test('it renders calendar and time icon classes based on isTime argument', async function(assert) { + assert.expect(2); + + this.set('isTime', false); + await render(hbs`{{bs-datetimepicker date='2016-01-01' isTime=isTime}}`); assert.dom('.input-group-addon i').hasAttribute('class', 'glyphicon glyphicon-calendar'); + this.set('isTime', true); + assert.dom('.input-group-addon i').hasAttribute('class', 'glyphicon glyphicon-time'); + }); + + test('changing the value will trigger change action', async function(assert) { + assert.expect(1); + + const done = assert.async(); + this.set('callback', date => { + assert.equal(date.toISOString(), '2016-01-01T00:00:00.000Z'); + done(); + }); + await render(hbs`{{bs-datetimepicker date="1970-01-01" change=callback}}`); + // Set a new Date to trigger the dp.change event + this.$('.input-group.date') + .data('DateTimePicker') + .date(new Date('2016-01-01')); + }); + + test('opens picker on focus when openOnFocus is enabled', async function(assert) { + assert.expect(1); + + await render(hbs`{{bs-datetimepicker date="1970-01-01" openOnFocus=true}}`); + await focus('input'); + assert.dom('.bootstrap-datetimepicker-widget').exists('picker should be shown'); }); }); From 193d1e8c975292f65e6cf5253fa3f6e9f7aa7376 Mon Sep 17 00:00:00 2001 From: Martin Adler Date: Fri, 21 Dec 2018 21:03:00 +0100 Subject: [PATCH 4/5] Ignore eslint ember/no-attrs-in-components --- addon/-private/dynamic-attribute-bindings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addon/-private/dynamic-attribute-bindings.js b/addon/-private/dynamic-attribute-bindings.js index cc6c60a..38e38d4 100644 --- a/addon/-private/dynamic-attribute-bindings.js +++ b/addon/-private/dynamic-attribute-bindings.js @@ -8,6 +8,7 @@ export default Mixin.create({ this._super(...arguments); let newAttributeBindings = []; + // eslint-disable-next-line ember/no-attrs-in-components for (let key in this.attrs) { if (this.NON_ATTRIBUTE_BOUND_PROPS.indexOf(key) === -1 && this.attributeBindings.indexOf(key) === -1) { newAttributeBindings.push(key); From 0e98392f8d2e53828382cfc3db60ba7af2f106cb Mon Sep 17 00:00:00 2001 From: Martin Adler Date: Sun, 30 Dec 2018 21:59:57 +0100 Subject: [PATCH 5/5] Fix ESLint error The comment line from the ember project template was inserted to satisfy the linter. --- tests/dummy/config/environment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index 9f7fdca..fda6fa4 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -41,7 +41,7 @@ module.exports = function(environment) { } if (environment === 'production') { - + // here you can enable a production-specific feature } return ENV;