Skip to content

Commit

Permalink
UI: Glimmerize BoxRadio and AlertPopup (hashicorp#19571)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiannaquach authored Mar 17, 2023
1 parent 670c952 commit 9a84a8e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 48 deletions.
33 changes: 0 additions & 33 deletions ui/app/components/alert-popup.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<div class="message {{this.type.class}}">
<div class="message {{@type.class}}">
<div class="columns is-mobile is-variable is-1">
<div class="column is-narrow message-icon">
<Icon aria-hidden="true" @name={{this.type.glyph}} />
<Icon aria-hidden="true" @name={{@type.glyph}} />
</div>
<div class="column">
<button type="button" class="close-button" {{on "click" this.close}}>
<button type="button" class="close-button" {{on "click" @close}}>
<Icon @name="x" aria-label="Close" />
</button>
<div class="message-title">
{{this.type.text}}
{{@type.text}}
</div>
{{#if this.message}}
<p class="message-body {{if @isPreformatted 'pre'}}" data-test-flash-message-body="true">{{this.message}}</p>
{{#if @message}}
<p class="message-body {{if @isPreformatted 'pre'}}" data-test-flash-message-body="true">{{@message}}</p>
{{/if}}
</div>
</div>
Expand Down
File renamed without changes.
15 changes: 6 additions & 9 deletions ui/lib/core/addon/components/box-radio.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Component from '@glimmer/component';

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
Expand All @@ -21,13 +23,8 @@
* @param {string} [tooltipMessage=default] - The message that shows in the tooltip if the radio option is disabled
*/

import Component from '@glimmer/component';
import layout from '../templates/components/box-radio';
import { setComponentTemplate } from '@ember/component';

class BoxRadio extends Component {
disabled = false;
tooltipMessage = 'This option is not available to you at this time.';
export default class BoxRadio extends Component {
get tooltipMessage() {
return this.args.tooltipMessage || 'This option is not available to you at this time.';
}
}

export default setComponentTemplate(layout, BoxRadio);
1 change: 1 addition & 0 deletions ui/lib/core/app/components/alert-popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'core/components/alert-popup';
58 changes: 58 additions & 0 deletions ui/tests/integration/components/alert-popup-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'vault/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { click } from '@ember/test-helpers';

module('Integration | Component | alert-popup', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function () {
this.set('message', 'some very important alert');
this.set('type', 'warning');
this.set('close', () => this.set('closed', true));
});

test('it renders the alert popup input', async function (assert) {
await render(hbs`
<AlertPopup @message={{this.message}} @type={{message-types this.type}} @close={{this.close}} />
`);

assert.dom(this.element).hasText('Warning some very important alert');
});

test('it invokes the close action', async function (assert) {
assert.expect(1);

await render(hbs`
<AlertPopup @message={{this.message}} @type={{message-types this.type}} @close={{this.close}} />
`);
await click('.close-button');

assert.true(this.closed);
});

test('it renders the alert popup with different colors based on types', async function (assert) {
await render(hbs`
<AlertPopup @message={{this.message}} @type={{message-types this.type}} @close={{this.close}} />
`);

assert.dom('.message').hasClass('is-highlight');

this.set('type', 'info');

await render(hbs`
<AlertPopup @message={{this.message}} @type={{message-types this.type}} @close={{this.close}} />
`);

assert.dom('.message').hasClass('is-info');

this.set('type', 'danger');

await render(hbs`
<AlertPopup @message={{this.message}} @type={{message-types this.type}} @close={{this.close}} />
`);

assert.dom('.message').hasClass('is-danger');
});
});

0 comments on commit 9a84a8e

Please sign in to comment.