Sha256: f3eb0ea71ff7c4ed1959847b086e21b159c8b309c147d429fd6929a2f663f8a8

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

describe 'The Collection View', ->
  beforeEach ->
    @collection = new Luca.Collection([
      id: 1, attr: "value_one", filter: "value"
    ,
      id: 2, attr: "value_two", filter: "value"
    ],
    model: Luca.Model)

    @view = new Luca.components.CollectionView
      itemTagName: "li"
      itemClassName: "custom-class"
      itemProperty: 'attr'
      collection: @collection
      filterable:
        query:
          filter: "value"
        options:
          sortBy: "filter"

    @view.render()

  it "should provide access to the query", ->
    expect( @view.getQuery() ).toBeDefined()

  it "should provide access to the query options", ->
    expect( @view.getQueryOptions() ).toBeDefined()

  it "should combine filter and pagination in the options hash", ->
    @view.setPage(5)
    @view.applyFilter({filter:"value"},{sortBy:'filter'})

    options = @view.getQueryOptions()
    query = @view.getQuery()

    expect( options.page ).toEqual 5
    expect( options.sortBy ).toEqual 'filter'
    expect( query.filter ).toEqual 'value'

  it "should render the attributes in the specified list elements", ->
    expect( @view.$html() ).toContain('value_one')

  it "should render each of the attributes", ->
    expect( @view.$('li.custom-class').length ).toEqual 2

  it "should locate a dom element by luca model id", ->
    expect( @view.locateItemElement(2).html() ).toContain('value_two')

  it "should refresh the view when a model is added", ->
    @view.collection.add(attr:"value_three",id:3)
    expect( @view ).toHaveTriggered('after:refresh')

  it "should refresh the view when a model is removed", ->
    @view.collection.remove( @view.collection.at(0) )
    expect( @view ).toHaveTriggered('after:refresh')




Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
luca-0.9.89 spec/javascripts/components/collection_view_spec.coffee
luca-0.9.8 spec/components/collection_view_spec.coffee
luca-0.9.76 spec/components/collection_view_spec.coffee
luca-0.9.7 spec/components/collection_view_spec.coffee
luca-0.9.65 spec/components/collection_view_spec.coffee