2018-01-10 12:06:14 -08:00
|
|
|
import { moduleForComponent, test } from 'ember-qunit';
|
2017-12-01 17:22:24 -08:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2018-01-17 10:40:17 -08:00
|
|
|
import { triggerEvent } from 'ember-native-dom-helpers';
|
2018-01-10 10:11:32 -08:00
|
|
|
import sinon from 'sinon';
|
2018-01-10 12:06:14 -08:00
|
|
|
|
2018-01-17 10:40:17 -08:00
|
|
|
import {
|
|
|
|
missingPolicyText,
|
|
|
|
purgePolicyProps,
|
|
|
|
exemptPolicy,
|
|
|
|
PurgePolicy,
|
|
|
|
getSupportedPurgePolicies
|
|
|
|
} from 'wherehows-web/constants';
|
2018-01-10 10:11:32 -08:00
|
|
|
import { DatasetPlatform } from 'wherehows-web/constants/datasets/platform';
|
2018-01-10 12:06:14 -08:00
|
|
|
import platforms from 'wherehows-web/mirage/fixtures/list-platforms';
|
|
|
|
import { ApiStatus } from 'wherehows-web/utils/api';
|
2017-12-01 17:22:24 -08:00
|
|
|
|
|
|
|
moduleForComponent('purge-policy', 'Integration | Component | purge policy', {
|
2018-01-10 10:11:32 -08:00
|
|
|
integration: true,
|
|
|
|
|
|
|
|
beforeEach() {
|
2018-01-10 12:06:14 -08:00
|
|
|
this.server = sinon.createFakeServer();
|
2018-01-10 10:11:32 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
afterEach() {
|
2018-01-10 12:06:14 -08:00
|
|
|
this.server.restore();
|
2018-01-10 10:11:32 -08:00
|
|
|
}
|
2017-12-01 17:22:24 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
const policyList = '.purge-policy-list';
|
2017-12-01 18:21:00 -08:00
|
|
|
const policyTypes = Object.keys(purgePolicyProps);
|
2017-12-01 17:22:24 -08:00
|
|
|
|
|
|
|
test('it renders', function(assert) {
|
|
|
|
assert.expect(1);
|
|
|
|
|
|
|
|
this.render(hbs`{{purge-policy}}`);
|
|
|
|
|
|
|
|
assert.equal(document.querySelector(policyList).tagName, 'UL', 'expected component element is rendered');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders each purge policy in edit mode', function(assert) {
|
|
|
|
assert.expect(1);
|
2017-12-01 18:21:00 -08:00
|
|
|
const purgePoliciesLength = policyTypes.length;
|
2017-12-01 17:22:24 -08:00
|
|
|
|
|
|
|
this.set('isEditable', true);
|
|
|
|
this.render(hbs`{{purge-policy isEditable=isEditable}}`);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
document.querySelectorAll(`${policyList} [type=radio]`).length,
|
|
|
|
purgePoliciesLength,
|
|
|
|
'all policies are rendered'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it triggers the onPolicyChange action', function(assert) {
|
|
|
|
assert.expect(2);
|
|
|
|
let onPolicyChangeActionCallCount = 0;
|
|
|
|
|
|
|
|
this.set('isEditable', true);
|
|
|
|
|
|
|
|
this.set('onPolicyChange', () => {
|
|
|
|
assert.equal(++onPolicyChangeActionCallCount, 1, 'onPolicyChange action is invoked when change event is triggered');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.render(hbs`{{purge-policy onPolicyChange=onPolicyChange isEditable=isEditable}}`);
|
|
|
|
assert.equal(onPolicyChangeActionCallCount, 0, 'onPolicyChange action is not invoked on instantiation');
|
|
|
|
|
|
|
|
triggerEvent(`${policyList} [type=radio]`, 'change');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders a user message if the purge policy is not set and is in readonly mode', function(assert) {
|
|
|
|
assert.expect(1);
|
|
|
|
|
|
|
|
this.render(hbs`{{purge-policy}}`);
|
|
|
|
assert.equal(
|
|
|
|
document.querySelector(`${policyList} p`).textContent,
|
|
|
|
missingPolicyText,
|
|
|
|
`${missingPolicyText} is rendered`
|
|
|
|
);
|
|
|
|
});
|
2017-12-01 18:21:00 -08:00
|
|
|
|
2018-01-10 12:06:14 -08:00
|
|
|
test('it indicates the currently selected purge policy', async function(assert) {
|
2017-12-01 18:21:00 -08:00
|
|
|
assert.expect(1);
|
2018-01-10 10:11:32 -08:00
|
|
|
const selectedPolicy = PurgePolicy.ManualPurge;
|
|
|
|
const platform = DatasetPlatform.MySql;
|
2017-12-01 18:21:00 -08:00
|
|
|
|
|
|
|
this.set('isEditable', true);
|
|
|
|
this.set('platform', platform);
|
|
|
|
this.set('purgePolicy', selectedPolicy);
|
2018-01-17 10:40:17 -08:00
|
|
|
this.set('supportedPurgePolicies', getSupportedPurgePolicies(platform, platforms));
|
2017-12-01 18:21:00 -08:00
|
|
|
|
2018-01-10 12:06:14 -08:00
|
|
|
this.server.respondWith('GET', '/api/v1/list/platforms', [
|
|
|
|
200,
|
|
|
|
{ 'Content-Type': 'application/json' },
|
|
|
|
JSON.stringify({ status: ApiStatus.OK, platforms })
|
|
|
|
]);
|
|
|
|
|
2018-01-17 10:40:17 -08:00
|
|
|
this.render(
|
|
|
|
hbs`{{purge-policy isEditable=isEditable purgePolicy=purgePolicy platform=platform supportedPurgePolicies=supportedPurgePolicies}}`
|
|
|
|
);
|
2018-01-10 12:06:14 -08:00
|
|
|
this.server.respond();
|
2017-12-01 18:21:00 -08:00
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
document.querySelector(`${policyList} [type=radio][value=${selectedPolicy}]`).checked,
|
|
|
|
`${selectedPolicy} radio is checked`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-01-10 12:06:14 -08:00
|
|
|
test('it focuses the comment element for exempt policy', function(assert) {
|
2017-12-01 18:21:00 -08:00
|
|
|
assert.expect(1);
|
|
|
|
|
|
|
|
const focusEditor = () => {
|
|
|
|
assert.equal(++focusMethodCount, 1, 'focusEditor action is invoked');
|
|
|
|
};
|
|
|
|
let selectedPolicy = exemptPolicy;
|
2018-01-10 12:06:14 -08:00
|
|
|
let platform = DatasetPlatform.MySql;
|
2017-12-01 18:21:00 -08:00
|
|
|
let focusMethodCount = 0;
|
|
|
|
|
|
|
|
this.setProperties({
|
|
|
|
platform,
|
|
|
|
focusEditor,
|
|
|
|
isEditable: true,
|
|
|
|
purgePolicy: selectedPolicy
|
|
|
|
});
|
|
|
|
|
|
|
|
this.render(
|
|
|
|
hbs`{{purge-policy isEditable=isEditable purgePolicy=purgePolicy platform=platform focusEditor=focusEditor}}`
|
|
|
|
);
|
|
|
|
});
|