2019-04-25 23:24:24 +08:00
|
|
|
/* eslint-disable max-classes-per-file */
|
2019-03-15 11:42:41 +08:00
|
|
|
import 'jest-extended'
|
|
|
|
import Vue from 'vue'
|
2019-03-26 17:42:27 +08:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Input,
|
2019-05-04 17:09:44 +08:00
|
|
|
Radio,
|
2019-03-26 22:04:27 +08:00
|
|
|
Switch,
|
2019-03-26 17:42:27 +08:00
|
|
|
} from 'element-ui'
|
2018-07-27 16:54:36 +08:00
|
|
|
|
2018-07-27 18:54:39 +08:00
|
|
|
window.blessing = {
|
2019-03-15 11:42:41 +08:00
|
|
|
base_url: '',
|
|
|
|
site_name: 'Blessing Skin',
|
|
|
|
version: '4.0.0',
|
2019-04-19 19:32:15 +08:00
|
|
|
extra: {},
|
2019-11-26 11:44:44 +08:00
|
|
|
i18n: {},
|
2019-03-15 11:42:41 +08:00
|
|
|
}
|
2018-07-27 18:54:39 +08:00
|
|
|
|
2019-11-26 11:44:44 +08:00
|
|
|
class Headers extends Map {
|
2019-11-26 11:49:10 +08:00
|
|
|
constructor(headers: object = {}) {
|
2019-11-26 11:44:44 +08:00
|
|
|
// @ts-ignore
|
2019-03-17 21:09:46 +08:00
|
|
|
super(Object.entries(headers))
|
|
|
|
}
|
|
|
|
}
|
2019-11-26 11:44:44 +08:00
|
|
|
class Request {
|
|
|
|
public url: string
|
2019-03-17 21:09:46 +08:00
|
|
|
|
2019-11-26 11:44:44 +08:00
|
|
|
public headers: Headers
|
|
|
|
|
|
|
|
constructor(url: string, init: RequestInit) {
|
2019-04-25 23:24:24 +08:00
|
|
|
this.url = url
|
|
|
|
Object.assign(this, init)
|
2019-11-26 11:44:44 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
|
|
this.headers = new Headers(Object.entries(init.headers || {}))
|
2019-04-25 23:24:24 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-26 11:44:44 +08:00
|
|
|
Object.assign(window, { Headers, Request })
|
2019-04-25 23:24:24 +08:00
|
|
|
|
2019-03-15 11:42:41 +08:00
|
|
|
const noop = () => undefined
|
2019-11-26 11:44:44 +08:00
|
|
|
Object.assign(console, {
|
|
|
|
log: noop,
|
|
|
|
info: noop,
|
|
|
|
warn: noop,
|
|
|
|
error: noop,
|
|
|
|
})
|
2018-07-31 10:18:14 +08:00
|
|
|
|
2019-03-15 11:42:41 +08:00
|
|
|
Vue.prototype.$t = key => key
|
2018-07-27 16:54:36 +08:00
|
|
|
|
2019-11-26 11:49:10 +08:00
|
|
|
Vue.directive('t', (el: Element, { value }) => {
|
2019-03-15 11:42:41 +08:00
|
|
|
if (typeof value === 'string') {
|
|
|
|
el.innerHTML = value
|
|
|
|
} else if (typeof value === 'object') {
|
|
|
|
el.innerHTML = value.path
|
|
|
|
} else {
|
|
|
|
throw new Error('[i18n] Invalid arguments in `v-t` directive.')
|
|
|
|
}
|
|
|
|
})
|
2018-08-06 12:14:20 +08:00
|
|
|
|
|
|
|
Vue.prototype.$http = {
|
2019-03-15 11:42:41 +08:00
|
|
|
get: jest.fn(),
|
|
|
|
post: jest.fn(),
|
2019-09-08 18:57:19 +08:00
|
|
|
put: jest.fn(),
|
|
|
|
del: jest.fn(),
|
2019-03-15 11:42:41 +08:00
|
|
|
}
|
2019-03-25 22:01:57 +08:00
|
|
|
|
2019-03-26 09:44:04 +08:00
|
|
|
Vue.use(Button)
|
2019-03-26 17:42:27 +08:00
|
|
|
Vue.use(Input)
|
2019-05-04 17:09:44 +08:00
|
|
|
Vue.use(Radio)
|
2019-03-26 22:04:27 +08:00
|
|
|
Vue.use(Switch)
|
2019-11-26 11:44:44 +08:00
|
|
|
// @ts-ignore
|
2019-03-25 22:01:57 +08:00
|
|
|
Vue.prototype.$message = {
|
|
|
|
info: jest.fn(),
|
|
|
|
success: jest.fn(),
|
|
|
|
warning: jest.fn(),
|
|
|
|
error: jest.fn(),
|
|
|
|
}
|
2019-11-26 11:44:44 +08:00
|
|
|
// @ts-ignore
|
2019-03-25 22:01:57 +08:00
|
|
|
Vue.prototype.$msgbox = jest.fn()
|
|
|
|
Vue.prototype.$alert = jest.fn()
|
|
|
|
Vue.prototype.$confirm = jest.fn()
|
|
|
|
Vue.prototype.$prompt = jest.fn()
|