Browse Source

Improve symbol tests

symbols-2
Artur Arseniev 6 years ago
parent
commit
7a2a916c4f
  1. 23
      test/specs/dom_components/model/Symbols.js

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

@ -120,6 +120,13 @@ describe('Symbols', () => {
describe('Creating 3 symbols in the wrapper', () => { describe('Creating 3 symbols in the wrapper', () => {
let allInst, all, comp, symbol, compInitChild; let allInst, all, comp, symbol, compInitChild;
const getFirstInnSymbol = cmp =>
cmp
.components()
.at(0)
.__getSymbol();
beforeEach(() => { beforeEach(() => {
comp = wrapper.append(compMultipleNodes)[0]; comp = wrapper.append(compMultipleNodes)[0];
compInitChild = comp.components().length; compInitChild = comp.components().length;
@ -149,13 +156,18 @@ describe('Symbols', () => {
); );
// Check symbol references // Check symbol references
expect(added.__getSymbols().length).toBe(allInst.length); expect(added.__getSymbols().length).toBe(allInst.length);
allInst.forEach(cmp => expect(getFirstInnSymbol(cmp)).toBe(added));
}); });
test('Adding a new component to an instance of the symbol, it will be propogated to all symbols', () => { test('Adding a new component to an instance of the symbol, it will be propogated to all symbols', () => {
comp.append(simpleComp, { at: 0 })[0]; const added = comp.append(simpleComp, { at: 0 })[0];
all.forEach(cmp => all.forEach(cmp =>
expect(cmp.components().length).toBe(compInitChild + 1) expect(cmp.components().length).toBe(compInitChild + 1)
); );
// Check symbol references
const addSymb = added.__getSymbol();
expect(symbol.components().at(0)).toBe(addSymb);
allInst.forEach(cmp => expect(getFirstInnSymbol(cmp)).toBe(addSymb));
}); });
test('Moving a new added component in the instance, will propagate the action in all symbols', () => { test('Moving a new added component in the instance, will propagate the action in all symbols', () => {
@ -166,14 +178,7 @@ describe('Symbols', () => {
// All symbols still have the same amount of components // All symbols still have the same amount of components
all.forEach(cmp => expect(cmp.components().length).toBe(newChildLen)); all.forEach(cmp => expect(cmp.components().length).toBe(newChildLen));
// All instances refer to the same symbol // All instances refer to the same symbol
allInst.forEach(cmp => allInst.forEach(cmp => expect(getFirstInnSymbol(cmp)).toBe(symbRef));
expect(
cmp
.components()
.at(0)
.__getSymbol()
).toBe(symbRef)
);
// The moved symbol contains all its instances // The moved symbol contains all its instances
expect( expect(
symbol symbol

Loading…
Cancel
Save