text: /* eslint-env mocha */
  import { moduleState, state } from '../tags'
  
  import App from '../'
  import assert from 'assert'
  
  describe('store', () => {
    it('should be able to SET state', () => {
      const rootModule = {
        state: {
          foo: 'bar',
        },
        sequences: {
          foo: [({ store }) => store.set('foo', 'bar2')],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: 'bar2' })
    })
    it('should work whith module tag', () => {
      const rootModule = {
        state: {
          foo: ['foo'],
        },
        sequences: {
          foo: [({ store }) => store.concat(moduleState`foo`, ['bar'])],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: ['foo', 'bar'] })
    })
    it('should be able to SET state with an array in the path', () => {
      const rootModule = {
        state: { foo: ['bar'] },
        sequences: {
          foo: [({ store }) => store.set(state`foo.0`, 'baz')],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: ['baz'] })
    })
    it('should be able to TOGGLE state', () => {
      const rootModule = {
        state: { foo: false },
        sequences: {
          foo: [({ store }) => store.toggle(state`foo`)],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: true })
    })
    it('should be able to PUSH state', () => {
      const rootModule = {
        state: {
          foo: ['foo'],
        },
        sequences: {
          foo: [({ store }) => store.push(state`foo`, 'bar')],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: ['foo', 'bar'] })
    })
    it('should be able to MERGE state', () => {
      const rootModule = {
        state: {
          foo: { foo: 'bar' },
        },
        sequences: {
          foo: [({ store }) => store.merge(state`foo`, { foo2: 'bar2' })],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), {
        foo: { foo: 'bar', foo2: 'bar2' },
      })
    })
    it('should be able to POP state', () => {
      const rootModule = {
        state: {
          foo: ['foo', 'bar'],
        },
        sequences: {
          foo: [({ store }) => store.pop(state`foo`)],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: ['foo'] })
    })
    it('should be able to SHIFT state', () => {
      const rootModule = {
        state: {
          foo: ['foo', 'bar'],
        },
        sequences: {
          foo: [({ store }) => store.shift(state`foo`)],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: ['bar'] })
    })
    it('should be able to UNSHIFT state', () => {
      const rootModule = {
        state: {
          foo: ['foo'],
        },
        sequences: {
          foo: [({ store }) => store.unshift(state`foo`, 'bar')],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: ['bar', 'foo'] })
    })
    it('should be able to SPLICE state', () => {
      const rootModule = {
        state: {
          foo: ['foo'],
        },
        sequences: {
          foo: [({ store }) => store.splice(state`foo`, 0, 1, 'bar')],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: ['bar'] })
    })
    it('should be able to UNSET state', () => {
      const rootModule = {
        state: {
          foo: 'bar',
        },
        sequences: {
          foo: [({ store }) => store.unset(state`foo`)],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), {})
    })
    it('should be able to CONCAT state', () => {
      const rootModule = {
        state: {
          foo: ['foo'],
        },
        sequences: {
          foo: [({ store }) => store.concat(state`foo`, ['bar'])],
        },
      }
      const controller = App(rootModule)
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: ['foo', 'bar'] })
    })
    it('should provide a descriptive error when passing invalid value to state', () => {
      const rootModule = {
        state: {
          foo: '',
        },
        sequences: {
          foo: [({ store }) => store.set(state`foo`, () => {})],
        },
      }
      const controller = App(rootModule, {
        devtools: { init() {}, sendExecutionData() {} },
      })
      assert.throws(() => {
        controller.getSequence('foo')()
      }, Error)
    })
    it('should work with devtools', () => {
      const rootModule = {
        state: {
          foo: ['foo'],
        },
        sequences: {
          foo: [({ store }) => store.splice(state`foo`, 0, 1, 'bar')],
        },
      }
      const controller = App(rootModule, {
        devtools: { init() {}, send() {}, sendExecutionData() {} },
      })
      controller.getSequence('foo')()
      assert.deepEqual(controller.getState(), { foo: ['bar'] })
    })
  })
  