-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Ember from 'ember' | ||
|
||
const {String: EmberString, get} = Ember | ||
|
||
/** | ||
* factory for a details page title handler | ||
* will get a dynamic title from a route's controller | ||
* based on a path to the data in its model | ||
* @param {string} modelPath - path in model to dynamic title data | ||
* @returns {array} - array of title sections | ||
*/ | ||
export default function pageTitleFactory (modelPath) { | ||
return function (sections, defaultTitle) { | ||
const name = get(this.controller.model, modelPath) | ||
let tab = get(this.controller, 'selectedTabId') | ||
|
||
if (tab) { | ||
tab = EmberString.capitalize(tab.replace(/-/g, ' ')) | ||
} | ||
|
||
return [name, tab] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default, initialize} from 'ember-frost-page-title/utils/details-page-title-factory' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {expect} from 'chai' | ||
import pageTitleFactory from 'ember-frost-page-title/utils/details-page-title-factory' | ||
import {beforeEach, describe, it} from 'mocha' | ||
|
||
describe('Unit / utils / details-page-title-factory /', function () { | ||
let dummyRoute | ||
|
||
beforeEach(function () { | ||
dummyRoute = { | ||
pageTitleHandler: pageTitleFactory('name'), | ||
|
||
controller: { | ||
model: { | ||
name: 'Details page title' | ||
}, | ||
|
||
selectedTabId: 'some-tab' | ||
} | ||
} | ||
}) | ||
|
||
it('should return a function', function () { | ||
expect(typeof dummyRoute.pageTitleHandler).to.equal('function') | ||
}) | ||
|
||
describe('the generated handler', function () { | ||
it('should return an array', function () { | ||
let handlerOutput = dummyRoute.pageTitleHandler([], 'defaultTitle') | ||
expect(Array.isArray(handlerOutput)).to.equal(true) | ||
}) | ||
|
||
it('should get the data from the model via the modelPath', function () { | ||
let handlerOutput = dummyRoute.pageTitleHandler([], 'defaultTitle') | ||
expect(handlerOutput[0]).to.equal('Details page title') | ||
}) | ||
|
||
it('should get the tab name and properly capitalize/de-dasherize it', function () { | ||
let handlerOutput = dummyRoute.pageTitleHandler([], 'defaultTitle') | ||
expect(handlerOutput[1]).to.equal('Some tab') | ||
}) | ||
}) | ||
}) |