|
| 1 | +import Mediator from '../../../src/scripts/core/Mediator'; |
| 2 | +import Config from '../../../src/scripts/modules/Config'; |
| 3 | + |
| 4 | +import toolbarConfig from '../../../src/scripts/config/toolbar'; |
| 5 | + |
| 6 | +describe('modules/Config', function () { |
| 7 | + let mediator; |
| 8 | + const toolbarConfigsKeysStrings = function (config, source) { |
| 9 | + const configKeysString = JSON.stringify(config.buttons.map((buttonConfig) => buttonConfig.configKey)); |
| 10 | + const sourceKeysString = JSON.stringify(source); |
| 11 | + return [ |
| 12 | + config.buttons.length, |
| 13 | + source.length, |
| 14 | + configKeysString, |
| 15 | + sourceKeysString |
| 16 | + ]; |
| 17 | + }; |
| 18 | + |
| 19 | + beforeEach(() => { |
| 20 | + mediator = new Mediator(); |
| 21 | + }); |
| 22 | + |
| 23 | + afterEach(() => { |
| 24 | + mediator = null; |
| 25 | + }); |
| 26 | + |
| 27 | + it('should return toolbar buttons from default toolbar config', () => { |
| 28 | + new Config({ mediator }); |
| 29 | + const toolbarButtons = mediator.get('config:toolbar:buttons'); |
| 30 | + const [ |
| 31 | + configLength, |
| 32 | + sourceLength, |
| 33 | + configKeysString, |
| 34 | + sourceKeysString |
| 35 | + ] = toolbarConfigsKeysStrings(toolbarButtons, toolbarConfig.buttons); |
| 36 | + |
| 37 | + expect(configLength).toBe(sourceLength); |
| 38 | + expect(configKeysString).toBe(sourceKeysString); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should return toolbar buttons from given custom config', () => { |
| 42 | + const customToolbarConfig = ['bold', 'h1', 'link']; |
| 43 | + new Config({ |
| 44 | + mediator, |
| 45 | + configs: { |
| 46 | + toolbar: { |
| 47 | + buttons: customToolbarConfig |
| 48 | + } |
| 49 | + } |
| 50 | + }); |
| 51 | + const toolbarButtons = mediator.get('config:toolbar:buttons'); |
| 52 | + const [ |
| 53 | + configLength, |
| 54 | + sourceLength, |
| 55 | + configKeysString, |
| 56 | + sourceKeysString |
| 57 | + ] = toolbarConfigsKeysStrings(toolbarButtons, customToolbarConfig); |
| 58 | + |
| 59 | + expect(configLength).toBe(sourceLength); |
| 60 | + expect(configKeysString).toBe(sourceKeysString); |
| 61 | + }); |
| 62 | +}); |
0 commit comments