Sha256: dd77453b635ebd9188aea5ce7ea8e195125b16382b6afba1390594b6be00899e

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 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().match(/value_one/) ).toBeTruthy()

  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

3 entries across 3 versions & 1 rubygems

Version Path
luca-0.9.91 spec/javascripts/components/collection_view_spec.coffee
luca-0.9.9 spec/javascripts/components/collection_view_spec.coffee
luca-0.9.899 spec/javascripts/components/collection_view_spec.coffee