import assert from 'assert'
import MarkdownIt from 'markdown-it'
import IncrementalDOM from 'incremental-dom'
import MarkdownItIncrementalDOM from '../src/markdown-it-incremental-dom'

describe('markdown-it-incremental-dom', () => {
  const md = () => MarkdownIt().use(MarkdownItIncrementalDOM, IncrementalDOM)

  describe('markdownIt().use', () => {
    context('when Incremental DOM argument is omitted', () => {
      afterEach(() => { delete window.IncrementalDOM })

      it('fails injection if window.IncrementalDOM is not defined', () => {
        assert.throws(() => MarkdownIt().use(MarkdownItIncrementalDOM))
      })

      it('succeeds injection if window.IncrementalDOM is defined', () => {
        window = { IncrementalDOM }
        assert.doesNotThrow(() => MarkdownIt().use(MarkdownItIncrementalDOM))
      })
    })
  })

  describe('.renderToIncrementalDOM', () => {
    it('returns patchable function by specified Incremental DOM', () => {
      const func = md().renderToIncrementalDOM('markdown-it-incremental-dom')

      IncrementalDOM.patch(document.body, func)
      assert(document.body.innerHTML === '<p>markdown-it-incremental-dom</p>')
    })
  })

  describe('.renderInlineToIncrementalDOM', () => {
    it('returns patchable function by specified Incremental DOM', () => {
      const func = md().renderInlineToIncrementalDOM('markdown-it-incremental-dom')

      IncrementalDOM.patch(document.body, func)
      assert(document.body.innerHTML === 'markdown-it-incremental-dom')
    })
  })
})

@@ -32,36 +32,25 @@
 ort 
-MarkdownIt from 'markdown-it
+sinon from 'sinon
 '%0Aim
@@ -92,16 +92,90 @@
 al-dom'%0A
+import MarkdownIt from 'markdown-it'%0Aimport %7B Parser %7D from 'htmlparser2'%0A
 import M
@@ -303,16 +303,25 @@
 t md = (
+opts = %7B%7D
 ) =%3E Mar
@@ -374,16 +374,22 @@
 entalDOM
+, opts
 )%0A%0A  des
@@ -812,16 +812,16 @@
 alDOM %7D%0A
-
         
@@ -897,32 +897,1058 @@
 %0A      %7D)%0A    %7D)
+%0A%0A    context('with option', () =%3E %7B%0A      describe('incrementalizeDefaultRules property', () =%3E %7B%0A        let spy%0A%0A        beforeEach(() =%3E %7B spy = sinon.spy(Parser.prototype, 'write') %7D)%0A        afterEach(() =%3E spy.restore())%0A%0A        const mdString = '%60code_inline%60'%0A        const expectedHTML = '%3Ccode%3Ecode_inline%3C/code%3E'%0A%0A        context('when it is false', () =%3E %7B%0A          it('parses HTML string by htmlparser2', () =%3E %7B%0A            const func = md(%7B incrementalizeDefaultRules: false %7D).renderInlineToIncrementalDOM(mdString)%0A%0A            IncrementalDOM.patch(document.body, func)%0A            assert(spy.calledWith(expectedHTML))%0A          %7D)%0A        %7D)%0A%0A        context('when it is true', () =%3E %7B%0A          it('does not parse HTML string in overridden rule', () =%3E %7B%0A            const func = md(%7B incrementalizeDefaultRules: true %7D).renderInlineToIncrementalDOM(mdString)%0A%0A            IncrementalDOM.patch(document.body, func)%0A            assert(!spy.calledWith(expectedHTML))%0A          %7D)%0A        %7D)%0A      %7D)%0A    %7D)
 %0A  %7D)%0A%0A  describ

Add test of the initialize with option