Skip to content

Commit

Permalink
Merge a4e630d into 1774f66
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOtherDude committed Nov 13, 2017
2 parents 1774f66 + a4e630d commit 20f3a91
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 16 deletions.
11 changes: 11 additions & 0 deletions addon/components/nav-route.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ember from 'ember'
const {inject} = Ember
import computed, {readOnly} from 'ember-computed-decorators'
import {Component} from 'ember-frost-core'
import {PropTypes} from 'ember-prop-types'

Expand Down Expand Up @@ -34,6 +35,16 @@ export default Component.extend({
}
},

// == Computed Properties ===================================================

@readOnly
@computed('icon')
iconHref (icon) {
if (icon && icon.includes('/')) {
return icon.includes('#') ? icon : `${icon}#root`
}
},

// == Functions =============================================================

// == DOM Events ============================================================
Expand Down
32 changes: 23 additions & 9 deletions addon/templates/components/nav-route.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
}}
<div class='content'>
<div class='nav-route-icon'>
{{#if icon}}
{{frost-icon
hook=(concat hookPrefix '-link-icon')
hookQualifiers=hookQualifiers
pack=pack
icon=icon
}}
{{#if iconHref}}
<svg
class='frost-icon'
data-test={{hook (concat hookPrefix '-link-icon') hookQualifiers}}
>
<use xlink:href="{{iconHref}}" />
</svg>
{{else if icon}}
{{frost-icon
hook=(concat hookPrefix '-link-icon')
hookQualifiers=hookQualifiers
pack=pack
icon=icon
}}
{{/if}}
</div>
<div>
Expand All @@ -34,10 +41,17 @@
class='frost-link'
href='{{url}}'
target="{{if tabbed '_blank'}}"
data-test={{hook (concat hookPrefix '-link') hookQualifiers=hookQualifiers}}>
data-test={{hook (concat hookPrefix '-link') hookQualifiers}}>
<div class='content'>
<div class='nav-route-icon'>
{{#if icon}}
{{#if iconHref}}
<svg
class='frost-icon'
data-test={{hook (concat hookPrefix '-link-icon') hookQualifiers}}
>
<use xlink:href="{{iconHref}}" />
</svg>
{{else if icon}}
{{frost-icon
hook=(concat hookPrefix '-link-icon')
hookQualifiers=hookQualifiers
Expand Down
11 changes: 10 additions & 1 deletion tests/dummy/app/pods/demo/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ export default Controller.extend({
routeModels: ['id0'],
routeQueryParams: {count: 0}
})
const iconLinkExample = Ember.Object.extend({}).create({
description: 'Icon is referenced by URI',
icon: '/svgs/pinpoint/nav/fiberplant.svg#Layer_1',
name: 'Custom Route',
route: 'test',
routeModels: ['id0'],
routeQueryParams: {count: 0}
})
set(this, 'customRouteObject', customRouteObject)
let columns = [
[
{
title: 'Custom Column',
routes: [
customRouteObject
customRouteObject,
iconLinkExample
]
}
]
Expand Down
128 changes: 122 additions & 6 deletions tests/integration/components/nav-route-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {expect} from 'chai'
import {$hook} from 'ember-hook'
import wait from 'ember-test-helpers/wait'
import {integration} from 'ember-test-utils/test-support/setup-component-test'
import hbs from 'htmlbars-inline-precompile'
import {beforeEach, describe, it} from 'mocha'
Expand All @@ -8,15 +10,129 @@ describe(test.label, function () {
test.setup()

beforeEach(function () {
this.render(hbs`{{nav-route}}`)
this.render(hbs`
{{nav-route
hook='hook'
hookQualifiers=(hash fizz='bang')
icon=icon
route=route
}}
`)
})

it('should render a single element in the DOM', function () {
expect(this.$()).to.have.length(1)
describe('when route is undefined', function () {
beforeEach(function () {
this.set('route', undefined)
return wait()
})

describe('when icon not a path', function () {
beforeEach(function () {
this.set('icon', 'add')
return wait()
})

it('should have frost-icon class', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.attr('class').split(' ')).to.include('frost-icon')
})

it('should have the expected xlink:href', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.find('use')).to.have.attr('xlink:href', 'assets/icon-packs/frost.svg#add')
})
})

describe('when icon is a path without an id', function () {
beforeEach(function () {
this.set('icon', '/my/icon/path')
return wait()
})

it('should have frost-icon class', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.attr('class').split(' ')).to.include('frost-icon')
})

it('should have the expected xlink:href', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.find('use')).to.have.attr('xlink:href', '/my/icon/path#root')
})
})

describe('when icon is a path with an id', function () {
beforeEach(function () {
this.set('icon', '/my/icon/path#Layer_1')
return wait()
})

it('should have frost-icon class', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.attr('class').split(' ')).to.include('frost-icon')
})

it('should have the expected xlink:href', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.find('use')).to.have.attr('xlink:href', '/my/icon/path#Layer_1')
})
})
})

// FIXME: add real tests
it.skip('should have real tests', function () {
expect(true).to.equal(false)
describe('when route is defined', function () {
beforeEach(function () {
this.set('route', 'test')
return wait()
})

describe('when icon not a path', function () {
beforeEach(function () {
this.set('icon', 'add')
return wait()
})

it('should have frost-icon class', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.attr('class').split(' ')).to.include('frost-icon')
})

it('should have the expected xlink:href', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.find('use')).to.have.attr('xlink:href', 'assets/icon-packs/frost.svg#add')
})
})

describe('when icon is a path without an id', function () {
beforeEach(function () {
this.set('icon', '/my/icon/path')
return wait()
})

it('should have frost-icon class', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.attr('class').split(' ')).to.include('frost-icon')
})

it('should have the expected xlink:href', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.find('use')).to.have.attr('xlink:href', '/my/icon/path#root')
})
})

describe('when icon is a path with an id', function () {
beforeEach(function () {
this.set('icon', '/my/icon/path#Layer_1')
return wait()
})

it('should have frost-icon class', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.attr('class').split(' ')).to.include('frost-icon')
})

it('should have the expected xlink:href', function () {
const $icon = $hook('hook-link-icon', {fizz: 'bang'})
expect($icon.find('use')).to.have.attr('xlink:href', '/my/icon/path#Layer_1')
})
})
})
})

0 comments on commit 20f3a91

Please sign in to comment.