forked from Tencent/vConsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
130 lines (107 loc) · 4.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
describe("vConsole", function() {
var assert = require('chai').assert;
var util = require('util');
var jsdom = require('jsdom');
it('touch event', function(done) {
jsdom.env('test/log.html', function(err, window) {
var document = window.document;
window.localStorage = {
getItem: function (key) {
return this[key];
},
setItem: function (key, value) {
this[key] = String(value);
}
};
global.localStorage = window.localStorage;
var vcSwitch = document.querySelector('.vc-switch');
var eventTouchstart = document.createEvent('Event');
eventTouchstart.initEvent('touchstart', true, true);
var point = { x: 10, y: 10 };
eventTouchstart.touches = [{
identifier: Math.random(),
pageX: point.x,
pageY: point.y,
screenX: point.x,
screenY: point.y,
clientX: point.x,
clientY: point.y
}];
vcSwitch.dispatchEvent(eventTouchstart);
var eventTouchmove = document.createEvent('Event');
eventTouchmove.initEvent('touchmove', true, true);
var point = { x: 12, y: 12 };
eventTouchmove.touches = [{
identifier: Math.random(),
pageX: point.x,
pageY: point.y,
screenX: point.x,
screenY: point.y,
clientX: point.x,
clientY: point.y
}];
vcSwitch.dispatchEvent(eventTouchmove);
var eventTouchend = document.createEvent('Event');
eventTouchend.initEvent('touchend', true, true);
vcSwitch.dispatchEvent(eventTouchend);
setTimeout(function () {
assert.equal(localStorage.vConsole_switch_x, '8');
global.localStorage = null;
window.localStorage = null;
done();
}, 100);
}, {
features: {
FetchExternalResources: ["link", "script"]
}
});
});
it('log.html', function(done) {
jsdom.env('test/log.html', function(err, window) {
var document = window.document;
assert.equal(document.querySelector('#__vconsole') !== null, true);
document.querySelector('.weui_btn.weui_btn_default:nth-of-type(1)').click(); // formattedLog
assert.equal(document.querySelector('.vc-logbox.vc-actived .vc-log .vc-item .vc-item-content').innerHTML, ' formattedLog() Start');
document.querySelector('.vc-toolbar .vc-tool.vc-tool-default:nth-of-type(1)').click(); // clear
assert.equal(document.querySelector('.vc-logbox.vc-actived .vc-log .vc-item .vc-item-content'), null);
document.querySelector('.weui_btn.weui_btn_default:nth-of-type(2)').click(); // normalObject
assert.equal(document.querySelector('.vc-logbox.vc-actived .vc-log .vc-item .vc-item-content').innerHTML, ' normalObject() Start');
document.querySelector('.vc-toolbar .vc-tool.vc-tool-default:nth-of-type(1)').click(); // clear
assert.equal(document.querySelector('.vc-logbox.vc-actived .vc-log .vc-item .vc-item-content'), null);
done();
}, {
features: {
FetchExternalResources: ["link", "script"]
}
});
});
it('plugin.html', function(done) {
jsdom.env('test/plugin.html', function(err, window) {
var document = window.document;
assert.equal(document.querySelector('#__vconsole') !== null, true);
document.querySelector('.page a:nth-of-type(1)').click(); // newTab
assert.equal(document.querySelector('.vc-tabbar .vc-tab:nth-of-type(4)').innerHTML, 'Tab1');
done();
}, {
features: {
FetchExternalResources: ["link", "script"]
}
});
});
it('ajax.html', function(done) {
this.timeout(2000);
jsdom.env('test/ajax.html', function(err, window) {
var document = window.document;
assert.equal(document.querySelector('#__vconsole') !== null, true);
document.querySelector('.page a:nth-of-type(1)').click(); // asyncAjax
setTimeout(function () {
assert.equal(document.querySelector('.vc-logbox.vc-actived .vc-log .vc-fold-outer').innerHTML, 'Object {ret: 0, msg: "ok"}');
done();
}, 10)
}, {
features: {
FetchExternalResources: ["link", "script"]
}
});
});
});