Skip to content

Commit

Permalink
test: Add test case for rebuilding blocked elements
Browse files Browse the repository at this point in the history
Follow-up to #117 - adds a test case
  • Loading branch information
billyvg committed Oct 19, 2023
1 parent 84da5e3 commit 11b97cf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/rrdom/test/virtual-dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as path from 'path';
import * as puppeteer from 'puppeteer';
import { JSDOM } from 'jsdom';
import {
buildNodeWithSN,
cdataNode,
commentNode,
documentNode,
Expand Down Expand Up @@ -207,6 +208,30 @@ describe('RRDocument for browser environment', () => {
expect((rrNode as RRElement).tagName).toEqual('SHADOWROOT');
expect(rrNode).toBe(parentRRNode.shadowRoot);
});

it('can rebuild blocked element with correct dimensions', () => {
// @ts-expect-error Testing buildNodeWithSN with rr elements
const node = buildNodeWithSN({
id: 1,
tagName: 'svg',
type: NodeType.Element,
isSVG: true,
attributes: {
rr_width: '50px',
rr_height: '50px',
},
childNodes: [],
}, {
// @ts-expect-error
doc: new RRDocument(),
mirror,
blockSelector: '*',
slimDOMOptions: {},
}) as RRElement;

expect(node.style.width).toBe('50px');
expect(node.style.height).toBe('50px');
});
});

describe('create a RRDocument from a html document', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function buildNode(
},
): Node | null {
const { doc, hackCss, cache } = options;
console.log('buildNode');
switch (n.type) {
case NodeType.Document:
return doc.implementation.createDocument(null, '', null);
Expand Down
27 changes: 27 additions & 0 deletions packages/rrweb-snapshot/test/rebuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ describe('rebuild', function () {
});
});

describe('rr_width/rr_height', function () {
it('rebuild blocked element with correct dimensions', function () {
const node = buildNodeWithSN(
{
id: 1,
tagName: 'svg',
type: NodeType.Element,
isSVG: true,
attributes: {
rr_width: '50px',
rr_height: '50px',
},
childNodes: [
],
},
{
doc: document,
mirror,
hackCss: false,
cache,
},
) as HTMLDivElement;
expect(node.style.width).toBe('50px');
expect(node.style.height).toBe('50px');
});
});

describe('shadowDom', function () {
it('rebuild shadowRoot without siblings', function () {
const node = buildNodeWithSN(
Expand Down

0 comments on commit 11b97cf

Please sign in to comment.