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 6244916 commit f3c85f1
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 98 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="41901.632424847834"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("41901.632424847834", "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="43924.59346308025"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("43924.59346308025", "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="65184.23524741545"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("65184.23524741545", "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="48735.96812194152"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("48735.96812194152", "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="13388.477585681103"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("13388.477585681103", "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="17173.271759814117"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("17173.271759814117", "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="26789.16503860723"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("26789.16503860723", "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="42981.54797643432"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("42981.54797643432", "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="38573.06134411787"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("38573.06134411787", "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="60247.40432442627"
class="mfr mfr-file"
>
</div>
<script>
$(document).ready(function () {new mfr.Render("60247.40432442627", "https://mfr-staging3.osf.io/render?url=https://staging3.osf.io/xxxxx/?action=download%26mode=render"); });
</script>
</p>
`;
109 changes: 12 additions & 97 deletions test/video.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ 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];
}

describe('md-video', function () {
const md = new MarkdownIt({}).use(video);
Expand All @@ -23,148 +17,69 @@ describe('md-video-mfr', function () {

it('make sure normal iframe generates properly when empty', function () {
const renderedHtml = md.render('@[osf]()');
assert.equal(renderedHtml, '<p></p>\n');
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',
);
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',
);
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',
);
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',
);
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',
);
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',
);
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',
);
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',
);
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',
);
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',
);

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

0 comments on commit f3c85f1

Please sign in to comment.