Skip to content

Commit

Permalink
chore: Fix video tests
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Sep 5, 2024
1 parent a82378a commit fa2095b
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 113 deletions.
2 changes: 1 addition & 1 deletion src/transform/plugins/video/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function tokenizeVideo(md: MarkdownIt, options: VideoFullOptions): Renderer.Rend
` class="embed-responsive-item ${service}-player"` +
` type="text/html" width="${width}" height="${height}"` +
` src="${options.url(service, videoID, options)}"` +
`frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>`;
` frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>`;
};
}

Expand Down
126 changes: 126 additions & 0 deletions test/__snapshots__/video.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`md-video-mfr make sure normal iframe generates properly when empty 1`] = `
<p>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with guid 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with guid and extra space 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with guid and line break 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with guid and two extra spaces 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with link 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with link and extra space 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with link and two extra spaces 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with link to local 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "https://localhost:7778/render?url=https://localhost:5000/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with link to local ip 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "http://localhost:7778/render?mode=render&amp;url=http://192.168.168.167:5000/y98tn/?action=download%26mode=render%26direct"); });
</script>
</p>
`;

exports[`md-video-mfr make sure normal iframe generates properly with link to staging 1`] = `
<p>
<div id="1.2"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("1.2", "https://mfr-staging3.osf.io/render?url=https://staging3.osf.io/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;
157 changes: 45 additions & 112 deletions test/video.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import MarkdownIt from 'markdown-it';
import video from '../src/transform/plugins/video/index';

const generate = require('markdown-it-testgen');
const assert = require('assert');

// eslint-disable-next-line no-implicit-globals
function getMfrId(html: string) {
return html.split('"')[1];
function preserveId(html: string) {
return html
.replace(/<div id="\d+.\d+"/, '<div id="1.2"')
.replace(/new mfr\.Render\("\d+.\d+"/, 'new mfr.Render("1.2"');
}

describe('md-video', function () {
Expand All @@ -22,149 +22,82 @@ describe('md-video-mfr', function () {
const md = new MarkdownIt({}).use(video);

it('make sure normal iframe generates properly when empty', function () {
const renderedHtml = md.render('@[osf]()');
assert.equal(renderedHtml, '<p></p>\n');
const renderedHtml = preserveId(md.render('@[osf]()'));
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with guid', function () {
const renderedHtml = md.render('@[osf](xxxxx)');
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
);
const renderedHtml = preserveId(md.render('@[osf](xxxxx)'));
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with guid and line break', function () {
const renderedHtml = md.render('@[osf](xxxxx\n)');
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
);
const renderedHtml = preserveId(md.render('@[osf](xxxxx\n)'));
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with guid and extra space', function () {
const renderedHtml = md.render('@[osf](xxxxx )');
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
);
const renderedHtml = preserveId(md.render('@[osf](xxxxx )'));
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with guid and two extra spaces', function () {
const renderedHtml = md.render('@[osf]( xxxxx )');
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
);
const renderedHtml = preserveId(md.render('@[osf]( xxxxx )'));
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with link', function () {
const renderedHtml = md.render(
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render)',
);
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
const renderedHtml = preserveId(
md.render(
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render)',
),
);
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with link and extra space', function () {
const renderedHtml = md.render(
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render )',
);
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
const renderedHtml = preserveId(
md.render(
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render )',
),
);
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with link and two extra spaces', function () {
const renderedHtml = md.render(
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render )',
);
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
const renderedHtml = preserveId(
md.render(
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render )',
),
);
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with link to staging', function () {
const renderedHtml = md.render(
'@[osf](https://mfr-staging3.osf.io/render?url=https://staging3.osf.io/xxxxx/?action=download%26mode=render)',
);
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "https://mfr-staging3.osf.io/render?url=https://staging3.osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
const renderedHtml = preserveId(
md.render(
'@[osf](https://mfr-staging3.osf.io/render?url=https://staging3.osf.io/xxxxx/?action=download%26mode=render)',
),
);
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with link to local', function () {
const renderedHtml = md.render(
'@[osf](https://localhost:7778/render?url=https://localhost:5000/xxxxx/?action=download%26mode=render)',
);
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "https://localhost:7778/render?url=https://localhost:5000/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
const renderedHtml = preserveId(
md.render(
'@[osf](https://localhost:7778/render?url=https://localhost:5000/xxxxx/?action=download%26mode=render)',
),
);
expect(renderedHtml).toMatchSnapshot();
});

it('make sure normal iframe generates properly with link to local ip', function () {
const renderedHtml = md.render(
'@[osf](http://localhost:7778/render?mode=render&url=http://192.168.168.167:5000/y98tn/?action=download%26mode=render%26direct)',
);
const id = getMfrId(renderedHtml);
assert.equal(
renderedHtml,
'<p><div id="' +
id +
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
id +
'", "http://localhost:7778/render?mode=render&amp;url=http://192.168.168.167:5000/y98tn/?action=download%26mode=render%26direct"); }); </script></p>\n',
const renderedHtml = preserveId(
md.render(
'@[osf](http://localhost:7778/render?mode=render&url=http://192.168.168.167:5000/y98tn/?action=download%26mode=render%26direct)',
),
);

expect(renderedHtml).toMatchSnapshot();
});
});

0 comments on commit fa2095b

Please sign in to comment.