Forked from mike-north/components.user-profile.js
Last active
September 27, 2017 21:31
-
-
Save RapsIn4/550a8d209d53978dfbf80b2a1546dae2 to your computer and use it in GitHub Desktop.
LI Bootcamp
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
classNames: ['profile', 'content-box'] | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
function capitalize(s) | |
{ | |
return s[0].toUpperCase() + s.slice(1); | |
} | |
export function fullName([model]) { | |
let result = '(No Name)'; | |
if (model.firstName) { | |
result = capitalize(model.firstName); | |
if (model.lastName) { | |
result += ' ' + capitalize(model.lastName); | |
} | |
} else if (model.lastName) { | |
result = capitalize(model.lastName); | |
} | |
return result; | |
} | |
export default Ember.Helper.helper(fullName); |
This file contains hidden or 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
import Ember from 'ember'; | |
export function placeholderUrl(params, hash) { | |
let width = 40; | |
let height = 40; | |
if (hash) { | |
if (hash.w && hash.w > 40) width = hash.w; | |
if (hash.h && hash.h > 40) height = hash.h; | |
} | |
return `http://placekitten.com/${width}/${height}`; | |
} | |
export default Ember.Helper.helper(placeholderUrl); |
This file contains hidden or 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
import Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('profile', {path: 'profile/:id'}); | |
}); | |
export default Router; |
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model({ id }) { | |
return { | |
firstName: 'Reid', | |
lastName: 'Hoffman', | |
headline: 'I founded LinkedIn', | |
location: 'Sunnyvale' | |
}; | |
} | |
}); |
This file contains hidden or 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
body { | |
padding: 0; | |
margin: 0; | |
font-family: Arial, Helvetica, sans-serif; | |
background-color: rgb(245, 245, 245); | |
} | |
body::selection { | |
background: #0084bf; | |
color: #fff; | |
} | |
nav.navbar { | |
height: 54px; | |
background: #283e4a; | |
margin-bottom: 10px; | |
} | |
nav.navbar .navbar-title { | |
color: white; | |
display: block; | |
text-align: center; | |
padding-top: 7px; | |
padding-bottom: 7px; | |
line-height: 40px; | |
font-size: 30px; | |
} | |
.container { | |
width: 960px; | |
max-width: calc(100% - 20px); | |
margin-left: auto; | |
margin-right: auto; | |
padding-left: 10px; | |
padding-right: 10px; | |
} | |
/**** utility ****/ | |
.pull-right { | |
float: right; | |
} | |
.pull-left { | |
float: left; | |
} | |
/**** content-box ****/ | |
.content-box { | |
margin-top: 10px; | |
border: 1px solid #aaa; | |
background: #fff; | |
padding: 10px; | |
} | |
.content-box p { | |
color: #777; | |
font-weight: 300; | |
line-height: 1.4rem; | |
} | |
/**** Code ****/ | |
code { | |
margin-left: 2px; | |
margin-right: 2px; | |
padding-left: 5px; | |
padding-right: 5px; | |
margin-top: 0.1rem; | |
margin-bottom: 0.1rem; | |
display: inline-block; | |
} | |
pre.code, code { | |
border-radius: 2px; | |
background-color: #486F84; | |
color: #A6F2DB; | |
line-height: 1.2rem; | |
} | |
/**** Profile *****/ | |
.profile .profile-picture { | |
max-width: 100%; | |
border-radius: 50%; | |
border: 1px solid #283e4a; | |
box-shadow: 0 0 10px rgba(0,0,0,0.8); | |
display: inline-block; | |
} | |
.profile .profile-left { | |
width: 100px; | |
float: left; | |
display: inline-block; | |
} | |
.profile .profile-right { | |
margin-left: 130px; | |
} | |
.profile .profile-name { | |
margin-bottom: 0.5rem; | |
} | |
.profile .profile-description, | |
.profile .profile-location { | |
margin-top: 0.5rem; | |
margin-bottom: 0.5rem; | |
color: #666; | |
font-weight: 300; | |
} | |
.profile .profile-description:before, | |
.profile .profile-location:before { | |
margin-right: 10px; | |
display: inline-block; | |
width: 20px; | |
} | |
.profile .profile-description:before { | |
content: '📢'; | |
} | |
.profile .profile-location:before { | |
content: '🗺'; | |
} |
This file contains hidden or 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
import Ember from 'ember'; | |
export default function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
This file contains hidden or 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
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
This file contains hidden or 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
import Ember from 'ember'; | |
import Application from '../../app'; | |
import config from '../../config/environment'; | |
const { run } = Ember; | |
const assign = Ember.assign || Ember.merge; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = assign({rootElement: "#test-root"}, config.APP); | |
attributes = assign(attributes, attrs); // use defaults, but you can override; | |
run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
This file contains hidden or 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
import { moduleForComponent, test } from 'ember-qunit'; | |
import hbs from 'htmlbars-inline-precompile'; | |
moduleForComponent('user-profile', 'user-profile component', { | |
integration: true | |
}); | |
test('it is rendered as expected when provided with complete data', function(assert) { | |
this.set('tempModel', { | |
firstName: 'Reid', | |
lastName: 'Hoffman', | |
headline: 'I founded LinkedIn', | |
location: 'Silicon Valley' | |
}); | |
this.render(hbs`{{user-profile person=tempModel}}`); | |
assert.equal( | |
this.$('.profile-name').text(), | |
'Reid Hoffman', | |
'Name shows up as expected' | |
); | |
assert.equal( | |
this.$('.profile-description').text(), | |
'I founded LinkedIn', | |
'Headline shows up as expected' | |
); | |
assert.equal( | |
this.$('.profile-location').text(), | |
'Silicon Valley', | |
'Location shows up as expected' | |
); | |
}); | |
test('When location is missing, it is not rendered', function(assert) { | |
this.set('tempModel', { | |
firstName: 'Reid', | |
lastName: 'Hoffman', | |
headline: 'I founded LinkedIn' | |
}); | |
this.render(hbs`{{user-profile person=tempModel}}`); | |
assert.equal( | |
this.$('.profile-location').length, | |
0, | |
'.profile-location <div> is not in the DOM' | |
); | |
}); | |
test('When headline is missing, it is not rendered', function(assert) { | |
this.set('tempModel', { | |
firstName: 'Reid', | |
lastName: 'Hoffman', | |
location: 'Silicon Valley' | |
}); | |
this.render(hbs`{{user-profile person=tempModel}}`); | |
assert.equal( | |
this.$('.profile-description').text(), | |
'A LinkedIn Employee', | |
'In the absence of a "headline" field on the model, "A LinkedIn Employee" is used instead' | |
); | |
}); |
This file contains hidden or 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
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
This file contains hidden or 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
import { moduleFor, test } from 'ember-qunit'; | |
import { fullName } from 'twiddle/helpers/full-name'; | |
module('helper:full-name'); | |
test('it works for models with data', function(assert) { | |
assert.equal( | |
fullName([{firstName: 'Santa', lastName: 'Claus'}]), | |
'Santa Claus', | |
'Correct result for capitalized first and last names'); | |
assert.equal( | |
fullName([{firstName: 'santa', lastName: 'claus'}]), | |
'Santa Claus', | |
'Uncapitalized name parts are capitalized'); | |
assert.equal( | |
fullName([{firstName: '', lastName: 'Claus'}]), | |
'Claus', | |
'Empty first name is ignored (including spaces)'); | |
assert.equal( | |
fullName([{firstName: 'Santa', lastName: ''}]), | |
'Santa', | |
'Empty last name is ignored (including spaces)'); | |
assert.equal( | |
fullName([{firstName: 'Santa'}]), | |
'Santa', | |
'Undefined last name is ignored'); | |
}); | |
test('Provides a reasonable output for unreasonable input', function(assert) { | |
assert.equal( | |
fullName([{}]), | |
'(No Name)', | |
'"(No Name)" used when firstName and lastName are both empty/undefined'); | |
}); |
This file contains hidden or 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
import { moduleFor, test } from 'ember-qunit'; | |
import { placeholderUrl } from 'twiddle/helpers/placeholder-url'; | |
module('helper:placeholder-url'); | |
test('it works when provided with both width and height', function(assert) { | |
assert.equal( | |
placeholderUrl([], {w: '200', h: '100'}), | |
'http://placekitten.com/200/100', | |
'positive width and height handled properly'); | |
assert.equal( | |
placeholderUrl([], {w: '-20', h: '100'}), | |
'http://placekitten.com/40/100', | |
'If provided with width < 40, uses 40 instead'); | |
assert.equal( | |
placeholderUrl([], { }), | |
'http://placekitten.com/40/40', | |
'If provided with width < 40, uses 40 instead'); | |
}); | |
test('it falls back to defaults when not provided with reasonable width and/or height', function(assert) { | |
assert.equal( | |
placeholderUrl([], {}), | |
'http://placekitten.com/40/40', | |
'when width and height are unspecified, use 40 x 40'); | |
assert.equal( | |
placeholderUrl([]), | |
'http://placekitten.com/40/40', | |
'If no arguments are provided (helper will receive undefined hash), we still fall back to 40 x 40 size'); | |
}); |
This file contains hidden or 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
{ | |
"version": "0.11.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.11.0", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.11.0", | |
"ember-testing": "2.11.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment