Sha256: 58eab85bbc49b9f64189d6b5d35083150acdf9ce148856cc64911d48632661ae

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

describe "Mercury.modalHandlers.insertSnippet", ->

  beforeEach ->
    fixture.load('mercury/modals/insertsnippet.html')
    Mercury.Snippet.all = []
    Mercury.Snippet.load({
      'snippet_0': {name: 'foo', options: {'first_name': "Jeremy", 'last_name': "Jackson"}},
    })
    @modal =
      element: $(fixture.el)
      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

1 entries across 1 versions & 1 rubygems

Version Path
kiteditor-1.0.12 spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee