Skip to content

Commit 2c0ca2f

Browse files
committed
Add integration test for changeDate action when input is cleared.
Also move an existing test from unit to integration test style. It also tests the clearing of the input field, so it might make sense to have both tests in the same place.
1 parent ec69d45 commit 2c0ca2f

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Ember from 'ember';
2+
import hbs from 'htmlbars-inline-precompile';
3+
import { moduleForComponent, test } from 'ember-qunit';
4+
5+
moduleForComponent('bootstrap-datepicker', 'BootstrapDatepickerComponent', {
6+
integration: true
7+
});
8+
9+
test('resets date when input is cleared', function (assert) {
10+
assert.expect(2);
11+
12+
this.set('myDate', new Date());
13+
14+
this.render(hbs`
15+
{{bootstrap-datepicker value=myDate}}
16+
`);
17+
18+
var datepicker = this.$('input.ember-text-field').datepicker();
19+
20+
datepicker.val('');
21+
Ember.run(() => {
22+
datepicker.trigger('input');
23+
});
24+
25+
assert.equal(this.get('myDate'), null, 'value is reset');
26+
assert.equal(this.$('input.ember-text-field').datepicker('getDate'), null, 'datepicker is updated');
27+
});
28+
29+
test('triggers changeDate action when input field is cleared', function (assert) {
30+
assert.expect(1);
31+
32+
this.set('myDate', new Date());
33+
34+
var actionIsTriggered = false;
35+
this.on('myAction', () => {
36+
actionIsTriggered = true;
37+
});
38+
39+
this.render(hbs`
40+
{{bootstrap-datepicker value=myDate changeDate="myAction"}}
41+
`);
42+
43+
var datepicker = this.$('input.ember-text-field').datepicker();
44+
45+
datepicker.val('');
46+
Ember.run(() => {
47+
datepicker.trigger('input');
48+
});
49+
50+
assert.ok(actionIsTriggered, 'action is triggered');
51+
});

tests/unit/components/bootstrap-datepicker-test.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ test('displays date with custom format when format is set', function(assert) {
4242
assert.equal(this.$().val(), '31.Dec.14');
4343
});
4444

45-
test('resets date when input is cleared', function(assert) {
46-
this.subject({
47-
value: new Date(2014, 11, 31)
48-
});
49-
50-
assert.ok(this.$().datepicker('getDate'), 'initial value is set');
51-
52-
this.$().val('');
53-
this.$().trigger('input');
54-
55-
assert.equal(this.$().datepicker('getDate'), null, 'value is reset when input is cleared');
56-
});
57-
5845
test('sets dates provided by value (multidate, default multidateSeparator)', function(assert) {
5946
this.subject({
6047
value: [new Date(2015, 0, 13), new Date(2015, 0, 7), new Date(2015, 0, 15)],

0 commit comments

Comments
 (0)