This repository was archived by the owner on Nov 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtest.youtube-embed.selenium.js
94 lines (83 loc) · 3.5 KB
/
test.youtube-embed.selenium.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
var expect = require('expect.js'),
common = require('./common'),
extractYoutubeId = require("../public/js/extract-youtube-id");
describe("YOUTUBE EMBEDS", function() {
var browser = null;
if (process.env.SKIP_SELENIUM_TESTS) {
return;
}
this.timeout(80000); // Extra long timeout for selenium :(
before(function(done) {
this.timeout(240000);
common.getSeleniumBrowser(function (theBrowser) {
browser = theBrowser;
common.standardSetup(done);
});
});
after(function(done) {
browser.quit().then(function() {
common.standardShutdown(done);
});
});
it("Tries a variety of YouTube urls", function (done) {
var event = common.server.db.events.findWhere({shortName: "writers-at-work"});
var ytId = "pco91kroVgQ";
event.set("open", true);
function tryEmbed(url, success) {
browser.get(common.FAST_URL).then(function() {
event.set("youtubeEmbed", "");
});
browser.get(common.URL + "/event/" + event.id);
browser.waitForEventReady(event, "superuser1", 45000);
browser.waitForSelector("#video-embed [name=youtube_id]", 45000);
browser.byCss("#video-embed [name=youtube_id]").sendKeys(url);
browser.byCss(".set-video").click();
if (success) {
// Wait for embed to finish..
browser.waitForSelector("iframe", 45000);
return browser.byCss("iframe").getAttribute("src").then(function(src) {
// youtube seems to randomly throw https at us sometimes these days.
var re = new RegExp("^https?://www.youtube.com/embed/" + ytId + "\?.*$");
expect(re.test(src)).to.be(true);
expect(event.get("youtubeEmbed")).to.eql(ytId);
});
} else {
browser.wait(function() {
return browser.byCsss(".text-warning").then(function(els) {
return els.length > 0;
});
});
return browser.byCss(".text-warning").getText().then(function(text) {
expect(text.indexOf("Unrecognized youtube URL")).to.not.eql(-1);
});
}
}
browser.mockAuthenticate("superuser1");
tryEmbed(ytId, true);
tryEmbed("foo", false);
tryEmbed("https://www.youtube.com/watch?v=" + ytId, true);
browser.get(common.FAST_URL);
browser.then(function() {
done();
});
});
it("Extracts youtube ID's", function() {
var ytId = "pco91kroVgQ";
function tryExtract(url, success) {
var res = extractYoutubeId.extractYoutubeId(url);
if (success) {
expect(res).to.be(ytId);
} else {
expect(res).to.be(null);
}
}
tryExtract("foo", false);
tryExtract(ytId, true);
tryExtract("http://www.youtube.com", false);
tryExtract("http://www.youtube.com/embed/" + ytId, true);
tryExtract("http://www.youtube.com/v/" + ytId + "?fs=1&hl=en_US", true);
tryExtract("http://www.youtube.com/watch?feature=player_embedded&v=" + ytId, true);
tryExtract("https://youtu.be/" + ytId, true);
tryExtract('<iframe width="560" height="315" src="//www.youtube.com/embed/' + ytId + '" frameborder="0" allowfullscreen></iframe>', true);
});
});