2018-08-09 10:41:52 -07:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2018-08-09 23:25:55 -07:00
|
|
|
import { render, find, findAll, click, fillIn } from '@ember/test-helpers';
|
2018-01-20 00:46:47 -08:00
|
|
|
import notificationsStub from 'wherehows-web/tests/stubs/services/notifications';
|
2017-11-01 09:10:42 -07:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import { run } from '@ember/runloop';
|
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
module('Integration | Component | dataset deprecation', function(hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
test('it renders', async function(assert) {
|
|
|
|
assert.expect(4);
|
|
|
|
|
|
|
|
await render(hbs`{{dataset-deprecation}}`);
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
document.querySelector('.dataset-deprecation-toggle__toggle-header__label'),
|
|
|
|
'it shows the dataset is deprecation label element'
|
|
|
|
);
|
2018-08-09 23:25:55 -07:00
|
|
|
assert.equal(findAll('#dataset-is-deprecated').length, 1, 'has one input checkbox with known selector');
|
2018-08-09 10:41:52 -07:00
|
|
|
assert.equal(
|
2018-08-09 23:25:55 -07:00
|
|
|
find('#dataset-is-deprecated').getAttribute('type'),
|
2018-08-09 10:41:52 -07:00
|
|
|
'checkbox',
|
|
|
|
'has an input checkbox to toggle deprecation'
|
|
|
|
);
|
2018-08-09 23:25:55 -07:00
|
|
|
assert.equal(findAll('.dataset-deprecation-toggle__actions').length, 1, 'has an actions container');
|
2018-08-09 10:41:52 -07:00
|
|
|
});
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('setting the deprecated property should toggle the checkbox', async function(assert) {
|
|
|
|
assert.expect(2);
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
this.set('deprecated', true);
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
await render(hbs`{{dataset-deprecation deprecated=deprecated}}`);
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
assert.ok(this.$('#dataset-is-deprecated').is(':checked'), 'checkbox is checked when property is set true');
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
this.set('deprecated', false);
|
|
|
|
assert.notOk(this.$('#dataset-is-deprecated').is(':checked'), 'checkbox is unchecked when property is set false');
|
|
|
|
});
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('decommissionTime', async function(assert) {
|
|
|
|
let isDisabled;
|
2018-09-27 16:57:46 -07:00
|
|
|
assert.expect(3);
|
2018-03-28 13:50:02 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
this.set('decommissionTime', void 0);
|
|
|
|
this.set('deprecated', true);
|
2018-03-28 13:50:02 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
await render(hbs`{{dataset-deprecation deprecated=deprecated decommissionTime=decommissionTime}}`);
|
|
|
|
isDisabled = this.$('.dataset-deprecation-toggle__actions [type=submit]').is(':disabled');
|
|
|
|
assert.ok(isDisabled, 'submit button is disabled');
|
2018-03-28 13:50:02 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
this.setProperties({ decommissionTime: new Date(), isDirty: true });
|
|
|
|
await render(hbs`{{dataset-deprecation deprecated=deprecated decommissionTime=decommissionTime}}`);
|
|
|
|
await fillIn('.comment-new__content', 'text');
|
2018-03-28 13:50:02 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
isDisabled = this.$('.dataset-deprecation-toggle__actions [type=submit]').is(':disabled');
|
2018-09-27 16:57:46 -07:00
|
|
|
assert.ok(isDisabled, 'submit button is disabled if we only fill in decomissionTime');
|
|
|
|
|
|
|
|
await click('#acknowledge-deprecation');
|
|
|
|
|
|
|
|
isDisabled = this.$('.dataset-deprecation-toggle__actions [type=submit]').is(':disabled');
|
|
|
|
assert.notOk(isDisabled, 'submit button is disabled if we only fill in decomissionTime');
|
2018-08-09 10:41:52 -07:00
|
|
|
});
|
2018-03-28 13:50:02 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('triggers the onUpdateDeprecation action when submitted', async function(assert) {
|
|
|
|
let submitActionCallCount = 0;
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
this.set('submit', function(deprecated, note) {
|
|
|
|
submitActionCallCount++;
|
|
|
|
assert.equal(deprecated, true, 'action is called with deprecation value of true');
|
|
|
|
assert.equal(note, '', 'action is called with an empty deprecation note');
|
|
|
|
});
|
|
|
|
this.set('decommissionTime', new Date());
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
await render(hbs`{{dataset-deprecation onUpdateDeprecation=(action submit) decommissionTime=decommissionTime}}`);
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
assert.equal(submitActionCallCount, 0, 'action is not called on render');
|
|
|
|
assert.equal(this.$('#dataset-is-deprecated').is(':checked'), false, 'deprecation checkbox is unchecked');
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
await click('#dataset-is-deprecated');
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
assert.equal(this.$('#dataset-is-deprecated').is(':checked'), true, 'deprecation checkbox is checked');
|
2018-09-27 16:57:46 -07:00
|
|
|
|
|
|
|
await click('#acknowledge-deprecation');
|
2018-08-09 10:41:52 -07:00
|
|
|
await click('.dataset-deprecation-toggle__actions [type=submit]');
|
2017-11-01 09:10:42 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
assert.equal(submitActionCallCount, 1, 'action is called once');
|
|
|
|
});
|
2017-11-01 09:10:42 -07:00
|
|
|
});
|