Sha256: f16ee00248d459fa1cbc42ba016723ff3f62e804484a5585149182143e285eba

Contents?: true

Size: 1.71 KB

Versions: 5

Compression:

Stored size: 1.71 KB

Contents

#= require lanes/components/grid


DATA = {total:2, success:true, message:"Retrieve succeeded", data:[
    [1, "TEST1", "Nathan Stitt", "swell guy"]
    [2, "TEST2", "Nathan Stitt", "Dupe of id #1"]
]}

Model = Lanes.Test.defineModel(
    props: {id: 'integer', code: 'string', name: 'string', notes: 'string'}
)

renderGrid = (q, done) ->
    loaded = spyOn(q.results, 'ensureLoaded').and.callThrough()
    grid = LT.renderComponent(LC.Grid, props: query: q)
    expect(loaded).toHaveBeenCalled()
    _.defer ->
        expect(_.dom(grid).qsa('.r').length)
            .toEqual( q.results.length )
        done()

describe "Lanes.Components.Grid", ->

    beforeEach (done) ->
        LT.syncRespondWith(DATA)
        @query = new Lanes.Models.Query(
            src: Model, fields: [ 'id', 'code', 'name', 'notes' ]
        )
        @collection = new Model.Collection
        @query.ensureLoaded().then => @collection.ensureLoaded().then -> done()

    describe "loading", ->

        it "from a result set", (d) ->
            renderGrid(@query, d)

        it "from a collection", (d) ->
            @query.src = @collection
            renderGrid(@query, d)

    it 'renders toolbar', ->
        grid = LT.renderComponent(LC.Grid, props: {
            query: @query, editor: true, allowCreate: true
        })
        tb = _.dom(grid).qs('.toolbar')
        expect(tb).not.toBeUndefined()

    it 'notifies when selection changes', (done) ->
        spy = jasmine.createSpy('selection')
        grid = LT.renderComponent(LC.Grid, props: {
            query: @query, editor: true, onSelectionChange: spy
        })
        _.defer ->
            _.dom(grid).qs('.grid-body .c').click()
            expect(spy).toHaveBeenCalled()
            done()

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lanes-0.5.6 spec/lanes/components/grid/GridSpec.coffee
lanes-0.5.5 spec/lanes/components/grid/GridSpec.coffee
lanes-0.5.0 spec/lanes/components/grid/GridSpec.coffee
lanes-0.4.0 spec/lanes/components/grid/GridSpec.coffee
lanes-0.3.0 spec/lanes/components/grid/GridSpec.coffee