From 1bd057bb4c39d8911f83054e1584336eaab8a2ef Mon Sep 17 00:00:00 2001 From: Devon Anderson Date: Tue, 10 Jan 2023 12:56:52 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20desktop=20display=20?= =?UTF-8?q?of=20complex=20nested=20secrets=20(#1551)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 desktop display of complex nested secrets A quick solution for displaying JSON secret objects in connection modal. ✅ Closes: ICU-7409 * refactor: 💡 refactor hidden-secret.js and test Guard against null for in `typeof` return. ✅ Closes: ICU-7409 * Update ui/desktop/app/styles/app.scss Co-authored-by: Cameron Perera * refactor: 💡 test Changed test to check for secret output after clicking on reveal * refactor: 💡 fix style for hidden-secret and test Refactor hidden-secret span styling to have content centered and refactored testing for assert.dom instead of find Co-authored-by: Cameron Perera --- .../app/components/hidden-secret/index.hbs | 4 +- .../app/components/hidden-secret/index.js | 8 ++++ ui/desktop/app/styles/app.scss | 10 +++++ .../components/hidden-secret-test.js | 45 ++++++++++++++----- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/ui/desktop/app/components/hidden-secret/index.hbs b/ui/desktop/app/components/hidden-secret/index.hbs index 67d6baae8..a2159cea8 100644 --- a/ui/desktop/app/components/hidden-secret/index.hbs +++ b/ui/desktop/app/components/hidden-secret/index.hbs @@ -11,12 +11,12 @@ {{t 'actions.toggle-secret'}} {{#if this.isHidden}} - {{@secret}} +
{{this.displaySecretValue}}
{{else}} {{this.textMask}} {{/if}} diff --git a/ui/desktop/app/components/hidden-secret/index.js b/ui/desktop/app/components/hidden-secret/index.js index 2541c81fb..5b991aa6b 100644 --- a/ui/desktop/app/components/hidden-secret/index.js +++ b/ui/desktop/app/components/hidden-secret/index.js @@ -7,6 +7,14 @@ export default class HiddenSecretComponent extends Component { @tracked isHidden = false; + get displaySecretValue() { + if (typeof this.args.secret === 'object' && this.args.secret !== null) { + return JSON.stringify(this.args.secret, null, 2); + } else { + return this.args.secret; + } + } + @action toggleSecretVisibility() { this.isHidden = !this.isHidden; diff --git a/ui/desktop/app/styles/app.scss b/ui/desktop/app/styles/app.scss index 405853544..812f9cff5 100644 --- a/ui/desktop/app/styles/app.scss +++ b/ui/desktop/app/styles/app.scss @@ -467,6 +467,16 @@ $chevron-down: url("data:image/svg+xml;utf-8, + `); + } test('it renders with a secret', async function (assert) { - assert.expect(2); - await render(hbs` - - `); + assert.expect(1); + await renderComponent(); + assert + .dom('.hidden-secret > span > span') + .hasText('â–  â–  â–  â–  â–  â–  â–  â–  â–  â–  â–  â– '); + }); - assert.ok(find('.hidden-secret')); - assert.strictEqual( - find('.hidden-secret > span > span').textContent.trim(), - 'â–  â–  â–  â–  â–  â–  â–  â–  â–  â–  â–  â– ' - ); + test('it reveals secret when button is clicked', async function (assert) { + assert.expect(1); + await renderComponent(); + await click('.hidden-secret > button'); + assert.dom('.hidden-secret > span > span').hasText(this.secret); }); });