import { expect } from 'chai'
import G11N from 'g11n'
import sinon from 'sinon'

describe('G11N', () => {
  const g11n = new G11N()

  beforeEach(() => {
    sinon.stub(window, 'fetch')

    const res = new window.Response('{"hello":"world"}', {
      status: 200,
      headers: {
        'Content-type': 'application/json'
      }
    })

    window.fetch.returns(Promise.resolve(res))
  })

  afterEach(() => {
    window.fetch.restore()
  })

  describe('imports()', () => {
    it('should get locale json file', (done) => {
      // mock
      g11n.imports({
        files: ['test.json']
      })

      setTimeout(() => {
        done()
      }, 500)
    })
  })

  describe('t()', () => {
    it('should get empty string', () => {
      expect(g11n.t('OOXX')).to.be.equal('')
    })

    it('should get locale string', () => {
      expect(g11n.t('hello')).to.be.equal('world')
    })
  })

  describe('render()', () => {
    it('should get empty string', () => {
      expect(g11n.render('{%hello%}!!')).to.be.equal('world!!')
    })
  })
})

@@ -937,32 +937,49 @@
 'should 
-get empty string
+render string with placehold type
 ', () =%3E
@@ -1007,16 +1007,20 @@
 render('
+the 
 %7B%25hello%25
@@ -1020,18 +1020,26 @@
 %25hello%25%7D
-!!
+ is beauty
 ')).to.b
@@ -1051,15 +1051,27 @@
 al('
+the 
 world
-!!
+ is beauty
 ')%0A 

Update test