Skip to content

Commit fa15931

Browse files
committed
#24 - Tests for the new Config module
1 parent 54a5582 commit fa15931

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
lines changed

src/scripts/core/Module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const Module = function (moduleObj) {
224224
let moduleConfigs = {};
225225

226226
moduleAcceptsConfigs.forEach((configKey) => {
227-
moduleConfigs[configKey] = optsConfigs[configKey] || {}
227+
moduleConfigs[configKey] = optsConfigs[configKey] || {};
228228
});
229229

230230
context.extendWith({ configs: moduleConfigs });

src/scripts/modules/Config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const Config = Module({
1616

1717
methods: {
1818
setup () {},
19-
init () {
20-
},
19+
init () {},
2120

2221
getToolbarButtons () {
2322
const { mediator, configs } = this;

src/scripts/utils/DOM.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,8 @@ const DOM = {
537537

538538
cloneNodes (rootElem, opts={}) {
539539
let clonedNodes = [];
540+
540541
rootElem.childNodes.forEach((node) => {
541-
const clonedNode = node.cloneNode(true);
542542
clonedNodes.push(node.cloneNode(true));
543543
});
544544

test/unit/helpers/e2eSetup.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const e2eSetup = function () {
3131
new UIContainer({ mediator });
3232
new CanvasContainer({ mediator });
3333

34-
3534
return {
3635
mediator,
3736
editableEl

test/unit/modules/Config.spec.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)