import Microcosm from '../../../src/microcosm'

describe('Domain construction', function() {
  it('object - primitive', function() {
    const repo = new Microcosm()

    repo.addDomain('count', {
      getInitialState() {
        return 0
      }
    })

    expect(repo).toHaveState('count', 0)
  })

  it('object - original primitive is not mutated', function() {
    const repo = new Microcosm()

    const MyDomain = {
      getInitialState() {
        return 0
      }
    }

    repo.addDomain('count', MyDomain)

    expect(MyDomain.setup).toBeUndefined()
  })

  it('class - simple', function() {
    const repo = new Microcosm()

    class Counter {
      getInitialState() {
        return 0
      }
    }

    repo.addDomain('count', Counter)

    expect(repo).toHaveState('count', 0)
  })

  it('class - with defaults', function() {
    expect.assertions(1)

    const repo = new Microcosm()

    class Counter {
      static defaults = {
        start: 0
      }

      setup(repo, options) {
        expect(options.start).toBe(0)
      }
    }

    repo.addDomain('count', Counter)
  })

  it('class - draw from Microcosm options', function() {
    expect.assertions(1)

    const repo = new Microcosm({ debug: true })

    class Counter {
      setup(repo, options) {
        expect(options.debug).toBe(true)
      }
    }

    repo.addDomain('count', Counter)
  })

  it('class - with defaults override Microcosm options', function() {
    expect.assertions(1)

    const repo = new Microcosm({ debug: true })

    class Counter {
      static defaults = {
        debug: false
      }

      setup(repo, options) {
        expect(options.debug).toBe(false)
      }
    }

    repo.addDomain('count', Counter)
  })

  it('class - with passed options override defaults', function() {
    expect.assertions(1)

    const repo = new Microcosm({ count: 0 })

    class Counter {
      static defaults = {
        count: 1
      }

      setup(repo, options) {
        expect(options.count).toBe(2)
      }
    }

    repo.addDomain('count', Counter, { count: 2 })
  })

  it('passes the mount key to options', function() {
    expect.assertions(1)

    const repo = new Microcosm({ count: 0 })

    class Counter {
      static defaults = {
        count: 1
      }

      setup(repo, options) {
        expect(options.key).toBe('count')
      }
    }

    repo.addDomain('count', Counter, { count: 2 })
  })
})

@@ -2190,94 +2190,40 @@
 osm(
-%7B count: 0 %7D)%0A%0A    class Counter %7B%0A      static defaults = %7B%0A        count: 1%0A      %7D%0A
+)%0A%0A    repo.addDomain('count', %7B
 %0A   
@@ -2307,59 +2307,8 @@
    %7D
-%0A%0A    repo.addDomain('count', Counter, %7B count: 2 %7D
 )%0A  

Simplify key option test