-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
widget_test3.html
134 lines (118 loc) · 4.42 KB
/
widget_test3.html
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
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../dist/avalon.test.js"></script>
</head>
<body>
<script>
var div = document.createElement('div')
var body = document.body
body.appendChild(div)
function heredoc(fn) {
return fn.toString().replace(/^[^\/]+\/\*!?\s?/, '').
replace(/\*\/[^\/]+$/, '').trim().replace(/>\s*</g, '><')
}
function fireClick(el) {
if (el.click) {
el.click()
} else {
//https://developer.mozilla.org/samples/domref/dispatchEvent.html
var evt = document.createEvent('MouseEvents')
evt.initMouseEvent('click', true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
!el.dispatchEvent(evt);
}
}
function expect(a){
return {
to: {
be:{
equal:function(b){
console.log(a,b,a===b)
}
},
equal:function(b){
console.log(a,b,a===b)
}
}
}
}
avalon.component('ms-hasha', {
template: '<div cached="true">{{@num}}<input type="text" ms-duplex-number="@num"/><button type="button" ms-on-click="@onPlus">+++</button></div>',
defaults: {
num: 1,
onPlus: function () {
this.num++;
}
}
});
var tpl = '<div cached="true"><h4>{{@title}}</h4><button type="button" ms-on-click="@onChangeTitle">点击改变title</button></div>';
var time = 10
avalon.component('ms-hashb', {
template: tpl,
defaults: {
title: "这是标题",
random: 0,
onChangeTitle: function (e) {
this.title = 'title' + (++time);
}
}
});
vm = avalon.define({
$id: 'router',
panel: '',
hash: ''
})
function changePanel(v) {
vm.panel = '<' + v + ' cached=\"true\" ms-widget=\"{$id:"' + v + '"}\"></' + v + '>'
}
vm.$watch('hash', changePanel)
vm.hash = 'ms-hasha'
div.innerHTML = heredoc(function () {
/*
<div ms-controller="router" ms-html="@panel">xxx</div>
*/
})
avalon.scan(div)
setTimeout(function () {
var input = div.getElementsByTagName('input')[0]
var button = div.getElementsByTagName('button')[0]
expect(input.value).to.be.equal('1')
fireClick(button)
expect(input.value).to.be.equal('2')
fireClick(button)
expect(input.value).to.be.equal('3')
fireClick(button)
expect(input.value).to.be.equal('4')
vm.hash = 'ms-hashb'
setTimeout(function () {
var h4 = div.getElementsByTagName('h4')[0]
var button = div.getElementsByTagName('button')[0]
expect(h4.innerHTML).to.be.equal('这是标题')
fireClick(button)
expect(h4.innerHTML).to.be.equal('title11')
fireClick(button)
expect(h4.innerHTML).to.be.equal('title12')
fireClick(button)
expect(h4.innerHTML).to.be.equal('title13')
vm.hash = 'ms-hasha'
setTimeout(function () {
var input = div.getElementsByTagName('input')[0]
var button = div.getElementsByTagName('button')[0]
expect(input.value).to.be.equal('4')
fireClick(button)
expect(input.value).to.be.equal('5')
fireClick(button)
expect(input.value).to.be.equal('6')
fireClick(button)
expect(input.value).to.be.equal('7')
// done()
})
})
})
</script>
</body>
</html>