Sha256: 2cad862765bca0abae44d7117ee12c148887681381cb8655dcb87d3660fd15dc

Contents?: true

Size: 1.94 KB

Versions: 31

Compression:

Stored size: 1.94 KB

Contents

describe "Mercury.modalHandlers.insertSnippet", ->

  template 'mercury/modals/insertsnippet.html'

  beforeEach ->
    Mercury.Snippet.all = []
    Mercury.Snippet.load({
      'snippet_0': {name: 'foo', options: {'first_name': "Jeremy", 'last_name': "Jackson"}},
    })
    @modal =
      element: $('#test')
      hide: ->
      options: {snippetName: 'test'}
    Mercury.modalHandlers.insertSnippet.call(@modal)

  describe "submitting", ->

    it "hides the modal", ->
      spy = spyOn(@modal, 'hide').andCallFake(=>)
      jasmine.simulate.click($('#submit').get(0))
      expect(spy.callCount).toEqual(1)

    describe "if there's an active snippet", ->

      beforeEach ->
        Mercury.snippet = Mercury.Snippet.all[0]

      it "updates the snippet", ->
        spy = spyOn(Mercury.Snippet.prototype, 'setOptions').andCallThrough()
        jasmine.simulate.click($('#submit').get(0))
        expect(spy.callCount).toEqual(1)
        expect(Mercury.Snippet.all[0]['options']).toEqual({first_name: 'Wilma', last_name: 'Flintstone'})

      it "triggers an action", ->
        spy = spyOn(Mercury, 'trigger').andCallFake(=>)
        jasmine.simulate.click($('#submit').get(0))
        expect(spy.callCount).toEqual(1)
        expect(spy.argsForCall[0]).toEqual(['action', {action: 'insertSnippet', value: Mercury.Snippet.all[0]}])

    describe "if there's no active snippet", ->

      it "creates a snippet", ->
        spy = spyOn(Mercury.Snippet, 'create').andCallThrough()
        jasmine.simulate.click($('#submit').get(0))
        expect(spy.callCount).toEqual(1)
        expect(Mercury.Snippet.all[1]['options']).toEqual({first_name: 'Wilma', last_name: 'Flintstone'})

      it "triggers an action", ->
        spy = spyOn(Mercury, 'trigger').andCallFake(=>)
        jasmine.simulate.click($('#submit').get(0))
        expect(spy.callCount).toEqual(1)
        expect(spy.argsForCall[0]).toEqual(['action', {action: 'insertSnippet', value: Mercury.Snippet.all[1]}])

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
kiteditor-1.0.25 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.24 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.23 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.22 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.21 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.20 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.19 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.18 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.17 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.16 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.14 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.13 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.11 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.10 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.9 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.8 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.7 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.6 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.5 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee
kiteditor-1.0.4 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee