-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-tests.js
138 lines (109 loc) · 4.7 KB
/
main-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const { throws, deepEqual } = require('assert');
const mod = require('./main.js');
import { JSDOM } from 'jsdom';
describe('OLSKEmbedEndpointURL', function test_OLSKEmbedEndpointURL () {
it('throws if not string', function () {
throws(function () {
mod.OLSKEmbedEndpointURL(null);
}, /OLSKErrorInputNotValid/);
});
it('returns null', function () {
deepEqual(mod.OLSKEmbedEndpointURL(''), null);
});
it('matches youtube', function () {
deepEqual(mod.OLSKEmbedEndpointURL('https://youtube.com/watch?v=oUFJJNQGwhk'), Object.keys(mod._OLSKEmbedPatterns()).filter(function (e) {
return e.match('youtube');
}).shift());
});
it('matches soundcloud', function () {
deepEqual(mod.OLSKEmbedEndpointURL('https://soundcloud.com/tycho/tycho-awake'), Object.keys(mod._OLSKEmbedPatterns()).filter(function (e) {
return e.match('soundcloud');
}).shift());
});
it('matches facebook', function () {
deepEqual(mod.OLSKEmbedEndpointURL('https://facebook.com/facebook/videos/10153231379946729'), Object.keys(mod._OLSKEmbedPatterns()).filter(function (e) {
return e.match('facebook');
}).pop());
});
it('matches vimeo', function () {
deepEqual(mod.OLSKEmbedEndpointURL('https://vimeo.com/90509568'), Object.keys(mod._OLSKEmbedPatterns()).filter(function (e) {
return e.match('vimeo');
}).shift());
});
it('matches instagram', function () {
deepEqual(mod.OLSKEmbedEndpointURL('https://www.instagram.com/p/CN4V2ksHAyE/'), Object.keys(mod._OLSKEmbedPatterns()).filter(function (e) {
return e.match('instagram');
}).shift());
});
});
describe('OLSKEmbedFetchURL', function test_OLSKEmbedFetchURL () {
it('throws if param1 not string', function () {
throws(function () {
mod.OLSKEmbedFetchURL(null, '');
}, /OLSKErrorInputNotValid/);
});
it('throws if param2 not string', function () {
throws(function () {
mod.OLSKEmbedFetchURL('', null);
}, /OLSKErrorInputNotValid/);
});
it('returns string', function () {
deepEqual(mod.OLSKEmbedFetchURL('', ''), '?url=');
});
it('url encodes param2', function () {
const param1 = Math.random().toString();
const param2 = 'https://example.com?alfa=bravo';
deepEqual(mod.OLSKEmbedFetchURL(param1, param2), param1 + '?url=' + encodeURIComponent(param2));
});
});
describe('OLSKEmbedGenerateProperties', function test_OLSKEmbedGenerateProperties () {
it('returns input', function () {
const item = {
html: Math.random().toString(),
};
deepEqual(mod.OLSKEmbedGenerateProperties(item), item);
});
it('sets OLSKEmbedFrameURL', function () {
const url = Math.random().toString();
const item = {
html: `<iframe width="200" height="113" src="${ url }" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen title="${ Math.random().toString() }"></iframe>`,
};
deepEqual(mod.OLSKEmbedGenerateProperties(item).OLSKEmbedFrameURL, url);
});
context('YouTube', function () {
it('sets OLSKEmbedFrameURL', function () {
const id = Math.random().toString();
const url = `https://www.youtube.com/embed/${ id }?feature=oembed`;
const item = {
provider_name: 'YouTube',
html: `<iframe width="200" height="113" src="${ url }" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen title="${ Math.random().toString() }"></iframe>`,
};
deepEqual(mod.OLSKEmbedGenerateProperties(item).OLSKEmbedFrameURL, url.replace('youtube.com', 'youtube-nocookie.com'));
});
it('sets OLSKEmbedHeight', function () {
const item = {
provider_name: 'YouTube',
html: `<iframe width="200" height="113" src="${ Math.random().toString() }" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen title="${ Math.random().toString() }"></iframe>`,
};
deepEqual(mod.OLSKEmbedGenerateProperties(item).OLSKEmbedHeight, 200);
});
});
context('TikTok', function () {
it('sets OLSKEmbedFrameURL', function () {
const item = {
provider_name: 'TikTok',
embed_product_id: Math.random().toString(),
html: Math.random().toString(),
};
deepEqual(mod.OLSKEmbedGenerateProperties(item).OLSKEmbedFrameURL, 'https://www.tiktok.com/embed/v2/' + item.embed_product_id);
});
it('sets OLSKEmbedHeight', function () {
const item = {
provider_name: 'TikTok',
embed_product_id: Math.random().toString(),
html: Math.random().toString(),
};
deepEqual(mod.OLSKEmbedGenerateProperties(item).OLSKEmbedHeight, 500);
});
});
});