Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit cfa252e

Browse files
committed
Add tests for storeMeta
1 parent 92bd9cf commit cfa252e

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

dist/js/medium-editor-insert-plugin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,10 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
11961196
.replace(/^(https:\/\/www\.facebook\.com\/(.*))$/, '<script src="//connect.facebook.net/en_US/sdk.js#xfbml=1&amp;version=v2.2" async></script><div class="fb-post" data-href="$1"><div class="fb-xfbml-parse-ignore"><a href="$1">Loading Facebook post...</a></div></div>')
11971197
.replace(/^https?:\/\/instagram\.com\/p\/(.+)\/?$/, '<span class="instagram"><iframe src="//instagram.com/p/$1/embed/" width="612" height="710" frameborder="0" scrolling="no" allowtransparency="true"></iframe></span>');
11981198

1199+
if (this.options.storeMeta) {
1200+
html += '<div class="medium-insert-embeds-meta"><script type="text/json">' + JSON.stringify({}) + '</script></div>';
1201+
}
1202+
11991203
if ((/<("[^"]*"|'[^']*'|[^'">])*>/).test(html) === false) {
12001204
$.proxy(this, 'convertBadEmbed', url)();
12011205
return false;

dist/js/medium-editor-insert-plugin.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/embeds.spec.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,5 +436,71 @@ describe('Embeds addon', function () {
436436
expect($serialized.find('[data-embed-code]').html()).toEqual('<div>good-value</div>');
437437
});
438438

439+
it('does include meta when storeMeta is set', function () {
440+
var $event = $.Event('keydown');
441+
442+
$event.which = 13;
443+
$('#fixtures').html('<div class="editable"><p class="medium-insert-embeds-input medium-insert-embeds-active">https://www.facebook.com/cneistat/videos/vb.210351389002863/922328184471843/?type=2&theater</p></div>');
444+
this.$el = $('.editable');
445+
this.$el.mediumInsert({
446+
addons: {
447+
embeds: {
448+
oembedProxy: false,
449+
storeMeta: true
450+
}
451+
}
452+
});
453+
this.$el.trigger($event);
454+
455+
expect(this.$el.find('.medium-insert-embeds').length).toEqual(1);
456+
expect(this.$el.find('.medium-insert-embeds .fb-post').length).toEqual(1);
457+
expect(this.$el.find('.medium-insert-embeds-meta').length).toEqual(1);
458+
expect(this.$el.find('.medium-insert-embeds-input').length).toEqual(0);
459+
});
460+
461+
it('does not include meta when storeMeta is not set', function () {
462+
var $event = $.Event('keydown');
463+
464+
$event.which = 13;
465+
$('#fixtures').html('<div class="editable"><p class="medium-insert-embeds-input medium-insert-embeds-active">https://www.facebook.com/cneistat/videos/vb.210351389002863/922328184471843/?type=2&theater</p></div>');
466+
this.$el = $('.editable');
467+
this.$el.mediumInsert({
468+
addons: {
469+
embeds: {
470+
oembedProxy: false,
471+
storeMeta: false
472+
}
473+
}
474+
});
475+
this.$el.trigger($event);
476+
477+
expect(this.$el.find('.medium-insert-embeds').length).toEqual(1);
478+
expect(this.$el.find('.medium-insert-embeds .fb-post').length).toEqual(1);
479+
expect(this.$el.find('.medium-insert-embeds-meta').length).toEqual(0);
480+
expect(this.$el.find('.medium-insert-embeds-input').length).toEqual(0);
481+
});
482+
483+
it('does not include meta for bad embeds', function () {
484+
var $event = $.Event('keydown');
485+
486+
$event.which = 13;
487+
$('#fixtures').html('<div class="editable"><p class="medium-insert-embeds-input medium-insert-embeds-active">test</p></div>');
488+
this.$el = $('.editable');
489+
490+
this.$el.mediumInsert({
491+
addons: {
492+
embeds: {
493+
oembedProxy: false,
494+
storeMeta: true
495+
}
496+
}
497+
});
498+
this.$el.trigger($event);
499+
500+
expect(this.$el.find('.medium-insert-embeds-input').length).toEqual(0);
501+
expect(this.$el.find('.medium-insert-embeds-meta').length).toEqual(0);
502+
expect(this.$el.find('p:first').html()).toBe('test');
503+
});
504+
439505

440506
});

src/js/embeds.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@
390390
.replace(/^(https:\/\/www\.facebook\.com\/(.*))$/, '<script src="//connect.facebook.net/en_US/sdk.js#xfbml=1&amp;version=v2.2" async></script><div class="fb-post" data-href="$1"><div class="fb-xfbml-parse-ignore"><a href="$1">Loading Facebook post...</a></div></div>')
391391
.replace(/^https?:\/\/instagram\.com\/p\/(.+)\/?$/, '<span class="instagram"><iframe src="//instagram.com/p/$1/embed/" width="612" height="710" frameborder="0" scrolling="no" allowtransparency="true"></iframe></span>');
392392

393+
if (this.options.storeMeta) {
394+
html += '<div class="medium-insert-embeds-meta"><script type="text/json">' + JSON.stringify({}) + '</script></div>';
395+
}
396+
393397
if ((/<("[^"]*"|'[^']*'|[^'">])*>/).test(html) === false) {
394398
$.proxy(this, 'convertBadEmbed', url)();
395399
return false;

0 commit comments

Comments
 (0)