2018-09-25 16:28:26 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2022-03-29 16:25:16 +00:00
|
|
|
import { render, settled } from '@ember/test-helpers';
|
2018-10-17 04:23:29 +00:00
|
|
|
import { resolve } from 'rsvp';
|
|
|
|
import { run } from '@ember/runloop';
|
|
|
|
import Service from '@ember/service';
|
2018-07-13 02:35:58 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
2018-10-17 04:23:29 +00:00
|
|
|
let capabilities;
|
|
|
|
const storeService = Service.extend({
|
|
|
|
queryRecord() {
|
|
|
|
return resolve(capabilities);
|
|
|
|
},
|
|
|
|
});
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Component | secret edit', function (hooks) {
|
2018-09-25 16:28:26 +00:00
|
|
|
setupRenderingTest(hooks);
|
2018-07-13 02:35:58 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(function () {
|
2018-10-17 04:23:29 +00:00
|
|
|
capabilities = null;
|
2018-09-25 16:28:26 +00:00
|
|
|
this.codeMirror = this.owner.lookup('service:code-mirror');
|
2018-10-17 04:23:29 +00:00
|
|
|
run(() => {
|
|
|
|
this.owner.unregister('service:store');
|
|
|
|
this.owner.register('service:store', storeService);
|
|
|
|
});
|
2018-07-13 02:35:58 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it disables JSON toggle in show mode when is an advanced format', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
this.set('mode', 'show');
|
2018-10-17 04:23:29 +00:00
|
|
|
this.set('model', {
|
2018-09-25 16:28:26 +00:00
|
|
|
secretData: {
|
|
|
|
int: 2,
|
|
|
|
null: null,
|
|
|
|
float: 1.234,
|
|
|
|
},
|
|
|
|
});
|
2018-07-13 02:35:58 +00:00
|
|
|
|
2018-10-17 04:23:29 +00:00
|
|
|
await render(hbs`{{secret-edit mode=mode model=model }}`);
|
2020-03-24 18:47:56 +00:00
|
|
|
assert.dom('[data-test-toggle-input="json"]').isDisabled();
|
2018-07-13 02:35:58 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it does JSON toggle in show mode when showing string data', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
this.set('mode', 'show');
|
2018-10-17 04:23:29 +00:00
|
|
|
this.set('model', {
|
2018-09-25 16:28:26 +00:00
|
|
|
secretData: {
|
|
|
|
int: '2',
|
|
|
|
null: 'null',
|
|
|
|
float: '1.234',
|
|
|
|
},
|
|
|
|
});
|
2018-09-05 16:07:39 +00:00
|
|
|
|
2018-10-17 04:23:29 +00:00
|
|
|
await render(hbs`{{secret-edit mode=mode model=model }}`);
|
2020-03-24 18:47:56 +00:00
|
|
|
assert.dom('[data-test-toggle-input="json"]').isNotDisabled();
|
2018-09-05 16:07:39 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it shows an error when creating and data is not an object', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
this.set('mode', 'create');
|
2018-10-17 04:23:29 +00:00
|
|
|
this.set('model', {
|
2022-03-29 16:25:16 +00:00
|
|
|
secretData: null,
|
2018-09-25 16:28:26 +00:00
|
|
|
});
|
2018-09-05 16:07:39 +00:00
|
|
|
|
2018-10-17 04:23:29 +00:00
|
|
|
await render(hbs`{{secret-edit mode=mode model=model preferAdvancedEdit=true }}`);
|
2022-03-29 16:25:16 +00:00
|
|
|
|
|
|
|
let instance = document.querySelector('.CodeMirror').CodeMirror;
|
2018-09-25 16:28:26 +00:00
|
|
|
instance.setValue(JSON.stringify([{ foo: 'bar' }]));
|
|
|
|
await settled();
|
|
|
|
assert.dom('[data-test-error]').includesText('Vault expects data to be formatted as an JSON object');
|
2018-09-05 16:07:39 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it allows saving when the model isError', async function (assert) {
|
2019-01-10 16:37:25 +00:00
|
|
|
this.set('mode', 'create');
|
|
|
|
this.set('model', {
|
|
|
|
isError: true,
|
|
|
|
secretData: {
|
|
|
|
int: '2',
|
|
|
|
null: 'null',
|
|
|
|
float: '1.234',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await render(hbs`<SecretEdit @mode={{mode}} @model={{model}} />`);
|
|
|
|
assert.dom('[data-test-secret-save]').isNotDisabled();
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it shows an error when editing and the data is not an object', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
this.set('mode', 'edit');
|
2018-10-17 04:23:29 +00:00
|
|
|
capabilities = {
|
2018-09-25 16:28:26 +00:00
|
|
|
canUpdate: true,
|
2018-10-17 04:23:29 +00:00
|
|
|
};
|
|
|
|
this.set('model', {
|
2018-09-25 16:28:26 +00:00
|
|
|
secretData: {
|
|
|
|
int: '2',
|
|
|
|
null: 'null',
|
|
|
|
float: '1.234',
|
|
|
|
},
|
2021-09-03 17:08:26 +00:00
|
|
|
canReadSecretData: true,
|
2018-09-25 16:28:26 +00:00
|
|
|
});
|
|
|
|
|
2018-10-17 04:23:29 +00:00
|
|
|
await render(hbs`{{secret-edit mode=mode model=model preferAdvancedEdit=true }}`);
|
2021-12-17 03:44:29 +00:00
|
|
|
|
2022-03-29 16:25:16 +00:00
|
|
|
let instance = document.querySelector('.CodeMirror').CodeMirror;
|
2018-09-25 16:28:26 +00:00
|
|
|
instance.setValue(JSON.stringify([{ foo: 'bar' }]));
|
|
|
|
await settled();
|
|
|
|
assert.dom('[data-test-error]').includesText('Vault expects data to be formatted as an JSON object');
|
|
|
|
});
|
2018-09-05 16:07:39 +00:00
|
|
|
});
|