`[data-test-ttl-toggle="${label}"]`,
+ label: '[data-test-ttl-form-label]',
+ subtext: '[data-test-ttl-form-subtext]',
+ tooltipTrigger: `[data-test-tooltip-trigger]`,
+ ttlValue: '[data-test-ttl-value]',
+ ttlUnit: '[data-test-select="ttl-unit"]',
+ valueInputByLabel: (label) => `[data-test-ttl-value="${label}"]`,
+ unitInputByLabel: (label) => `[data-test-ttl-unit="${label}"] [data-test-select="ttl-unit"]`,
+};
+
+export default selectors;
diff --git a/ui/tests/integration/components/mfa/method-form-test.js b/ui/tests/integration/components/mfa/method-form-test.js
index 160f9c816..0ffb4823e 100644
--- a/ui/tests/integration/components/mfa/method-form-test.js
+++ b/ui/tests/integration/components/mfa/method-form-test.js
@@ -63,7 +63,7 @@ module('Integration | Component | mfa-method-form', function (hooks) {
assert.expect(3);
this.model.issuer = 'Vault';
- this.model.period = '30';
+ this.model.period = '30s';
this.model.algorithm = 'SHA512';
await render(hbs`
diff --git a/ui/tests/integration/components/pki/config-pki-test.js b/ui/tests/integration/components/pki/config-pki-test.js
index 1ed31298c..7d0e9adc4 100644
--- a/ui/tests/integration/components/pki/config-pki-test.js
+++ b/ui/tests/integration/components/pki/config-pki-test.js
@@ -54,22 +54,25 @@ module('Integration | Component | config pki', function (hooks) {
'renders form subtext'
);
assert
- .dom('[data-test-toggle-label]')
- .hasText('CRL building enabled The CRL will expire after', 'renders enabled field title and subtext');
+ .dom('[data-test-ttl-form-label="CRL building enabled"]')
+ .hasText('CRL building enabled', 'renders enabled field title');
+ assert
+ .dom('[data-test-ttl-form-subtext]')
+ .hasText('The CRL will expire after', 'renders enabled field subtext');
assert.dom('[data-test-input="expiry"] input').isChecked('defaults to enabling CRL build');
assert.dom('[data-test-ttl-value="CRL building enabled"]').hasValue('3', 'default value is 3 (72h)');
assert.dom('[data-test-select="ttl-unit"]').hasValue('d', 'default unit value is days');
await click('[data-test-input="expiry"] input');
assert
- .dom('[data-test-toggle-label]')
- .hasText('CRL building disabled The CRL will not be built.', 'renders disabled text when toggled off');
+ .dom('[data-test-ttl-form-subtext]')
+ .hasText('The CRL will not be built.', 'renders disabled text when toggled off');
// assert 'disable' attr on pki-config model updates with toggle
assert.true(this.config.disable, 'when toggled off, sets CRL config to disable=true');
await click('[data-test-input="expiry"] input');
assert
- .dom('[data-test-toggle-label]')
- .hasText('CRL building enabled The CRL will expire after', 'toggles back to enabled text');
+ .dom('[data-test-ttl-form-subtext]')
+ .hasText('The CRL will expire after', 'toggles back to enabled text');
assert.false(this.config.disable, 'CRL config toggles back to disable=false');
});
diff --git a/ui/tests/integration/components/pki/radio-select-ttl-or-string-test.js b/ui/tests/integration/components/pki/radio-select-ttl-or-string-test.js
index 0d09bee4b..a0e5a9bf7 100644
--- a/ui/tests/integration/components/pki/radio-select-ttl-or-string-test.js
+++ b/ui/tests/integration/components/pki/radio-select-ttl-or-string-test.js
@@ -33,14 +33,13 @@ module('Integration | Component | radio-select-ttl-or-string', function (hooks)
`,
{ owner: this.engine }
);
- assert.dom('[data-test-input="ttl"]').exists('shows the TTL component');
- const inputValue = document.querySelector('[data-test-ttl-value="TTL"]').value;
- assert.strictEqual(inputValue, '', 'default TTL is empty');
+ assert.dom('[data-test-ttl-inputs]').exists('shows the TTL component');
+ assert.dom('[data-test-ttl-value]').hasValue('', 'default TTL is empty');
assert.dom('[data-test-radio-button="ttl"]').isChecked('ttl is selected by default');
});
test('it should set the model properties ttl or notAfter based on the radio button selections', async function (assert) {
- assert.expect(8);
+ assert.expect(7);
await render(
hbs`
@@ -68,23 +67,21 @@ module('Integration | Component | radio-select-ttl-or-string', function (hooks)
'sets the model property notAfter when this value is selected and filled in.'
);
- await fillIn('[data-test-ttl-value="TTL"]', ttlDate);
- assert.strictEqual(this.model.ttl, '', 'No ttl is set because the radio button was not selected.');
-
await click('[data-test-radio-button="ttl"]');
assert.strictEqual(
this.model.notAfter,
'',
'The notAfter is cleared on the model because the radio button was selected.'
);
+ await fillIn('[data-test-ttl-value="TTL"]', ttlDate);
assert.strictEqual(
this.model.ttl,
- ttlDate,
+ '1s',
'The ttl is now saved on the model because the radio button was selected.'
);
await click('[data-test-radio-button="not_after"]');
- assert.strictEqual(this.model.ttl, '', 'Both ttl and notAfter are cleared.');
- assert.strictEqual(this.model.notAfter, '', 'Both ttl and notAfter are cleared.');
+ assert.strictEqual(this.model.ttl, '', 'TTL is cleared after radio select.');
+ assert.strictEqual(this.model.notAfter, '', 'notAfter is cleared after radio select.');
});
});
diff --git a/ui/tests/integration/components/ttl-form-test.js b/ui/tests/integration/components/ttl-form-test.js
deleted file mode 100644
index 91bd9a7a6..000000000
--- a/ui/tests/integration/components/ttl-form-test.js
+++ /dev/null
@@ -1,49 +0,0 @@
-import { module, test } from 'qunit';
-import { setupRenderingTest } from 'ember-qunit';
-import { render, fillIn } from '@ember/test-helpers';
-import hbs from 'htmlbars-inline-precompile';
-import sinon from 'sinon';
-
-module('Integration | Component | ttl-form', function (hooks) {
- setupRenderingTest(hooks);
-
- hooks.beforeEach(function () {
- this.changeSpy = sinon.spy();
- this.set('onChange', this.changeSpy);
- });
-
- test('it shows no initial time and initial unit of s when not time or unit passed in', async function (assert) {
- await render(hbs``);
- assert.dom('[data-test-ttlform-value]').hasValue('');
- assert.dom('[data-test-select="ttl-unit"]').hasValue('s');
- });
-
- test('it calls the change fn with the correct values', async function (assert) {
- await render(hbs``);
-
- assert.dom('[data-test-select="ttl-unit"]').hasValue('m', 'unit value initially shows m (minutes)');
- await fillIn('[data-test-ttlform-value]', '10');
- await assert.ok(this.changeSpy.calledOnce, 'it calls the passed onChange');
- assert.ok(
- this.changeSpy.calledWith({
- seconds: 600,
- timeString: '10m',
- }),
- 'Passes the default values back to onChange'
- );
- });
-
- test('it correctly shows initial unit', async function (assert) {
- const changeSpy = sinon.spy();
- this.set('onChange', changeSpy);
- await render(hbs`
-
- `);
-
- assert.dom('[data-test-select="ttl-unit"]').hasValue('h', 'unit value initially shows as h (hours)');
- });
-});
diff --git a/ui/tests/integration/components/ttl-picker-test.js b/ui/tests/integration/components/ttl-picker-test.js
index 3ea88cfcb..ad3adb3ec 100644
--- a/ui/tests/integration/components/ttl-picker-test.js
+++ b/ui/tests/integration/components/ttl-picker-test.js
@@ -1,30 +1,390 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
-import { render, fillIn } from '@ember/test-helpers';
-import hbs from 'htmlbars-inline-precompile';
+import { render, click, fillIn } from '@ember/test-helpers';
import sinon from 'sinon';
+import hbs from 'htmlbars-inline-precompile';
+import selectors from 'vault/tests/helpers/components/ttl-picker';
-module('Integration | Component | ttl picker', function (hooks) {
+module('Integration | Component | ttl-picker', function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
- this.changeSpy = sinon.spy();
- this.set('onChange', this.changeSpy);
+ this.set('onChange', sinon.spy());
+ this.set('label', 'Foobar');
});
- test('it renders error on non-number input', async function (assert) {
- await render(hbs``);
+ module('without toggle', function (hooks) {
+ hooks.beforeEach(function () {
+ this.set('hideToggle', true);
+ });
- const callCount = this.changeSpy.callCount;
- await fillIn('[data-test-ttl-value]', 'foo');
- assert.strictEqual(this.changeSpy.callCount, callCount, "it didn't call onChange again");
- assert.dom('[data-test-ttl-error]').includesText('Error', 'renders the error box');
- await fillIn('[data-test-ttl-value]', '33');
- assert.dom('[data-test-ttl-error]').doesNotExist('removes the error box');
+ test('it shows correct time and value when no initialValue set', async function (assert) {
+ await render(hbs``);
+ assert.dom(selectors.ttlFormGroup).exists('TTL Form fields exist');
+ assert.dom(selectors.ttlValue).hasValue('');
+ assert.dom(selectors.ttlUnit).hasValue('s');
+ });
+
+ test('it calls the change fn with the correct values', async function (assert) {
+ const changeSpy = sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs`
+
+ `);
+ assert.dom(selectors.ttlUnit).hasValue('m', 'unit value shows m (minutes)');
+ await fillIn(selectors.ttlValue, '10');
+ await assert.ok(changeSpy.calledOnce, 'it calls the passed onChange');
+ assert.ok(
+ changeSpy.calledWithExactly({
+ enabled: true,
+ seconds: 600,
+ timeString: '10m',
+ goSafeTimeString: '10m',
+ }),
+ 'Passes the values back to onChange'
+ );
+ });
+
+ test('it correctly shows initial time and unit', async function (assert) {
+ await render(hbs`
+
+ `);
+
+ assert.dom(selectors.ttlUnit).hasValue('h', 'unit value initially shows as h (hours)');
+ assert.dom(selectors.ttlValue).hasValue('3', 'time value initially shows as 3');
+ });
+
+ test('it fails gracefully when initialValue is not parseable', async function (assert) {
+ const changeSpy = sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs`
+
+ `);
+
+ assert.dom(selectors.ttlValue).hasValue('', 'time value initially shows as empty');
+ assert.dom(selectors.ttlUnit).hasValue('s', 'unit value initially shows as s (seconds)');
+ assert.ok(changeSpy.notCalled, 'onChange is not called on init');
+ });
+
+ test('it recalculates time when unit is changed', async function (assert) {
+ const changeSpy = sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs`
+
+ `);
+
+ assert.dom(selectors.ttlUnit).hasValue('h', 'unit value initially shows as h (hours)');
+ assert.dom(selectors.ttlValue).hasValue('1', 'time value initially shows as 1');
+ await fillIn(selectors.ttlUnit, 'm');
+ assert.dom(selectors.ttlUnit).hasValue('m', 'unit value changed to m (minutes)');
+ assert.dom(selectors.ttlValue).hasValue('60', 'time value recalculates to fit unit');
+ assert.ok(
+ changeSpy.calledWithExactly({
+ enabled: true,
+ seconds: 3600,
+ timeString: '60m',
+ goSafeTimeString: '60m',
+ }),
+ 'Passes the values back to onChange'
+ );
+ });
+
+ test('it skips recalculating time when unit is changed if time is not whole number', async function (assert) {
+ const changeSpy = sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs`
+
+ `);
+
+ assert.dom(selectors.ttlUnit).hasValue('s', 'unit value starts as s (seconds)');
+ assert.dom(selectors.ttlValue).hasValue('30', 'time value starts as 30');
+ await fillIn(selectors.ttlUnit, 'm');
+ assert.dom(selectors.ttlUnit).hasValue('m', 'unit value changed to m (minutes)');
+ assert.dom(selectors.ttlValue).hasValue('30', 'time value is still 30');
+ assert.ok(
+ changeSpy.calledWithExactly({
+ enabled: true,
+ seconds: 1800,
+ timeString: '30m',
+ goSafeTimeString: '30m',
+ }),
+ 'Passes the values back to onChange'
+ );
+ });
+
+ test('it calls onChange on init when changeOnInit is true', async function (assert) {
+ const changeSpy = sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs`
+
+ `);
+
+ assert.ok(changeSpy.calledOnce, 'it calls the passed onChange when rendered');
+ assert.ok(
+ changeSpy.calledWithExactly({
+ enabled: true,
+ seconds: 600,
+ timeString: '10m',
+ goSafeTimeString: '10m',
+ }),
+ 'Passes the values back to onChange'
+ );
+ });
+
+ test('it shows a label when passed', async function (assert) {
+ this.set('label', 'My Label');
+ await render(hbs`
+
+ `);
+
+ assert.dom('[data-test-ttl-form-label]').hasText('My Label', 'Renders label correctly');
+ assert.dom('[data-test-ttl-form-subtext]').doesNotExist('Subtext not rendered');
+ assert.dom('[data-test-tooltip-trigger]').doesNotExist('Description tooltip not rendered');
+ });
+
+ test('it shows subtext and description when passed', async function (assert) {
+ this.set('label', 'My Label');
+ await render(hbs`
+
+ `);
+
+ assert.dom('[data-test-ttl-form-label]').hasText('My Label', 'Renders label correctly');
+ assert.dom('[data-test-ttl-form-subtext]').hasText('Subtext', 'Renders subtext when present');
+ assert
+ .dom('[data-test-tooltip-trigger]')
+ .exists({ count: 1 }, 'Description tooltip icon shows when description present');
+ });
+
+ test('it yields in place of label if block is present', async function (assert) {
+ this.set('label', 'My Label');
+ await render(hbs`
+
+
+
+ `);
+
+ assert.dom('[data-test-custom]').hasText('Different Label', 'custom block is rendered');
+ assert.dom('[data-test-ttl-form-label]').doesNotExist('Label not rendered');
+ });
});
- test('it shows 30s for invalid duration initialValue input', async function (assert) {
- await render(hbs``);
- assert.dom('[data-test-ttl-value]').hasValue('30', 'sets 30 as the default');
+ module('with toggle', function () {
+ test('it has toggle off by default', async function (assert) {
+ await render(hbs`
+
+ `);
+ assert.dom(selectors.toggle).isNotChecked('Toggle is unchecked by default');
+ assert.dom(selectors.ttlFormGroup).doesNotExist('TTL Form is not rendered');
+ });
+
+ test('it shows time and unit inputs when initialEnabled', async function (assert) {
+ const changeSpy = sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs`
+
+ `);
+ assert.dom(selectors.toggle).isChecked('Toggle is checked when initialEnabled is true');
+ assert.dom(selectors.ttlFormGroup).exists('TTL Form is rendered');
+ assert.ok(changeSpy.notCalled, 'onChange not called because initialValue not parsed');
+ });
+
+ test('it sets initial value to initialValue', async function (assert) {
+ await render(hbs`
+
+ `);
+ assert.dom(selectors.ttlValue).hasValue('2', 'time value is 2');
+ assert.dom(selectors.ttlUnit).hasValue('h', 'unit is hours');
+ assert.ok(
+ this.onChange.notCalled,
+ 'it does not call onChange after render when changeOnInit is not set'
+ );
+ });
+
+ test('it passes the appropriate data to onChange when toggled on', async function (assert) {
+ const changeSpy = sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs`
+
+ `);
+ await click(selectors.toggle);
+ assert.ok(changeSpy.calledOnce, 'it calls the passed onChange');
+ assert.ok(
+ changeSpy.calledWith({
+ enabled: true,
+ seconds: 600,
+ timeString: '10m',
+ goSafeTimeString: '10m',
+ }),
+ 'Passes the values back to onChange'
+ );
+ });
+
+ test('inputs reflect initial value when toggled on', async function (assert) {
+ await render(hbs`
+
+ `);
+ assert.dom(selectors.toggle).isNotChecked('Toggle is off');
+ assert.dom(selectors.ttlFormGroup).doesNotExist('TTL Form not shown on mount');
+ await click(selectors.toggle);
+ assert.dom(selectors.ttlValue).hasValue('100', 'time after toggle is 100');
+ assert.dom(selectors.ttlUnit).hasValue('m', 'Unit is minutes after toggle');
+ });
+
+ test('it is enabled on init if initialEnabled is true', async function (assert) {
+ await render(hbs`
+
+ `);
+ assert.dom(selectors.toggle).isChecked('Toggle is on');
+ assert.dom(selectors.ttlFormGroup).exists();
+ assert.dom(selectors.ttlValue).hasValue('100', 'time is shown on mount');
+ assert.dom(selectors.ttlUnit).hasValue('m', 'Unit is shown on mount');
+ await click(selectors.toggle);
+ assert.dom(selectors.toggle).isNotChecked('Toggle is off');
+ assert.dom(selectors.ttlFormGroup).doesNotExist('TTL Form no longer shows after toggle');
+ });
+
+ test('it is enabled on init if initialEnabled evals to truthy', async function (assert) {
+ await render(hbs`
+
+ `);
+ assert.dom(selectors.toggle).isChecked('Toggle is enabled');
+ assert.dom(selectors.ttlValue).hasValue('100', 'time value is shown on mount');
+ assert.dom(selectors.ttlUnit).hasValue('m', 'Unit matches what is passed in');
+ });
+
+ test('it converts days to go safe time', async function (assert) {
+ await render(hbs`
+
+ `);
+ await click(selectors.toggle);
+ assert.ok(this.onChange.calledOnce, 'it calls the passed onChange');
+ assert.ok(
+ this.onChange.calledWith({
+ enabled: true,
+ seconds: 172800,
+ timeString: '2d',
+ goSafeTimeString: '48h',
+ }),
+ 'Converts day unit to go safe time'
+ );
+ });
+
+ test('it converts to the largest round unit on init', async function (assert) {
+ await render(hbs`
+
+ `);
+ assert.dom(selectors.ttlValue).hasValue('1000', 'time value is converted');
+ assert.dom(selectors.ttlUnit).hasValue('m', 'unit value is m (minutes)');
+ });
+
+ test('it converts to the largest round unit on init when no unit provided', async function (assert) {
+ await render(hbs`
+
+ `);
+ assert.dom(selectors.ttlValue).hasValue('1', 'time value is converted');
+ assert.dom(selectors.ttlUnit).hasValue('d', 'unit value is d (days)');
+ });
});
});
diff --git a/ui/tests/integration/components/ttl-picker2-test.js b/ui/tests/integration/components/ttl-picker2-test.js
deleted file mode 100644
index 822f2ccc2..000000000
--- a/ui/tests/integration/components/ttl-picker2-test.js
+++ /dev/null
@@ -1,248 +0,0 @@
-import { module, test } from 'qunit';
-import { setupRenderingTest } from 'ember-qunit';
-import { render, click, fillIn } from '@ember/test-helpers';
-import sinon from 'sinon';
-import hbs from 'htmlbars-inline-precompile';
-
-module('Integration | Component | ttl-picker2', function (hooks) {
- setupRenderingTest(hooks);
-
- hooks.beforeEach(function () {
- this.set('onChange', sinon.spy());
- });
-
- test('it renders time and unit inputs when TTL enabled', async function (assert) {
- await render(hbs`
-
- `);
- assert.dom('[data-test-ttl-value]').exists('TTL Picker time input exists');
- assert.dom('[data-test-ttl-unit]').exists('TTL Picker unit select exists');
- });
-
- test('it does not show time and unit inputs when TTL disabled', async function (assert) {
- await render(hbs`
-
- `);
- assert.dom('[data-test-ttl-value]').doesNotExist('TTL Picker time input exists');
- assert.dom('[data-test-ttl-unit]').doesNotExist('TTL Picker unit select exists');
- });
-
- test('it passes the appropriate data to onChange when toggled on', async function (assert) {
- await render(hbs`
-
- `);
- await click('[data-test-toggle-input="clicktest"]');
- assert.ok(this.onChange.calledOnce, 'it calls the passed onChange');
- assert.ok(
- this.onChange.calledWith({
- enabled: true,
- seconds: 600,
- timeString: '10m',
- goSafeTimeString: '10m',
- }),
- 'Passes the default values back to onChange'
- );
- });
-
- test('it keeps seconds value when unit is changed', async function (assert) {
- await render(hbs`
-
- `);
- await click('[data-test-toggle-input="clicktest"]');
- assert.ok(this.onChange.calledOnce, 'it calls the passed onChange');
- assert.ok(
- this.onChange.calledWith({
- enabled: true,
- seconds: 360,
- timeString: '360s',
- goSafeTimeString: '360s',
- }),
- 'Changes enabled to true on click'
- );
- await fillIn('[data-test-select="ttl-unit"]', 'm');
- assert.ok(
- this.onChange.calledWith({
- enabled: true,
- seconds: 360,
- timeString: '6m',
- goSafeTimeString: '6m',
- }),
- 'Units and time update without changing seconds value'
- );
- assert.dom('[data-test-ttl-value]').hasValue('6', 'time value shows as 6');
- assert.dom('[data-test-select="ttl-unit"]').hasValue('m', 'unit value shows as m (minutes)');
- });
-
- test('it recalculates seconds when unit is changed and recalculateSeconds is on', async function (assert) {
- await render(hbs`
-
- `);
- await fillIn('[data-test-select="ttl-unit"]', 'm');
- assert.ok(
- this.onChange.calledWith({
- enabled: true,
- seconds: 7200,
- timeString: '120m',
- goSafeTimeString: '120m',
- }),
- 'Seconds value is recalculated based on time and unit'
- );
- });
-
- test('it sets default value to time and unit passed', async function (assert) {
- await render(hbs`
-
- `);
- assert.dom('[data-test-ttl-value]').hasValue('2', 'time value is 2');
- assert.dom('[data-test-select="ttl-unit"]').hasValue('h', 'unit is hours');
- assert.ok(this.onChange.notCalled, 'it does not call onChange after render when changeOnInit is not set');
- });
-
- test('it is disabled on init if initialEnabled is false', async function (assert) {
- await render(hbs`
-
- `);
- assert.dom('[data-test-ttl-value]').doesNotExist('Value is not shown on mount');
- assert.dom('[data-test-ttl-unit]').doesNotExist('Unit is not shown on mount');
- await click('[data-test-toggle-input="inittest"]');
- assert.dom('[data-test-ttl-value]').hasValue('100', 'time after toggle is 100');
- assert.dom('[data-test-select="ttl-unit"]').hasValue('m', 'Unit is minutes after toggle');
- });
-
- test('it is enabled on init if initialEnabled is true', async function (assert) {
- await render(hbs`
-
- `);
- assert.dom('[data-test-ttl-value]').hasValue('100', 'time is shown on mount');
- assert.dom('[data-test-select="ttl-unit"]').hasValue('m', 'Unit is shown on mount');
- await click('[data-test-toggle-input="inittest"]');
- assert.dom('[data-test-ttl-value]').doesNotExist('Value no longer shows after toggle');
- assert.dom('[data-test-ttl-unit]').doesNotExist('Unit no longer shows after toggle');
- });
-
- test('it is enabled on init if initialEnabled evals to truthy', async function (assert) {
- await render(hbs`
-
- `);
- assert.dom('[data-test-ttl-value]').hasValue('100', 'time value is shown on mount');
- assert.dom('[data-test-ttl-unit]').exists('Unit is shown on mount');
- assert.dom('[data-test-select="ttl-unit"]').hasValue('m', 'Unit matches what is passed in');
- });
-
- test('it calls onChange', async function (assert) {
- await render(hbs`
-
- `);
- await click('[data-test-toggle-input="clicktest"]');
- assert.ok(this.onChange.calledOnce, 'it calls the passed onChange');
- assert.ok(
- this.onChange.calledWith({
- enabled: true,
- seconds: 172800,
- timeString: '2d',
- goSafeTimeString: '48h',
- }),
- 'Converts day unit to go safe time'
- );
- });
-
- test('it calls onChange on init when rendered if changeOnInit is true', async function (assert) {
- await render(hbs`
-
- `);
- assert.ok(
- this.onChange.calledWith({
- enabled: true,
- seconds: 6000,
- timeString: '100m',
- goSafeTimeString: '100m',
- }),
- 'Seconds value is recalculated based on time and unit'
- );
- assert.ok(this.onChange.calledOnce, 'it calls the passed onChange after render');
- });
-
- test('it converts to the largest round unit on init', async function (assert) {
- await render(hbs`
-
- `);
- assert.dom('[data-test-ttl-value]').hasValue('1000', 'time value is converted');
- assert.dom('[data-test-select="ttl-unit"]').hasValue('m', 'unit value is m (minutes)');
- });
-
- test('it converts to the largest round unit on init when no unit provided', async function (assert) {
- await render(hbs`
-
- `);
- assert.dom('[data-test-ttl-value]').hasValue('1', 'time value is converted');
- assert.dom('[data-test-select="ttl-unit"]').hasValue('d', 'unit value is d (days)');
- });
-});
diff --git a/ui/tests/integration/components/wrap-ttl-test.js b/ui/tests/integration/components/wrap-ttl-test.js
index 6bcb6dfd2..20bc4700d 100644
--- a/ui/tests/integration/components/wrap-ttl-test.js
+++ b/ui/tests/integration/components/wrap-ttl-test.js
@@ -1,4 +1,5 @@
import { module, test } from 'qunit';
+import Sinon from 'sinon';
import { setupRenderingTest } from 'ember-qunit';
import { render, click, fillIn } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
@@ -7,38 +8,37 @@ import waitForError from 'vault/tests/helpers/wait-for-error';
module('Integration | Component | wrap ttl', function (hooks) {
setupRenderingTest(hooks);
- hooks.beforeEach(function () {
- this.lastOnChangeCall = null;
- this.set('onChange', (val) => {
- this.lastOnChangeCall = val;
- });
- });
-
test('it requires `onChange`', async function (assert) {
const promise = waitForError();
- render(hbs`{{wrap-ttl}}`);
+ render(hbs``);
const err = await promise;
assert.ok(err.message.includes('`onChange` handler is a required attr in'), 'asserts without onChange');
});
test('it renders', async function (assert) {
- await render(hbs`{{wrap-ttl onChange=(action this.onChange)}}`);
- assert.strictEqual(this.lastOnChangeCall, '30m', 'calls onChange with 30m default on first render');
- assert.dom('label[for="toggle-Wrapresponse"] .ttl-picker-label').hasText('Wrap response');
+ const changeSpy = Sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs``);
+ assert.ok(changeSpy.calledWithExactly('30m'), 'calls onChange with 30m default on render');
+ assert.dom('[data-test-ttl-form-label]').hasText('Wrap response');
});
test('it nulls out value when you uncheck wrapResponse', async function (assert) {
- await render(hbs`{{wrap-ttl onChange=(action this.onChange)}}`);
- await click('[data-test-toggle-label="Wrap response"]');
- assert.strictEqual(this.lastOnChangeCall, null, 'calls onChange with null');
+ const changeSpy = Sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs``);
+ await click('[data-test-ttl-form-label]');
+ assert.ok(changeSpy.calledWithExactly(null), 'calls onChange with null');
});
test('it sends value changes to onChange handler', async function (assert) {
- await render(hbs`{{wrap-ttl onChange=(action this.onChange)}}`);
+ const changeSpy = Sinon.spy();
+ this.set('onChange', changeSpy);
+ await render(hbs``);
// for testing purposes we need to input unit first because it keeps seconds value
await fillIn('[data-test-select="ttl-unit"]', 'h');
- assert.strictEqual(this.lastOnChangeCall, '1800s', 'calls onChange correctly on time input');
- await fillIn('[data-test-ttl-value="Wrap response"]', '20');
- assert.strictEqual(this.lastOnChangeCall, '72000s', 'calls onChange correctly on unit change');
+ assert.ok(changeSpy.calledWithExactly('30h'), 'calls onChange correctly on time input');
+ await fillIn('[data-test-ttl-value]', '20');
+ assert.ok(changeSpy.calledWithExactly('20h'), 'calls onChange correctly on unit change');
});
});