chore: 🤖 Add model check for linkbutton rose component
Anchor element cannot be passed in an invalid or empty model when a route is defined. Add check for model existence when generating linkbutton html.
This commit is contained in:
6 files changed
+98
-32
No files matched your search
@@ -3,6 +3,9 @@ import layout from '../../templates/components/rose/link-button';
|
||||
|
||||
/**
|
||||
* An achor element based on `rose-button` component styles
|
||||
* An empty model cannot be passed in to `link-to` component when a route
|
||||
* is defined. Thus, `link-button` body content is separated to avoid
|
||||
* duplication when checked for model existence.
|
||||
*
|
||||
* @example
|
||||
* <Rose::LinkButton @submit={{true}} @style="primary">Save</Rose::LinkButton>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import Component from '@ember/component';
|
||||
import layout from '../../../templates/components/rose/link-button/body';
|
||||
|
||||
export default Component.extend({
|
||||
layout,
|
||||
tagName: '',
|
||||
});
|
||||
@@ -1,33 +1,22 @@
|
||||
<LinkTo
|
||||
...attributes
|
||||
@route={{@route}}
|
||||
class="rose-link-button {{if @style (concat "rose-button-" @style)}} {{if @iconLeft "has-icon-left"}} {{if @iconRight "has-icon-right"}} {{if @iconOnly "has-icon-only"}}"
|
||||
>
|
||||
|
||||
<span class="rose-button-wrapper">
|
||||
{{#if @iconLeft}}
|
||||
<Rose::Icon
|
||||
@name={{@iconLeft}}
|
||||
@size="medium"
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
<span class="rose-button-body">
|
||||
{{#if @model}}
|
||||
<LinkTo
|
||||
...attributes
|
||||
@route={{if @route @route "index"}}
|
||||
@model={{@model}}
|
||||
class="rose-link-button {{if @style (concat "rose-button-" @style)}} {{if @iconLeft "has-icon-left"}} {{if @iconRight "has-icon-right"}} {{if @iconOnly "has-icon-only"}}"
|
||||
>
|
||||
<Rose::LinkButton::Body @iconOnly={{@iconOnly}} @iconLeft={{@iconLeft}} @iconRight={{@iconRight}}>
|
||||
{{yield}}
|
||||
</span>
|
||||
|
||||
{{#if @iconOnly}}
|
||||
<Rose::Icon
|
||||
@name={{@iconOnly}}
|
||||
@size="medium"
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
{{#if @iconRight}}
|
||||
<Rose::Icon
|
||||
@name={{@iconRight}}
|
||||
@size="medium"
|
||||
/>
|
||||
{{/if}}
|
||||
</span>
|
||||
</LinkTo>
|
||||
</Rose::LinkButton::Body>
|
||||
</LinkTo>
|
||||
{{else}}
|
||||
<LinkTo
|
||||
...attributes
|
||||
@route={{if @route @route "index"}}
|
||||
class="rose-link-button {{if @style (concat "rose-button-" @style)}} {{if @iconLeft "has-icon-left"}} {{if @iconRight "has-icon-right"}} {{if @iconOnly "has-icon-only"}}"
|
||||
>
|
||||
<Rose::LinkButton::Body @iconOnly={{@iconOnly}} @iconLeft={{@iconLeft}} @iconRight={{@iconRight}}>
|
||||
{{yield}}
|
||||
</Rose::LinkButton::Body>
|
||||
</LinkTo>
|
||||
{{/if}}
|
||||
@@ -0,0 +1,26 @@
|
||||
<span class="rose-button-wrapper">
|
||||
{{#if @iconLeft}}
|
||||
<Rose::Icon
|
||||
@name={{@iconLeft}}
|
||||
@size="medium"
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
<span class="rose-button-body">
|
||||
{{yield}}
|
||||
</span>
|
||||
|
||||
{{#if @iconOnly}}
|
||||
<Rose::Icon
|
||||
@name={{@iconOnly}}
|
||||
@size="medium"
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
{{#if @iconRight}}
|
||||
<Rose::Icon
|
||||
@name={{@iconRight}}
|
||||
@size="medium"
|
||||
/>
|
||||
{{/if}}
|
||||
</span>
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'rose/components/rose/link-button/body';
|
||||
@@ -0,0 +1,40 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render, find } from '@ember/test-helpers';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
|
||||
module('Integration | Component | rose/link-button/body', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function (assert) {
|
||||
await render(hbs`<Rose::LinkButton::Body />`);
|
||||
assert.ok(find('.rose-button-wrapper'));
|
||||
});
|
||||
|
||||
test('it renders with content', async function (assert) {
|
||||
await render(hbs`<Rose::LinkButton::Body>
|
||||
Body content
|
||||
</Rose::LinkButton::Body>`);
|
||||
assert.equal(
|
||||
find('.rose-button-wrapper').textContent.trim(),
|
||||
'Body content'
|
||||
);
|
||||
});
|
||||
|
||||
test('it supports @iconLeft', async function (assert) {
|
||||
await render(hbs`<Rose::LinkButton::Body @iconLeft="chevron-left"/>`);
|
||||
assert.ok(find('.rose-icon'));
|
||||
});
|
||||
|
||||
test('it supports @iconRight', async function (assert) {
|
||||
await render(hbs`<Rose::LinkButton::Body @iconRight="chevron-right" />`);
|
||||
assert.ok(find('.rose-icon'));
|
||||
});
|
||||
|
||||
test('it supports @iconOnly', async function (assert) {
|
||||
await render(
|
||||
hbs`<Rose::LinkButton::Body @iconOnly="help-circle-outline" />`
|
||||
);
|
||||
assert.ok(find('.rose-icon'));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user