{expect, calls} = require 'racer/test/util' {DetachedModel: Model} = require './mocks' View = require '../lib/View.server' describe 'App HTML components', -> view = model = null beforeEach (done) -> view = new View model = new Model view._init model, false, done it 'supports void components', -> view.make 'test', 'say ""' view.make 'test2', 'hi' expect(view.get 'test').to.equal 'say "hi"' it 'supports lookup', -> view.make 'test', 'say ""' view.make 'test2', 'hi' expect(view.get 'test').to.equal 'say "hi"' it 'supports lookup', -> view.make 'test', 'say ""' view.make 'test2', 'hi' expect(view.get 'test', {template: 'test2'}).to.equal 'say "hi"' it 'supports lookup', -> view.make 'test', '' view.make 'test2', 'say ""' view.make 'test3', 'hi' expect(view.get 'test').to.equal 'say "hi"' it 'supports lookup via inherit', -> view.make 'test', '' view.make 'test2', 'say ""' view.make 'test3', 'hi' expect(view.get 'test').to.equal 'say "hi"' it 'supports literal attributes', -> 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.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.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.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.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.make 'test', 'say ""' view.make 'test2', ''' {{@message.text}} ''' expect(view.get 'test', myMessage: {text: 'Heyo'}).to.equal 'say "Heyo"' it 'supports dot syntax for nested properties of variable object attributes', -> view.make 'test', 'say ""' view.make 'test2', ''' {{@messages.0.text}} ''' expect(view.get 'test', myMessages: [{text: 'Heyo'}]).to.equal 'say "Heyo"' it 'supports passing through literal attributes', -> view.make 'test', '' view.make 'test2', '' view.make 'test3', '{{@text}}' expect(view.get 'test').to.equal 'Howdy' it 'supports passing through bound attributes', -> view.make 'test', '' view.make 'test2', '' view.make 'test3', '{{@text}}' model.set '_stuff', 'Howdy' expect(view.get 'test').to.equal 'Howdy' it 'supports this within scope from literal attribute', -> view.make 'test', 'say ""' view.make 'test2', ''' {{#with @message}} {{this}} {this} {{/}} ''' expect(view.get 'test').to.equal 'say "HeyoHeyo"' it 'supports bound attributes', -> 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.make 'test', 'say ""' view.make 'test2', '
' model.set 'myMessage', 'Heyo' expect(view.get 'test').to.equal 'say "
"' it 'supports blocks in attributes used in an attribute', -> view.make 'test', 'say ""' view.make 'test2', '
' model.set 'myMessage', 'Heyo' expect(view.get 'test').to.equal 'say "
"' it 'supports bound blocks in attributes used in an attribute' # view.make 'test', 'say ""' # view.make 'test2', '
' # model.set 'myMessage', 'Heyo' # expect(view.get 'test').to.equal 'say "
"' it 'supports nonvoid components', -> view.make 'test', '
    Hi!
' view.make 'test2', '
  • {{@content}}
  • ', {nonvoid: true} expect(view.get 'test').to.equal '
    • Hi!
    ' it 'supports content sections', -> view.make 'test', '
      <@section>HeyoHi!
    ' view.make 'test2', '
  • {{@content}}
  • {{@section}}
  • ', {nonvoid: true} expect(view.get 'test').to.equal '
    • Hi!
    • Heyo
    '