-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
宋慧武
committed
Apr 13, 2019
1 parent
f1404ef
commit c06e7e6
Showing
9 changed files
with
263 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* @Author: 宋慧武 | ||
* @Date: 2019-04-13 22:00:04 | ||
* @Last Modified by: 宋慧武 | ||
* @Last Modified time: 2019-04-13 22:54:09 | ||
*/ | ||
import Vue from "vue"; | ||
import VTrack from "@/"; | ||
import { mount, createLocalVue } from "@vue/test-utils"; | ||
|
||
const localVue = createLocalVue(); | ||
const mockTrackAction = jest.fn(({ status }) => status); | ||
const trackEvents = { | ||
18015: mockTrackAction | ||
}; | ||
const Child = Vue.extend({ | ||
template: ` | ||
<div @click="$emit('search')" /> | ||
` | ||
}); | ||
const TrackCustomEventAsync = Vue.extend({ | ||
template: ` | ||
<child v-track:18015.search.async="{ fetchRest, rest }" /> | ||
`, | ||
components: { | ||
child: Child | ||
}, | ||
data() { | ||
return { | ||
rest: null | ||
}; | ||
}, | ||
methods: { | ||
async fetchRest() { | ||
const response = await Promise.resolve({ data: "success" }); | ||
this.rest = response.data; | ||
} | ||
} | ||
}); | ||
|
||
localVue.use(VTrack, { | ||
trackEvents | ||
}); | ||
|
||
describe("TrackCustomEventAsync", () => { | ||
it("确保异步的自定义事件返回成功之后再上报埋点", done => { | ||
const wrapper = mount(TrackCustomEventAsync, { | ||
localVue | ||
}); | ||
const vm = wrapper.vm; | ||
|
||
wrapper.find(Child).trigger("click"); | ||
expect(vm.rest).toBeNull(); | ||
expect(mockTrackAction).toBeCalledTimes(0); | ||
vm.$nextTick(() => { | ||
expect(vm.rest).toBe("success"); | ||
expect(mockTrackAction).toBeCalledTimes(1); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* @Author: 宋慧武 | ||
* @Date: 2019-04-13 22:00:04 | ||
* @Last Modified by: 宋慧武 | ||
* @Last Modified time: 2019-04-13 22:30:58 | ||
*/ | ||
import Vue from "vue"; | ||
import VTrack from "@/"; | ||
import { mount, createLocalVue } from "@vue/test-utils"; | ||
|
||
const localVue = createLocalVue(); | ||
const mockTrackAction = jest.fn(({ status }) => status); | ||
const trackEvents = { | ||
18015: mockTrackAction | ||
}; | ||
const Child = Vue.extend({ | ||
template: ` | ||
<div @click="$emit('expand', { status })" /> | ||
`, | ||
data() { | ||
return { | ||
status: true | ||
}; | ||
} | ||
}); | ||
const TrackCustomEventDelay = Vue.extend({ | ||
template: ` | ||
<child v-track:18015.expand.delay="handleExpand" /> | ||
`, | ||
components: { | ||
child: Child | ||
}, | ||
data() { | ||
return { | ||
status: false | ||
}; | ||
}, | ||
methods: { | ||
handleExpand({ status }) { | ||
this.status = status; | ||
} | ||
} | ||
}); | ||
|
||
localVue.use(VTrack, { | ||
trackEvents | ||
}); | ||
|
||
describe("TrackCustomEventDelay", () => { | ||
it("确保埋点在自定义事件之后上报", () => { | ||
const wrapper = mount(TrackCustomEventDelay, { | ||
localVue | ||
}); | ||
|
||
wrapper.find(Child).trigger("click"); | ||
expect(mockTrackAction).toBeTruthy(); | ||
expect(mockTrackAction).toBeCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* @Author: 宋慧武 | ||
* @Date: 2019-04-13 21:03:55 | ||
* @Last Modified by: 宋慧武 | ||
* @Last Modified time: 2019-04-13 22:56:41 | ||
*/ | ||
import Vue from "vue"; | ||
import VTrack from "@/"; | ||
import { mount, createLocalVue } from "@vue/test-utils"; | ||
|
||
const localVue = createLocalVue(); | ||
const mockTrackAction = jest.fn(); | ||
const trackEvents = { | ||
18015: mockTrackAction | ||
}; | ||
const Child = Vue.extend({ | ||
template: ` | ||
<div @click="$emit('search', { item })" /> | ||
`, | ||
data() { | ||
return { | ||
item: { | ||
id: 0 | ||
} | ||
}; | ||
} | ||
}); | ||
const TrackCustomEventParam = Vue.extend({ | ||
template: ` | ||
<child v-track:18015.search="handleClick" /> | ||
`, | ||
components: { | ||
child: Child | ||
}, | ||
data() { | ||
return { | ||
id: 0 | ||
}; | ||
}, | ||
methods: { | ||
handleClick({ id }) { | ||
this.id = id; | ||
} | ||
} | ||
}); | ||
|
||
localVue.use(VTrack, { | ||
trackEvents | ||
}); | ||
|
||
describe("TrackCustomEventParam", () => { | ||
it("确保自定义事件传参正确,并且点击事件次数等于埋点上报次数", () => { | ||
const wrapper = mount(TrackCustomEventParam, { | ||
localVue | ||
}); | ||
const vm = wrapper.vm; | ||
const childWrapper = wrapper.find(Child); | ||
|
||
expect(vm.id).toBe(0); | ||
childWrapper.setData({ item: { id: 1 } }); | ||
childWrapper.trigger("click"); | ||
expect(vm.id).toBe(1); | ||
childWrapper.setData({ item: { id: 2 } }); | ||
childWrapper.trigger("click"); | ||
expect(vm.id).toBe(2); | ||
expect(mockTrackAction).toBeCalledTimes(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* @Author: 宋慧武 | ||
* @Date: 2019-04-13 21:03:55 | ||
* @Last Modified by: 宋慧武 | ||
* @Last Modified time: 2019-04-13 22:17:26 | ||
*/ | ||
import Vue from "vue"; | ||
import VTrack from "@/"; | ||
import { mount, createLocalVue } from "@vue/test-utils"; | ||
|
||
const localVue = createLocalVue(); | ||
const mockTrackAction = jest.fn(); | ||
const trackEvents = { | ||
18015: mockTrackAction | ||
}; | ||
const Child = Vue.extend({ | ||
template: ` | ||
<div @click="$emit('click')" /> | ||
` | ||
}); | ||
const TrackCustomEvent = Vue.extend({ | ||
template: ` | ||
<child v-track:18015.click="handleClick" /> | ||
`, | ||
components: { | ||
child: Child | ||
}, | ||
data() { | ||
return { | ||
count: 0 | ||
}; | ||
}, | ||
methods: { | ||
handleClick() { | ||
this.count += 1; | ||
} | ||
} | ||
}); | ||
|
||
localVue.use(VTrack, { | ||
trackEvents | ||
}); | ||
|
||
describe("TrackCustomEvent", () => { | ||
it("确保自定义事件、埋点事件正常触发,且只触发一次", () => { | ||
const wrapper = mount(TrackCustomEvent, { | ||
localVue | ||
}); | ||
|
||
expect(wrapper.vm.count).toBe(0); | ||
wrapper.find(Child).trigger("click"); | ||
expect(wrapper.vm.count).toBe(1); | ||
expect(mockTrackAction).toBeCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters