{expect, calls} = require 'racer/test/util' {DetachedModel: Model} = require './mocks' View = require '../lib/View.server' describe 'App HTML components', -> it 'supports void components', -> view = new View view._init new Model view.make 'test', 'say ""' view.make 'test2', 'hi' expect(view.get 'test').to.equal 'say "hi"' it 'supports literal attributes', -> view = new View view._init new Model view.make 'test', 'say "" or ""' view.make 'test2', ''' {{{#if message}}} {{{message}}} {{{else}}} Yo {{{/}}} ''' expect(view.get 'test').to.equal 'say "Howdy" or "Yo"' it 'macro attributes are case-insensitive', -> view = new View view._init new Model view.make 'test', 'say "" or ""' view.make 'test2', ''' {{{#if messAGE}}} {{{message}}} {{{else}}} Yo {{{/}}} ''' expect(view.get 'test').to.equal 'say "Howdy" or "Yo"' it 'supports boolean and numerical attributes', -> view = new View view._init new Model view.make 'test', ' / / ' view.make 'test2', ''' {{{#if show}}} Hi {{{else if equal(num, -4.5)}}} Got it {{{else}}} Nada {{{/}}} ''' expect(view.get 'test').to.equal 'Hi / Got it / Nada' it 'supports variable attributes', -> view = new View view._init new Model view.make 'test', 'say ""' view.make 'test2', ''' {{{#if message}}} {{{message}}} {{{else}}} Yo {{{/}}} ''' expect(view.get 'test').to.equal 'say "Yo"' expect(view.get 'test', myMessage: 'Heyo').to.equal 'say "Heyo"' it 'supports variable object attributes', -> view = new View view._init new Model view.make 'test', 'say ""' view.make 'test2', ''' {{{#with message}}} {{text}} {{{/}}} ''' expect(view.get 'test', myMessage: {text: 'Heyo'}).to.equal 'say "Heyo"' it 'supports dot syntax for properties of variable object attributes', -> view = new View view._init new Model view.make 'test', 'say ""' view.make 'test2', ''' {{{message.text}}} ''' expect(view.get 'test', myMessage: {text: 'Heyo'}).to.equal 'say "Heyo"' it 'supports bound attributes', -> view = new View model = new Model view._init model view.make 'test', 'say ""' view.make 'test2', ''' {{{#if message}}} {{{message}}} {{{else}}} Yo {{{/}}} ''' model.set 'myMessage', 'Heyo' expect(view.get 'test').to.equal 'say "Heyo"' it 'supports bound attributes as element attributes', -> view = new View model = new Model view._init model view.make 'test', 'say ""' view.make 'test2', '''
''' model.set 'myMessage', 'Heyo' expect(view.get 'test').to.equal 'say "
"' it 'supports nonvoid components', -> view = new View view._init new Model view.make 'test', '
    Hi!
' view.make 'test2', '
  • {{{content}}}
  • ', {nonvoid: null} expect(view.get 'test').to.equal '
    • Hi!
    '