-
Notifications
You must be signed in to change notification settings - Fork 60
/
test.js
143 lines (112 loc) · 3.12 KB
/
test.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
139
140
141
142
143
var React = require("react");
var ReactDom = require("react-dom");
var ReactSocial = require("./react-social");
var test = require("tape");
var $ = require("jquery");
var testUrl = "http://github.com";
function newNode() {
var node = document.createElement("div");
document.body.appendChild(node);
return node;
}
function render(comp, props) {
var node = newNode();
props = props || {};
props.className = "test";
props.url = testUrl;
ReactDom.render(React.createElement(comp, props), node);
return $(node).find(".test");
}
function testCount(t, str, wait) {
wait = wait || 2000;
var comp = ReactSocial[str];
t.equal(comp.displayName, str, "display name and comp name should be equal");
setTimeout(function () {
var $el = render(comp, {onCount: function (count) {
var countText = parseInt($el.text(), 10);
t.equal(count, countText);
}});
});
return 2;
}
function testButton(t, str, _blank) {
var comp = ReactSocial[str];
_blank = _blank || "_blank";
t.equal(comp.displayName, str, "display name and comp name should be equal");
setTimeout(function () {
var $el = render(comp, {_open: false, onClick: function (e, url, target) {
t.equal(target, _blank);
}, appId: 1});
$el.click();
t.equal($el[0].nodeName, "BUTTON");
});
return 3;
}
// Counts
test("FacebookCount", function (t) {
t.plan(testCount(t, "FacebookCount"));
});
test("TwitterCount", function (t) {
t.plan(testCount(t, "TwitterCount"));
});
test("GooglePlusCount", function (t) {
t.plan(testCount(t, "GooglePlusCount"));
});
test("PinterestCount", function (t) {
t.plan(testCount(t, "PinterestCount"));
});
test("LinkedInCount", function (t) {
t.plan(testCount(t, "LinkedInCount"));
});
test("RedditCount", function (t) {
t.plan(testCount(t, "RedditCount"));
});
test("VKontakteCount", function (t) {
t.plan(testCount(t, "VKontakteCount"));
});
test("TumblrCount", function (t) {
t.plan(testCount(t, "TumblrCount"));
});
test("PocketCount", function (t) {
t.plan(testCount(t, "PocketCount"));
});
// Buttons
test("FacebookButton", function (t) {
t.plan(testButton(t, "FacebookButton"));
});
test("OdnoklassnikiButton", function (t) {
t.plan(testButton(t, "OdnoklassnikiButton"));
});
test("MyMailRuButton", function (t) {
t.plan(testButton(t, "MyMailRuButton"));
});
test("TwitterButton", function (t) {
t.plan(testButton(t, "TwitterButton"));
});
test("GooglePlusButton", function (t) {
t.plan(testButton(t, "GooglePlusButton"));
});
test("PinterestButton", function (t) {
t.plan(testButton(t, "PinterestButton"));
});
test("LinkedInButton", function (t) {
t.plan(testButton(t, "LinkedInButton"));
});
test("RedditButton", function (t) {
t.plan(testButton(t, "RedditButton"));
});
test("VKontakteButton", function (t) {
t.plan(testButton(t, "VKontakteButton"));
});
test("EmailButton", function (t) {
t.plan(testButton(t, "EmailButton"));
});
test("XingButton", function (t) {
t.plan(testButton(t, "XingButton"));
});
test("TumblrButton", function (t) {
t.plan(testButton(t, "TumblrButton"));
});
test("PocketButton", function (t) {
t.plan(testButton(t, "TumblrButton"));
});