|
|
|
@ -31,6 +31,13 @@ describe('Symbols', () => { |
|
|
|
|
|
|
|
let allInst, all, comp, symbol, compInitChild; |
|
|
|
let secComp, secSymbol; |
|
|
|
const toHTML = cmp => |
|
|
|
cmp.toHTML({ |
|
|
|
attributes: (m, attr) => { |
|
|
|
delete attr.id; |
|
|
|
return attr; |
|
|
|
} |
|
|
|
}); |
|
|
|
const getUm = cmp => cmp.em.get('UndoManager'); |
|
|
|
const getInnerComp = (cmp, i = 0) => cmp.components().at(i); |
|
|
|
const getFirstInnSymbol = cmp => getInnerComp(cmp).__getSymbol(); |
|
|
|
@ -42,14 +49,8 @@ describe('Symbols', () => { |
|
|
|
cFrom.components(`New text content ${rand}`); |
|
|
|
const toAttr = cTo.getAttributes(); |
|
|
|
delete toAttr.id; |
|
|
|
const htmlOpts = { |
|
|
|
attributes: (m, attr) => { |
|
|
|
delete attr.id; |
|
|
|
return attr; |
|
|
|
} |
|
|
|
}; |
|
|
|
expect(toAttr).toEqual(newAttr); |
|
|
|
expect(cFrom.toHTML(htmlOpts)).toBe(cTo.toHTML(htmlOpts)); |
|
|
|
expect(toHTML(cFrom)).toBe(toHTML(cTo)); |
|
|
|
}; |
|
|
|
|
|
|
|
beforeAll(() => { |
|
|
|
@ -89,7 +90,7 @@ describe('Symbols', () => { |
|
|
|
expect(comp.__getSymbol()).toBe(symbol); |
|
|
|
expect(symbs.length).toBe(1); |
|
|
|
expect(symbs[0]).toBe(comp); |
|
|
|
expect(comp.toHTML()).toBe(symbol.toHTML()); |
|
|
|
expect(toHTML(comp)).toBe(toHTML(symbol)); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Create 1 symbol and clone the instance for another one', () => { |
|
|
|
@ -101,7 +102,7 @@ describe('Symbols', () => { |
|
|
|
expect(symbs[0]).toBe(comp); |
|
|
|
expect(symbs[1]).toBe(comp2); |
|
|
|
expect(comp2.__getSymbol()).toBe(symbol); |
|
|
|
expect(comp2.toHTML()).toBe(symbol.toHTML()); |
|
|
|
expect(toHTML(comp2)).toBe(toHTML(symbol)); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Create 1 symbol and clone it to have another instance', () => { |
|
|
|
@ -113,7 +114,7 @@ describe('Symbols', () => { |
|
|
|
expect(symbs[0]).toBe(comp); |
|
|
|
expect(symbs[1]).toBe(comp2); |
|
|
|
expect(comp2.__getSymbol()).toBe(symbol); |
|
|
|
expect(comp2.toHTML()).toBe(symbol.toHTML()); |
|
|
|
expect(toHTML(comp2)).toBe(toHTML(symbol)); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Symbols and instances are correctly serialized', () => { |
|
|
|
@ -354,8 +355,8 @@ describe('Symbols', () => { |
|
|
|
expect(attrs[attrKey2]).toBe(attrValue2); |
|
|
|
}); |
|
|
|
// All symbols still have the same HTML
|
|
|
|
const symbHtml = symbol.toHTML(); |
|
|
|
all.forEach(cmp => expect(cmp.toHTML()).toBe(symbHtml)); |
|
|
|
const symbHtml = toHTML(symbol); |
|
|
|
all.forEach(cmp => expect(toHTML(cmp)).toBe(symbHtml)); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Cloning a component in an instance, reflects changes to all symbols', () => { |
|
|
|
@ -468,7 +469,7 @@ describe('Symbols', () => { |
|
|
|
symbol.components('Test text'); |
|
|
|
// The symbol has changed, but istances should remain the same
|
|
|
|
expect(symbol.components().length).toBe(1); |
|
|
|
allInst.forEach(cmp => expect(cmp.toHTML()).toBe(comp.toHTML())); |
|
|
|
allInst.forEach(cmp => expect(toHTML(cmp)).toBe(toHTML(comp))); |
|
|
|
allInst.forEach(cmp => |
|
|
|
expect(cmp.components().length).toBe(innCompsLen) |
|
|
|
); |
|
|
|
@ -564,7 +565,7 @@ describe('Symbols', () => { |
|
|
|
expect(secComp.__getSymbol()).toBe(secSymbol); |
|
|
|
expect(symbs.length).toBe(1); |
|
|
|
expect(symbs[0]).toBe(secComp); |
|
|
|
expect(secComp.toHTML()).toBe(secSymbol.toHTML()); |
|
|
|
expect(toHTML(secComp)).toBe(toHTML(secSymbol)); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Adding the instance, of the second symbol, inside the first symbol, propagates correctly to all first instances', () => { |
|
|
|
|