2018-08-09 10:41:52 -07:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render } from '@ember/test-helpers';
|
2017-11-10 02:05:48 -08:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2017-11-13 11:07:38 -08:00
|
|
|
import { triggerEvent } from 'ember-native-dom-helpers';
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-06-25 23:42:28 -07:00
|
|
|
import { noop } from 'wherehows-web/utils/helpers/functions';
|
2017-11-10 02:05:48 -08:00
|
|
|
import { OwnerType, OwnerSource } from 'wherehows-web/utils/api/datasets/owners';
|
|
|
|
import owners from 'wherehows-web/mirage/fixtures/owners';
|
|
|
|
import userStub from 'wherehows-web/tests/stubs/services/current-user';
|
2017-11-13 11:07:38 -08:00
|
|
|
import { minRequiredConfirmedOwners } from 'wherehows-web/constants/datasets/owner';
|
2017-11-10 02:05:48 -08:00
|
|
|
|
|
|
|
const [confirmedOwner] = owners;
|
|
|
|
const ownerTypes = Object.values(OwnerType);
|
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
module('Integration | Component | dataset authors', function(hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
hooks.beforeEach(function() {
|
|
|
|
this.owner.register('service:current-user', userStub);
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
this['current-user'] = this.owner.lookup('service:current-user');
|
|
|
|
});
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('it renders', async function(assert) {
|
|
|
|
assert.expect(1);
|
|
|
|
this.set('owners', owners);
|
|
|
|
this.set('ownerTypes', ownerTypes);
|
|
|
|
this.set('saveOwnerChanges', noop);
|
|
|
|
await render(hbs`{{dataset-authors owners=owners ownerTypes=ownerTypes save=(action saveOwnerChanges)}}`);
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
assert.equal(this.$('.dataset-author').length, 2, 'expected two dataset author components to be rendered');
|
|
|
|
});
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('it should remove an owner when removeOwner is invoked', async function(assert) {
|
|
|
|
assert.expect(1);
|
|
|
|
this.set('owners', [confirmedOwner]);
|
|
|
|
this.set('ownerTypes', ownerTypes);
|
|
|
|
this.set('saveOwnerChanges', noop);
|
|
|
|
await render(hbs`{{dataset-authors owners=owners ownerTypes=ownerTypes save=(action saveOwnerChanges)}}`);
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
triggerEvent('.remove-dataset-author', 'click');
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
assert.equal(this.get('owners').length, 0);
|
|
|
|
});
|
2017-11-13 11:07:38 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('it should update a suggested owner to confirmed', async function(assert) {
|
|
|
|
assert.expect(3);
|
|
|
|
const [owner, suggestedOwner] = owners;
|
|
|
|
const resolvedOwners = [owner];
|
|
|
|
const suggestedOwners = [suggestedOwner];
|
|
|
|
|
|
|
|
const initialLength = resolvedOwners.length;
|
|
|
|
let userName, confirmedOwner;
|
|
|
|
|
|
|
|
this.set('owners', resolvedOwners);
|
|
|
|
this.set('ownerTypes', ownerTypes);
|
|
|
|
this.set('saveOwnerChanges', noop);
|
|
|
|
this.set('suggestedOwners', suggestedOwners);
|
|
|
|
await render(
|
|
|
|
hbs`{{dataset-authors owners=owners suggestedOwners=suggestedOwners ownerTypes=ownerTypes save=(action saveOwnerChanges)}}`
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
this.get('owners.length'),
|
|
|
|
initialLength,
|
|
|
|
`the list of owners is ${initialLength} before adding confirmed owner`
|
|
|
|
);
|
|
|
|
|
|
|
|
triggerEvent('.dataset-authors-suggested__info__trigger', 'click');
|
|
|
|
triggerEvent('.suggested-owner-card__owner-info__add button', 'click');
|
|
|
|
|
|
|
|
userName = this.get('current-user.currentUser.userName');
|
|
|
|
confirmedOwner = this.get('owners').findBy('confirmedBy', userName);
|
|
|
|
|
|
|
|
assert.equal(this.get('owners.length'), initialLength + 1, 'the list of owner contains one more new owner');
|
|
|
|
assert.equal(confirmedOwner.source, OwnerSource.Ui, 'contains a new owner with ui source');
|
|
|
|
});
|
2017-11-13 11:07:38 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('it should disable the save button when confirmedOwners is less than required minimum', async function(assert) {
|
|
|
|
assert.expect(2);
|
|
|
|
this.set('owners', [confirmedOwner]);
|
|
|
|
this.set('ownerTypes', ownerTypes);
|
|
|
|
this.set('saveOwnerChanges', noop);
|
|
|
|
await render(hbs`{{dataset-authors owners=owners ownerTypes=ownerTypes save=(action saveOwnerChanges)}}`);
|
2017-11-13 11:07:38 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
const isDisabled = document.querySelector('.dataset-authors-save').disabled;
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
assert.ok(
|
|
|
|
this.get('owners').length < minRequiredConfirmedOwners,
|
|
|
|
`owners is less than the minimum required ${minRequiredConfirmedOwners}`
|
|
|
|
);
|
|
|
|
assert.equal(isDisabled, true, 'save button interaction is disabled');
|
2017-11-10 02:05:48 -08:00
|
|
|
});
|
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('it should invoke the external save action on save', async function(assert) {
|
|
|
|
assert.expect(2);
|
|
|
|
this.set('owners', [confirmedOwner]);
|
|
|
|
this.set('ownerTypes', ownerTypes);
|
|
|
|
this.set('saveOwnerChanges', owners => {
|
|
|
|
assert.ok(owners === this.get('owners'), 'the list of owners is passed into the save action');
|
|
|
|
});
|
|
|
|
await render(
|
|
|
|
hbs`{{dataset-authors owners=owners ownerTypes=ownerTypes requiredMinNotConfirmed=requiredMinNotConfirmed save=(action saveOwnerChanges)}}`
|
|
|
|
);
|
|
|
|
|
|
|
|
// enable save button interaction
|
|
|
|
this.set('requiredMinNotConfirmed', false);
|
2017-11-13 11:07:38 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
triggerEvent('.dataset-authors-save', 'click');
|
2017-11-10 02:05:48 -08:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
assert.equal(this.get('owners').length, 1);
|
|
|
|
});
|
2017-11-10 02:05:48 -08:00
|
|
|
});
|