Browse Source

Update symbols tests

symbols-2
Artur Arseniev 5 years ago
parent
commit
7aef99ec55
  1. 86
      src/dom_components/model/Component.js
  2. 10
      test/specs/dom_components/model/Symbols.js

86
src/dom_components/model/Component.js

@ -672,17 +672,17 @@ const Component = Backbone.Model.extend(Styleable).extend(
if (!o) {
// Reset
!this.opt.temporary &&
console.log(
'Reset cid',
this.cid,
o,
'isSymb',
this.__isSymbol(),
'symbToUp',
this.__getSymbToUp(toUpOpts),
{ toUpOpts }
);
// !this.opt.temporary &&
// console.log(
// 'Reset cid',
// this.cid,
// o,
// 'isSymb',
// this.__isSymbol(),
// 'symbToUp',
// this.__getSymbToUp(toUpOpts),
// { toUpOpts }
// );
this.__getSymbToUp(toUpOpts).forEach(symb => {
const newMods = m.models.map(mod => mod.clone({ symbol: 1 }));
symb.components().reset(newMods, { fromInstance: this, ...c });
@ -690,17 +690,17 @@ const Component = Backbone.Model.extend(Styleable).extend(
} else if (o.add) {
// Add
const addedInstances = m.__getSymbToUp(toUpOpts);
!m.opt.temporary &&
console.log(
`Added cid ${m.cid} (symb: ${m.__isSymbol()}) in ${
this.cid
} (symb: ${this.__isSymbol()})`,
'SymbToUp added',
addedInstances,
'symbToUp',
this.__getSymbToUp(toUpOpts),
{ toUpOpts }
);
// !m.opt.temporary &&
// console.log(
// `Added cid ${m.cid} (symb: ${m.__isSymbol()}) in ${
// this.cid
// } (symb: ${this.__isSymbol()})`,
// 'SymbToUp added',
// addedInstances,
// 'symbToUp',
// this.__getSymbToUp(toUpOpts),
// { toUpOpts }
// );
// Here, before appending new symbol, I have to ensure there no already previosly
// created symbol (eg. used mainly when drag components around)
this.__getSymbToUp(toUpOpts).forEach(symb => {
@ -722,31 +722,31 @@ const Component = Backbone.Model.extend(Styleable).extend(
// !m.opt.temporary && console.log('Exit, fromInstance === symb', fromInstance, 'toAppend', appended, symbMain.get('__symbol'))
// return;
// }
!m.opt.temporary &&
console.log(
'Added inner',
toAppend.cid,
'of',
symb.cid,
`(symb ${symb.__isSymbol()})`,
{ symb, symbPrev, toAppend }
);
// !m.opt.temporary &&
// console.log(
// 'Added inner',
// toAppend.cid,
// 'of',
// symb.cid,
// `(symb ${symb.__isSymbol()})`,
// { symb, symbPrev, toAppend }
// );
symb.append(toAppend, { fromInstance: this, toAppend: m, ...o });
});
} else {
// Remove
!m.opt.temporary &&
console.log(
'Remove cid',
m.cid,
m.toHTML(),
o,
'isSymb',
m.__isSymbol(),
'symbToUp',
m.__getSymbToUp(toUpOpts),
{ toUpOpts }
);
// !m.opt.temporary &&
// console.log(
// 'Remove cid',
// m.cid,
// m.toHTML(),
// o,
// 'isSymb',
// m.__isSymbol(),
// 'symbToUp',
// m.__getSymbToUp(toUpOpts),
// { toUpOpts }
// );
const symbToUp = m.__getSymbToUp(toUpOpts);
!m.__isSymbolTop() &&
symbToUp.forEach(symb => symb.remove({ fromInstance: m, ...o }));

10
test/specs/dom_components/model/Symbols.js

@ -21,12 +21,9 @@ describe('Symbols', () => {
editor.destroy();
});
beforeEach(() => {
console.log('Symbols before each');
});
beforeEach(() => {});
afterEach(() => {
console.log('Symbols after each');
wrapper.components().reset();
});
@ -80,10 +77,11 @@ describe('Symbols', () => {
const comp = wrapper.append(simpleComp)[0];
const symbol = createSymbol(comp);
const comp2 = createSymbol(comp);
wrapper.append(symbol);
wrapper.append(comp2);
expect(wrapper.components().length).toBe(2);
expect(wrapper.components().length).toBe(3);
comp.remove();
expect(wrapper.components().length).toBe(1);
expect(wrapper.components().length).toBe(2);
expect(comp2.__getSymbol()).toBe(symbol);
});

Loading…
Cancel
Save