fix previewing textures at players page

This commit is contained in:
Pig Fang 2020-06-11 17:53:21 +08:00
parent d018f207f3
commit 9f6cec56a8
2 changed files with 13 additions and 17 deletions

View File

@ -2,8 +2,6 @@ import { useState, useEffect } from 'react'
import * as fetch from '../net'
import { Texture, TextureType } from '../types'
type Response = fetch.ResponseBody<Texture>
export default function useTexture() {
const [tid, setTid] = useState(0)
const [url, setUrl] = useState('')
@ -16,9 +14,7 @@ export default function useTexture() {
}
const getTexture = async () => {
const {
data: { hash, type },
} = await fetch.get<Response>(`/skinlib/info/${tid}`)
const { hash, type } = await fetch.get<Texture>(`/skinlib/info/${tid}`)
setUrl(`${blessing.base_url}/textures/${hash}`)
setType(type)

View File

@ -66,8 +66,8 @@ describe('select player automatically', () => {
it('only one player', async () => {
fetch.get
.mockResolvedValueOnce([fixture])
.mockResolvedValueOnce({ data: { hash: '', type: TextureType.Steve } })
.mockResolvedValueOnce({ data: { hash: '', type: TextureType.Cape } })
.mockResolvedValueOnce({ hash: '', type: TextureType.Steve })
.mockResolvedValueOnce({ hash: '', type: TextureType.Cape })
render(<Players />)
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
@ -97,8 +97,8 @@ describe('2d preview', () => {
it('skin and cape', async () => {
fetch.get
.mockResolvedValueOnce([fixture])
.mockResolvedValueOnce({ data: { hash: 'a', type: TextureType.Steve } })
.mockResolvedValueOnce({ data: { hash: 'b', type: TextureType.Cape } })
.mockResolvedValueOnce({ hash: 'a', type: TextureType.Steve })
.mockResolvedValueOnce({ hash: 'b', type: TextureType.Cape })
const { getByAltText, getByText } = render(<Players />)
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
@ -118,7 +118,7 @@ describe('2d preview', () => {
it('skin only', async () => {
fetch.get
.mockResolvedValueOnce([{ ...fixture, tid_cape: 0 }])
.mockResolvedValueOnce({ data: { hash: 'a', type: TextureType.Steve } })
.mockResolvedValueOnce({ hash: 'a', type: TextureType.Steve })
const { getByAltText, queryByAltText, getByText, queryByText } = render(
<Players />,
@ -138,7 +138,7 @@ describe('2d preview', () => {
it('cape only', async () => {
fetch.get
.mockResolvedValueOnce([{ ...fixture, tid_skin: 0 }])
.mockResolvedValueOnce({ data: { hash: 'a', type: TextureType.Cape } })
.mockResolvedValueOnce({ hash: 'a', type: TextureType.Cape })
const { getByAltText, queryByAltText, getByText, queryByText } = render(
<Players />,
@ -265,8 +265,8 @@ describe('edit player name', () => {
beforeEach(() => {
fetch.get
.mockResolvedValueOnce([fixture])
.mockResolvedValueOnce({ data: { hash: 'a', type: 'skin' } })
.mockResolvedValueOnce({ data: { hash: 'b', type: TextureType.Cape } })
.mockResolvedValueOnce({ hash: 'a', type: 'skin' })
.mockResolvedValueOnce({ hash: 'b', type: TextureType.Cape })
})
it('succeeded', async () => {
@ -346,8 +346,8 @@ describe('reset texture', () => {
beforeEach(() => {
fetch.get
.mockResolvedValueOnce([fixture])
.mockResolvedValueOnce({ data: { hash: 'a', type: 'skin' } })
.mockResolvedValueOnce({ data: { hash: 'b', type: TextureType.Cape } })
.mockResolvedValueOnce({ hash: 'a', type: 'skin' })
.mockResolvedValueOnce({ hash: 'b', type: TextureType.Cape })
})
it('clear skin and cape', async () => {
@ -457,8 +457,8 @@ describe('delete player', () => {
beforeEach(() => {
fetch.get
.mockResolvedValueOnce([fixture])
.mockResolvedValueOnce({ data: { hash: 'a', type: 'skin' } })
.mockResolvedValueOnce({ data: { hash: 'b', type: TextureType.Cape } })
.mockResolvedValueOnce({ hash: 'a', type: 'skin' })
.mockResolvedValueOnce({ hash: 'b', type: TextureType.Cape })
})
it('succeeded', async () => {