Skip to content

Commit

Permalink
Tests with mut helper and value
Browse files Browse the repository at this point in the history
  • Loading branch information
mlazze committed Mar 4, 2017
1 parent 288482c commit 71300a4
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions tests/integration/components/ember-flatpickr-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,93 @@ test('onChange gets called with the correct parameters', function(assert) {
});

});

test('onChange action mut helper returns date', function(assert) {
assert.expect(5);

let originalPosition = '1';
let originalDate = '2080-12-01T20:00:00.000Z';
let newPosition = '5';

this.set('dateValue', originalDate);

this.render(
hbs`{{ember-flatpickr
onChange=(action (mut dateValue))
placeholder="Pick date"
value=(readonly dateValue)
}}`);

run(() => {
assert.equal($('.flatpickr-days .flatpickr-day.selected').text(), originalPosition, 'initial selected date text');

$('.flatpickr-input')[0].dispatchEvent(new Event('focus'));
$('.flatpickr-days .flatpickr-day').get(newPosition - 1).click();

assert.equal($('.flatpickr-days .flatpickr-day.selected').text(), newPosition, 'selected changes with dateValue');

assert.ok(this.get('dateValue') instanceof Array, 'dateValue is instanceof Array');
assert.ok(this.get('dateValue').length, 1, 'dateValue has 1 item');
assert.ok(this.get('dateValue')[0] instanceof Date, 'dateValue is an array of DateObjects');
});

});

test('value accepts string, dateObject or array of string/dateObjects', function(assert) {
assert.expect(4);

let originalDate = '2080-12-05T20:00:00.000Z';

this.set('dateValue', originalDate);

this.render(
hbs`{{ember-flatpickr
onChange=(action (mut dateValue))
placeholder="Pick date"
value=(readonly dateValue)
}}`);

run(() => {
assert.equal($('.flatpickr-days .flatpickr-day.selected').text(), 5, 'initial selected date text');
});

this.set('dateValue', new Date(originalDate));

this.render(
hbs`{{ember-flatpickr
onChange=(action (mut dateValue))
placeholder="Pick date"
value=(readonly dateValue)
}}`);

run(() => {
assert.equal($('.flatpickr-days .flatpickr-day.selected').text(), 5, 'initial selected date text');
});

this.set('dateValue', [originalDate]);

this.render(
hbs`{{ember-flatpickr
onChange=(action (mut dateValue))
placeholder="Pick date"
value=(readonly dateValue)
}}`);

run(() => {
assert.equal($('.flatpickr-days .flatpickr-day.selected').text(), 5, 'initial selected date text');
});

this.set('dateValue', [new Date(originalDate)]);

this.render(
hbs`{{ember-flatpickr
onChange=(action (mut dateValue))
placeholder="Pick date"
value=(readonly dateValue)
}}`);

run(() => {
assert.equal($('.flatpickr-days .flatpickr-day.selected').text(), 5, 'initial selected date text');
});

});

0 comments on commit 71300a4

Please sign in to comment.