Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ui/ttl wrap #9632

Merged
merged 4 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions ui/app/components/wrap-ttl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default Component.extend({
onChange: null,
wrapResponse: true,

ttl: null,
ttl: '30m',

wrapTTL: computed('wrapResponse', 'ttl', function() {
const { wrapResponse, ttl } = this.getProperties('wrapResponse', 'ttl');
Expand All @@ -27,30 +27,22 @@ export default Component.extend({

layout: hbs`
<div class="field">
<div class="b-checkbox">
<input
id="wrap-response"
class="styled"
name="wrap-response"
type="checkbox"
checked={{wrapResponse}}
onchange={{action 'changedValue' 'wrapResponse'}}
/>
<label for="wrap-response" class="is-label">
Wrap response
</label>
</div>
{{#if wrapResponse}}
{{ttl-picker data-test-wrap-ttl-picker=true labelText='Wrap TTL' onChange=(action (mut ttl))}}
{{/if}}
{{ttl-picker2
data-test-wrap-ttl-picker=true
label='Wrap response'
helperTextDisabled='Will not wrap response'
helperTextEnabled='Will wrap response with a lease of'
enableTTL=wrapResponse
initialValue=ttl
onChange=(action 'changedValue')
}}
</div>
`,

actions: {
changedValue(key, event) {
const { type, value, checked } = event.target;
const val = type === 'checkbox' ? checked : value;
set(this, key, val);
changedValue(ttlObj) {
set(this, 'wrapResponse', ttlObj.enabled);
set(this, 'ttl', `${ttlObj.seconds}s`);
get(this, 'onChange')(get(this, 'wrapTTL'));
},
},
Expand Down
6 changes: 2 additions & 4 deletions ui/tests/integration/components/transit-key-actions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ module('Integration | Component | transit key actions', function(hooks) {
const response = { keys: { a: 'key' } };
this.set('storeService.keyActionReturnVal', response);
await setupExport.call(this);
await click('#wrap-response');
await triggerEvent('#wrap-response', 'change');
await click('[data-test-toggle-label="Wrap response"]');
await click('button[type="submit"]');
assert.dom('.modal.is-active').exists('Modal opens after export');
assert.deepEqual(
Expand All @@ -295,8 +294,7 @@ module('Integration | Component | transit key actions', function(hooks) {
const response = { keys: { a: 'key' } };
this.set('storeService.keyActionReturnVal', response);
await setupExport.call(this);
await click('#wrap-response');
await triggerEvent('#wrap-response', 'change');
await click('[data-test-toggle-label="Wrap response"]');
await click('#exportVersion');
await triggerEvent('#exportVersion', 'change');
await click('button[type="submit"]');
Expand Down
25 changes: 11 additions & 14 deletions ui/tests/integration/components/wrap-ttl-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click, fillIn, blur, find, triggerEvent } from '@ember/test-helpers';
import { render, click, fillIn, find } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import waitForError from 'vault/tests/helpers/wait-for-error';

Expand All @@ -24,28 +24,25 @@ module('Integration | Component | wrap ttl', function(hooks) {
test('it renders', async function(assert) {
await render(hbs`{{wrap-ttl onChange=(action onChange)}}`);
assert.equal(this.lastOnChangeCall, '30m', 'calls onChange with 30m default on first render');
assert.equal(find('label[for=wrap-response]').textContent.trim(), 'Wrap response');
// await this.pauseTest();
assert.equal(
find('label[for="toggle-Wrapresponse"] .ttl-picker-label').textContent.trim(),
'Wrap response'
);
});

test('it nulls out value when you uncheck wrapResponse', async function(assert) {
await render(hbs`{{wrap-ttl onChange=(action onChange)}}`);
await click('#wrap-response');
await triggerEvent('#wrap-response', 'change');
await click('[data-test-toggle-label="Wrap response"]');
assert.equal(this.lastOnChangeCall, null, 'calls onChange with null');
});

test('it sends value changes to onChange handler', async function(assert) {
await render(hbs`{{wrap-ttl onChange=(action onChange)}}`);

await fillIn('[data-test-wrap-ttl-picker] input', '20');
assert.equal(this.lastOnChangeCall, '20m', 'calls onChange correctly on time input');

// for testing purposes we need to input unit first because it keeps seconds value
await fillIn('[data-test-select="ttl-unit"]', 'h');
await blur('[data-test-select="ttl-unit"]');
assert.equal(this.lastOnChangeCall, '20h', 'calls onChange correctly on unit change');

await fillIn('[data-test-select="ttl-unit"]', 'd');
await blur('[data-test-select="ttl-unit"]');
assert.equal(this.lastOnChangeCall, '480h', 'converts days to hours correctly');
assert.equal(this.lastOnChangeCall, '1800s', 'calls onChange correctly on time input');
await fillIn('[data-test-ttl-value="Wrap response"]', '20');
assert.equal(this.lastOnChangeCall, '72000s', 'calls onChange correctly on unit change');
});
});