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

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

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

Loading…
Cancel
Save