Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(`should insert the view before the refNode under the parent of the refNode (depth=${depth},width=${width})`, function () {
const node = ctx.dom.createElement('div');
const fragment = createFragment(ctx, node, 0, depth, width);
sut = new FragmentNodeSequence(ctx.dom, fragment);
const parent = ctx.dom.createElement('div');
const ref1 = ctx.dom.createElement('div');
const ref2 = ctx.dom.createElement('div');
parent.appendChild(ref1);
parent.appendChild(ref2);
sut.insertBefore(ref2);
assert.strictEqual(parent.childNodes.length, width + 2, `parent.childNodes.length`);
assert.strictEqual(fragment.childNodes.length, 0, `fragment.childNodes.length`);
assert.strictEqual(parent.childNodes.item(0) === ref1, true, `parent.childNodes.item(0) === ref1`);
let i = 0;
while (i < width) {
assert.strictEqual(parent.childNodes.item(i + 1) === sut.childNodes[i], true, `parent.childNodes.item(i + 1) === sut.childNodes[i]`);
i++;
}
assert.strictEqual(parent.childNodes.item(width + 1) === ref2, true, `parent.childNodes.item(width + 1) === ref2`);
assert.strictEqual(fragment.childNodes.length, 0, `fragment.childNodes.length`);
it(`should put the view back into the fragment (depth=${depth},width=${width})`, function () {
const node = ctx.dom.createElement('div');
const fragment = createFragment(ctx, node, 0, depth, width);
sut = new FragmentNodeSequence(ctx.dom, fragment);
const parent = ctx.dom.createElement('div');
assert.strictEqual(parent.childNodes.length, 0, `parent.childNodes.length`);
assert.strictEqual(fragment.childNodes.length, width, `fragment.childNodes.length`);
parent.appendChild(fragment);
assert.strictEqual(parent.childNodes.length, width, `parent.childNodes.length`);
assert.strictEqual(fragment.childNodes.length, 0, `fragment.childNodes.length`);
sut.remove();
assert.strictEqual(parent.childNodes.length, 0, `parent.childNodes.length`);
assert.strictEqual(fragment.childNodes.length, width, `fragment.childNodes.length`);
});
}
it(`should correctly assign children (depth=1,width=${width})`, function () {
const node = ctx.dom.createElement('div');
const fragment = createFragment(ctx, node, 0, 1, width);
sut = new FragmentNodeSequence(ctx.dom, fragment);
assert.strictEqual(sut.childNodes.length, width, `sut.childNodes.length`);
assert.strictEqual(sut.childNodes[0] === sut.firstChild, true, `sut.childNodes[0] === sut.firstChild`);
assert.strictEqual(sut.childNodes[width - 1] === sut.lastChild, true, `sut.childNodes[width - 1] === sut.lastChild`);
});
}
it(`should return empty array when there are no targets (depth=${depth},width=${width})`, function () {
const node = ctx.dom.createElement('div');
const fragment = createFragment(ctx, node, 0, depth, width);
sut = new FragmentNodeSequence(ctx.dom, fragment);
const actual = sut.findTargets();
assert.strictEqual(actual.length, 0, `actual.length`);
});
it(`should append the view to the parent (depth=${depth},width=${width})`, function () {
const node = ctx.dom.createElement('div');
const fragment = createFragment(ctx, node, 0, depth, width);
sut = new FragmentNodeSequence(ctx.dom, fragment);
const parent = ctx.dom.createElement('div');
sut.appendTo(parent);
assert.strictEqual(parent.childNodes.length, width, `parent.childNodes.length`);
assert.strictEqual(fragment.childNodes.length, 0, `fragment.childNodes.length`);
let i = 0;
while (i < width) {
assert.strictEqual(parent.childNodes.item(i) === sut.childNodes[i], true, `parent.childNodes.item(i) === sut.childNodes[i]`);
i++;
}
});
}