aboutsummaryrefslogtreecommitdiff
path: root/js/tests/unit/util/config.spec.js
blob: dc14c1fdb74df2044ff41a5159ea3b3810cadba6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import Config from '../../../src/util/config'

class DummyConfigClass extends Config {
  static get NAME() {
    return 'dummy'
  }
}

describe('Config', () => {
  const name = 'dummy'
  describe('NAME', () => {
    it('should return plugin NAME', () => {
      expect(DummyConfigClass.NAME).toEqual(name)
    })
  })

  describe('DefaultType', () => {
    it('should return plugin default type', () => {
      expect(DummyConfigClass.DefaultType).toEqual(undefined)
      expect(new DummyConfigClass()._getConfigDefaultType()).toEqual(jasmine.any(Object))
    })
  })

  describe('Default', () => {
    it('should return plugin defaults', () => {
      expect(DummyConfigClass.Default).toEqual(jasmine.any(Object))
    })
  })

  describe('typeCheckConfig', () => {
    it('should check type of the config object', () => {
      const obj = new DummyConfigClass()
      spyOn(obj, '_getConfigDefaultType').and.returnValue({
        toggle: 'boolean',
        parent: '(string|element)'
      })
      const config = {
        toggle: true,
        parent: 777
      }

      expect(() => {
        obj._typeCheckConfig(config)
      }).toThrowError(TypeError, obj.constructor.NAME.toUpperCase() + ': Option "parent" provided type "number" but expected type "(string|element)".')
    })

    it('should return null stringified when null is passed', () => {
      const obj = new DummyConfigClass()
      spyOn(obj, '_getConfigDefaultType').and.returnValue({
        toggle: 'boolean',
        parent: '(null|element)'
      })
      const config = {
        toggle: true,
        parent: null
      }

      obj._typeCheckConfig(config)
      expect().nothing()
    })

    it('should return undefined stringified when undefined is passed', () => {
      const obj = new DummyConfigClass()
      spyOn(obj, '_getConfigDefaultType').and.returnValue({
        toggle: 'boolean',
        parent: '(undefined|element)'
      })
      const config = {
        toggle: true,
        parent: undefined
      }

      obj._typeCheckConfig(config)
      expect().nothing()
    })
  })
})