This commit is contained in:
Pig Fang 2019-05-19 10:30:00 +08:00
parent 4012cfc46f
commit 979290c71c
2 changed files with 8 additions and 11 deletions

View File

@ -225,14 +225,8 @@ export default {
methods: { methods: {
async fetchData() { async fetchData() {
const { data = {} } = await this.$http.get(`/skinlib/info/${this.tid}`) const { data = {} } = await this.$http.get(`/skinlib/info/${this.tid}`)
this.name = data.name Object.assign(this, data)
this.type = data.type
this.likes = data.likes
this.hash = data.hash
this.uploader = data.uploader
this.size = data.size
this.uploadAt = data.upload_at this.uploadAt = data.upload_at
this.public = !!data.public
}, },
async addToCloset() { async addToCloset() {
this.$once('like-toggled', () => { this.$once('like-toggled', () => {

View File

@ -121,18 +121,19 @@ test('render nickname of uploader', () => {
expect(wrapper.text()).toContain('general.unexistent-user') expect(wrapper.text()).toContain('general.unexistent-user')
}) })
test('operation panel should not be rendered if not auth', () => { test('operation panel should not be rendered if user is anonymous', async () => {
Object.assign(window.blessing.extra, { currentUid: 0 }) Object.assign(window.blessing.extra, { currentUid: 0 })
Vue.prototype.$http.get.mockResolvedValue({ data: {} }) Vue.prototype.$http.get.mockResolvedValue({ data: { uploader: 1 } })
const wrapper = mount(Show, { const wrapper = mount(Show, {
mocks: { mocks: {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
}, },
}) })
await wrapper.vm.$nextTick()
expect(wrapper.find('.box-warning').exists()).toBeFalse() expect(wrapper.find('.box-warning').exists()).toBeFalse()
}) })
test('operation panel should not be rendered if not privileged', () => { test('operation panel should not be rendered if not privileged', async () => {
Object.assign(window.blessing.extra, { currentUid: 2 }) Object.assign(window.blessing.extra, { currentUid: 2 })
Vue.prototype.$http.get.mockResolvedValue({ data: { uploader: 1 } }) Vue.prototype.$http.get.mockResolvedValue({ data: { uploader: 1 } })
const wrapper = mount(Show, { const wrapper = mount(Show, {
@ -140,10 +141,11 @@ test('operation panel should not be rendered if not privileged', () => {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
}, },
}) })
await wrapper.vm.$nextTick()
expect(wrapper.find('.box-warning').exists()).toBeFalse() expect(wrapper.find('.box-warning').exists()).toBeFalse()
}) })
test('operation panel should be rendered if privileged', () => { test('operation panel should be rendered if privileged', async () => {
Object.assign(window.blessing.extra, { currentUid: 1 }) Object.assign(window.blessing.extra, { currentUid: 1 })
Vue.prototype.$http.get.mockResolvedValue({ data: { uploader: 1 } }) Vue.prototype.$http.get.mockResolvedValue({ data: { uploader: 1 } })
const wrapper = mount(Show, { const wrapper = mount(Show, {
@ -151,6 +153,7 @@ test('operation panel should be rendered if privileged', () => {
$route: ['/skinlib/show/1', '1'], $route: ['/skinlib/show/1', '1'],
}, },
}) })
await wrapper.vm.$nextTick()
expect(wrapper.find('.box-warning').exists()).toBeTrue() expect(wrapper.find('.box-warning').exists()).toBeTrue()
}) })