Skip to content

Instantly share code, notes, and snippets.

@rafaltrojanowski
Last active April 27, 2016 10:35
test "Sebastian commented on Matylda's gallery: Looks awesome!", (assert) ->
assert.expect 1
commenter = Ember.Object.create( # mock for Ember DS.Model
displayName: "Sebastian"
)
galleryOwner = Ember.Object.create(
id: 2,
displayName: "Matylda"
)
gallery = Ember.Object.create(
name: "Paintings"
owner: galleryOwner
)
comment = Ember.Object.create(
id: 1,
text: "Looks awesome!",
commenter: commenter,
gallery: gallery,
)
notification = Ember.Object.create(
id: 1,
comment: comment
)
@set('notification', notification)
@render hbs """{{notifications/new-comment/gallery-notification notification=notification}}"""
assert.equal @$().text().trim(), "Sebastian commented on Matylda's gallery: Looks awesome!"
# component's template
notification.comment.commenter.displayName
| commented on
notification.comment.gallery.owner.displayName
| 's gallery:
notification.comment.text
# component
`import Ember from "ember"`
GalleryNotification = Ember.Component.extend
comment: Ember.computed.readOnly('notification.comment')
commenter: Ember.computed.readOnly('comment.commenter')
gallery: Ember.computed.readOnly('comment.gallery')
galleryOwner: Ember.computed.readOnly('gallery.owner')
`export default GalleryNotification`
# template
commenter.displayName
| commented on
galleryOwner.displayName
|'s gallery:
|  
comment.text
test 'when Sebastian commented on his own gallery: Looks awesome!', (assert) ->
assert.expect 1
commenter = Ember.Object.create(
id: 1,
displayName: "Sebastian",
gender: 'male'
)
gallery = Ember.Object.create(
name: "Paintings",
owner: commenter
)
comment = Ember.Object.create(
id: 1,
text: "Looks awesome!",
commenter: commenter,
gallery: gallery
)
notification = Ember.Object.create(
id: 1,
comment: comment
)
@set('notification', notification)
@render hbs """{{notifications/new-comment/gallery-notification notification=notification}}"""
assert.equal @$().text().trim(), 'Sebastian commented on his own gallery: Looks awesome!'
# component
GalleryNotification = Ember.Component.extend
comment: Ember.computed.readOnly('notification.comment')
commenter: Ember.computed.readOnly('comment.commenter')
gallery: Ember.computed.readOnly('comment.gallery')
galleryOwner: Ember.computed.readOnly('gallery.owner')
hasCommentedOwnGallery: Ember.computed 'commenter', 'galleryOwner', ->
@get('commenter') == @get('galleryOwner')
isCommenterMale: Ember.computed 'commenter', ->
@get('commenter.gender') == 'male'
# template
commenter.displayName
| commented on
if hasCommentedOwnCreation
if isCommenterMale
_ "his own"
else
galleryOwner.displayName
_"'s gallery" space='e'
comment.text
test 'when Matylda commented on her own gallery: Looks awesome!', (assert) ->
assert.expect 1
commenter = Ember.Object.create(
id: 1,
displayName: "Matylda",
gender: 'female',
)
gallery = Ember.Object.create(
name: "Paintings",
owner: commenter,
)
comment = Ember.Object.create(
id: 1,
text: "Looks awesome!",
commenter: commenter,
gallery: gallery,
)
notification = Ember.Object.create(
id: 1,
comment: comment
)
@set('notification', notification)
@render hbs """{{notifications/new-comment/gallery-notification notification=notification}}"""
assert.equal @$().text().trim(), "Matylda commented on her own gallery: Looks awesome!"
# template
commenter.displayName
| commented on
if hasCommentedOwnCreation
if isCommenterMale
_ "his"
else
_ "her"
_ "own" space='s
galleryOwner.displayName
_"'s gallery" space='e'
comment.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment