Skip to content

Commit e5a6fe5

Browse files
committed
test: e2e test for composition API examples
1 parent 4608565 commit e5a6fe5

17 files changed

+923
-73
lines changed

examples/classic/markdown/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
computed: {
2626
compiledMarkdown: function () {
27-
return marked(this.input, { sanitize: true })
27+
return marked.marked(this.input)
2828
}
2929
},
3030
methods: {

examples/classic/svg/svg.js

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// The raw data to observe
2-
var stats = [
2+
var globalStats = [
33
{ label: 'A', value: 100 },
44
{ label: 'B', value: 100 },
55
{ label: 'C', value: 100 },
@@ -16,10 +16,12 @@ Vue.component('polygraph', {
1616
// a computed property for the polygon's points
1717
points: function () {
1818
var total = this.stats.length
19-
return this.stats.map(function (stat, i) {
20-
var point = valueToPoint(stat.value, i, total)
21-
return point.x + ',' + point.y
22-
}).join(' ')
19+
return this.stats
20+
.map(function (stat, i) {
21+
var point = valueToPoint(stat.value, i, total)
22+
return point.x + ',' + point.y
23+
})
24+
.join(' ')
2325
}
2426
},
2527
components: {
@@ -33,26 +35,22 @@ Vue.component('polygraph', {
3335
template: '#axis-label-template',
3436
computed: {
3537
point: function () {
36-
return valueToPoint(
37-
+this.stat.value + 10,
38-
this.index,
39-
this.total
40-
)
38+
return valueToPoint(+this.stat.value + 10, this.index, this.total)
4139
}
4240
}
4341
}
4442
}
4543
})
4644

4745
// math helper...
48-
function valueToPoint (value, index, total) {
49-
var x = 0
50-
var y = -value * 0.8
51-
var angle = Math.PI * 2 / total * index
52-
var cos = Math.cos(angle)
53-
var sin = Math.sin(angle)
54-
var tx = x * cos - y * sin + 100
55-
var ty = x * sin + y * cos + 100
46+
function valueToPoint(value, index, total) {
47+
var x = 0
48+
var y = -value * 0.8
49+
var angle = ((Math.PI * 2) / total) * index
50+
var cos = Math.cos(angle)
51+
var sin = Math.sin(angle)
52+
var tx = x * cos - y * sin + 100
53+
var ty = x * sin + y * cos + 100
5654
return {
5755
x: tx,
5856
y: ty
@@ -64,7 +62,7 @@ new Vue({
6462
el: '#demo',
6563
data: {
6664
newLabel: '',
67-
stats: stats
65+
stats: globalStats
6866
},
6967
methods: {
7068
add: function (e) {
@@ -80,7 +78,7 @@ new Vue({
8078
if (this.stats.length > 3) {
8179
this.stats.splice(this.stats.indexOf(stat), 1)
8280
} else {
83-
alert('Can\'t delete more!')
81+
alert("Can't delete more!")
8482
}
8583
}
8684
}

examples/composition/commits.html

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<script src="../../dist/vue.min.js"></script>
2+
3+
<div id="demo">
4+
<h1>Latest Vue.js Commits</h1>
5+
<template v-for="branch in branches">
6+
<input type="radio"
7+
:id="branch"
8+
:value="branch"
9+
name="branch"
10+
v-model="currentBranch">
11+
<label :for="branch">{{ branch }}</label>
12+
</template>
13+
<p>vuejs/vue@{{ currentBranch }}</p>
14+
<ul>
15+
<li v-for="{ html_url, sha, author, commit } in commits">
16+
<a :href="html_url" target="_blank" class="commit">{{ sha.slice(0, 7) }}</a>
17+
- <span class="message">{{ truncate(commit.message) }}</span><br>
18+
by <span class="author"><a :href="author.html_url" target="_blank">{{ commit.author.name }}</a></span>
19+
at <span class="date">{{ formatDate(commit.author.date) }}</span>
20+
</li>
21+
</ul>
22+
</div>
23+
24+
<script>
25+
const { ref, watchEffect } = Vue
26+
const API_URL = `https://api.github.com/repos/vuejs/vue/commits?per_page=3&sha=`
27+
28+
const truncate = v => {
29+
const newline = v.indexOf('\n')
30+
return newline > 0 ? v.slice(0, newline) : v
31+
}
32+
33+
const formatDate = v => v.replace(/T|Z/g, ' ')
34+
35+
new Vue({
36+
setup() {
37+
const currentBranch = ref('main')
38+
const commits = ref(null)
39+
40+
watchEffect(() => {
41+
fetch(`${API_URL}${currentBranch.value}`)
42+
.then(res => res.json())
43+
.then(data => {
44+
console.log(data)
45+
commits.value = data
46+
})
47+
})
48+
49+
return {
50+
branches: ['main', 'dev'],
51+
currentBranch,
52+
commits,
53+
truncate,
54+
formatDate
55+
}
56+
}
57+
}).$mount('#demo')
58+
</script>
59+
60+
<style>
61+
#demo {
62+
font-family: 'Helvetica', Arial, sans-serif;
63+
}
64+
a {
65+
text-decoration: none;
66+
color: #f66;
67+
}
68+
li {
69+
line-height: 1.5em;
70+
margin-bottom: 20px;
71+
}
72+
.author, .date {
73+
font-weight: bold;
74+
}
75+
</style>

examples/composition/grid.html

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<script src="../../dist/vue.min.js"></script>
2+
3+
<!-- DemoGrid component template -->
4+
<script type="text/x-template" id="grid-template">
5+
<table v-if="filteredData.length">
6+
<thead>
7+
<tr>
8+
<th v-for="key in columns"
9+
@click="sortBy(key)"
10+
:class="{ active: state.sortKey == key }">
11+
{{ capitalize(key) }}
12+
<span class="arrow" :class="state.sortOrders[key] > 0 ? 'asc' : 'dsc'">
13+
</span>
14+
</th>
15+
</tr>
16+
</thead>
17+
<tbody>
18+
<tr v-for="entry in filteredData">
19+
<td v-for="key in columns">
20+
{{entry[key]}}
21+
</td>
22+
</tr>
23+
</tbody>
24+
</table>
25+
<p v-else>No matches found.</p>
26+
</script>
27+
<!-- DemoGrid component script -->
28+
<script>
29+
const { reactive, computed } = Vue
30+
31+
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)
32+
33+
const DemoGrid = {
34+
template: '#grid-template',
35+
props: {
36+
data: Array,
37+
columns: Array,
38+
filterKey: String
39+
},
40+
setup(props) {
41+
const state = reactive({
42+
sortKey: '',
43+
sortOrders: props.columns.reduce((o, key) => (o[key] = 1, o), {})
44+
})
45+
46+
const filteredData = computed(() => {
47+
let { data, filterKey } = props
48+
if (filterKey) {
49+
filterKey = filterKey.toLowerCase()
50+
data = data.filter(row => {
51+
return Object.keys(row).some(key => {
52+
return String(row[key]).toLowerCase().indexOf(filterKey) > -1
53+
})
54+
})
55+
}
56+
const { sortKey } = state
57+
if (sortKey) {
58+
const order = state.sortOrders[sortKey]
59+
data = data.slice().sort((a, b) => {
60+
a = a[sortKey]
61+
b = b[sortKey]
62+
return (a === b ? 0 : a > b ? 1 : -1) * order
63+
})
64+
}
65+
return data
66+
})
67+
68+
function sortBy(key) {
69+
state.sortKey = key
70+
state.sortOrders[key] *= -1
71+
}
72+
73+
return {
74+
state,
75+
filteredData,
76+
sortBy,
77+
capitalize
78+
}
79+
}
80+
}
81+
</script>
82+
83+
<!-- App template (in DOM) -->
84+
<div id="demo">
85+
<form id="search">
86+
Search <input name="query" v-model="searchQuery">
87+
</form>
88+
<demo-grid
89+
:data="gridData"
90+
:columns="gridColumns"
91+
:filter-key="searchQuery">
92+
</demo-grid>
93+
</div>
94+
<!-- App script -->
95+
<script>
96+
new Vue({
97+
components: {
98+
DemoGrid
99+
},
100+
data: () => ({
101+
searchQuery: '',
102+
gridColumns: ['name', 'power'],
103+
gridData: [
104+
{ name: 'Chuck Norris', power: Infinity },
105+
{ name: 'Bruce Lee', power: 9000 },
106+
{ name: 'Jackie Chan', power: 7000 },
107+
{ name: 'Jet Li', power: 8000 }
108+
]
109+
})
110+
}).$mount('#demo')
111+
</script>
112+
113+
<style>
114+
body {
115+
font-family: Helvetica Neue, Arial, sans-serif;
116+
font-size: 14px;
117+
color: #444;
118+
}
119+
120+
table {
121+
border: 2px solid #42b983;
122+
border-radius: 3px;
123+
background-color: #fff;
124+
}
125+
126+
th {
127+
background-color: #42b983;
128+
color: rgba(255,255,255,0.66);
129+
cursor: pointer;
130+
-webkit-user-select: none;
131+
-moz-user-select: none;
132+
-ms-user-select: none;
133+
user-select: none;
134+
}
135+
136+
td {
137+
background-color: #f9f9f9;
138+
}
139+
140+
th, td {
141+
min-width: 120px;
142+
padding: 10px 20px;
143+
}
144+
145+
th.active {
146+
color: #fff;
147+
}
148+
149+
th.active .arrow {
150+
opacity: 1;
151+
}
152+
153+
.arrow {
154+
display: inline-block;
155+
vertical-align: middle;
156+
width: 0;
157+
height: 0;
158+
margin-left: 5px;
159+
opacity: 0.66;
160+
}
161+
162+
.arrow.asc {
163+
border-left: 4px solid transparent;
164+
border-right: 4px solid transparent;
165+
border-bottom: 4px solid #fff;
166+
}
167+
168+
.arrow.dsc {
169+
border-left: 4px solid transparent;
170+
border-right: 4px solid transparent;
171+
border-top: 4px solid #fff;
172+
}
173+
</style>

0 commit comments

Comments
 (0)