From d614f0e63002af824ca096a5cc74149440a59624 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Wed, 17 Jun 2020 13:51:15 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20Add=20model=20check=20f?= =?UTF-8?q?or=20linkbutton=20rose=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../rose/addon/components/rose/link-button.js | 3 ++ .../addon/components/rose/link-button/body.js | 7 +++ .../templates/components/rose/link-button.hbs | 53 ++++++++----------- .../components/rose/link-button/body.hbs | 26 +++++++++ .../app/components/rose/link-button/body.js | 1 + .../components/rose/link-button/body-test.js | 40 ++++++++++++++ 6 files changed, 98 insertions(+), 32 deletions(-) create mode 100644 addons/rose/addon/components/rose/link-button/body.js create mode 100644 addons/rose/addon/templates/components/rose/link-button/body.hbs create mode 100644 addons/rose/app/components/rose/link-button/body.js create mode 100644 addons/rose/tests/integration/components/rose/link-button/body-test.js diff --git a/addons/rose/addon/components/rose/link-button.js b/addons/rose/addon/components/rose/link-button.js index 32e084f7e..3219bcbff 100644 --- a/addons/rose/addon/components/rose/link-button.js +++ b/addons/rose/addon/components/rose/link-button.js @@ -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 * Save diff --git a/addons/rose/addon/components/rose/link-button/body.js b/addons/rose/addon/components/rose/link-button/body.js new file mode 100644 index 000000000..7934097df --- /dev/null +++ b/addons/rose/addon/components/rose/link-button/body.js @@ -0,0 +1,7 @@ +import Component from '@ember/component'; +import layout from '../../../templates/components/rose/link-button/body'; + +export default Component.extend({ + layout, + tagName: '', +}); diff --git a/addons/rose/addon/templates/components/rose/link-button.hbs b/addons/rose/addon/templates/components/rose/link-button.hbs index 9a992f149..f7d7e94c3 100644 --- a/addons/rose/addon/templates/components/rose/link-button.hbs +++ b/addons/rose/addon/templates/components/rose/link-button.hbs @@ -1,33 +1,22 @@ - - - - {{#if @iconLeft}} - - {{/if}} - - +{{#if @model}} + + {{yield}} - - - {{#if @iconOnly}} - - {{/if}} - - {{#if @iconRight}} - - {{/if}} - - + + +{{else}} + + + {{yield}} + + +{{/if}} diff --git a/addons/rose/addon/templates/components/rose/link-button/body.hbs b/addons/rose/addon/templates/components/rose/link-button/body.hbs new file mode 100644 index 000000000..20ea6c6a5 --- /dev/null +++ b/addons/rose/addon/templates/components/rose/link-button/body.hbs @@ -0,0 +1,26 @@ + + {{#if @iconLeft}} + + {{/if}} + + + {{yield}} + + + {{#if @iconOnly}} + + {{/if}} + + {{#if @iconRight}} + + {{/if}} + diff --git a/addons/rose/app/components/rose/link-button/body.js b/addons/rose/app/components/rose/link-button/body.js new file mode 100644 index 000000000..b3c9ee39f --- /dev/null +++ b/addons/rose/app/components/rose/link-button/body.js @@ -0,0 +1 @@ +export { default } from 'rose/components/rose/link-button/body'; diff --git a/addons/rose/tests/integration/components/rose/link-button/body-test.js b/addons/rose/tests/integration/components/rose/link-button/body-test.js new file mode 100644 index 000000000..2ff8aecaa --- /dev/null +++ b/addons/rose/tests/integration/components/rose/link-button/body-test.js @@ -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``); + assert.ok(find('.rose-button-wrapper')); + }); + + test('it renders with content', async function (assert) { + await render(hbs` + Body content + `); + assert.equal( + find('.rose-button-wrapper').textContent.trim(), + 'Body content' + ); + }); + + test('it supports @iconLeft', async function (assert) { + await render(hbs``); + assert.ok(find('.rose-icon')); + }); + + test('it supports @iconRight', async function (assert) { + await render(hbs``); + assert.ok(find('.rose-icon')); + }); + + test('it supports @iconOnly', async function (assert) { + await render( + hbs`` + ); + assert.ok(find('.rose-icon')); + }); +});