fix closet previewer don't apply texture type

fix #152
This commit is contained in:
Pig Fang 2020-03-19 09:26:29 +08:00
parent 2a3d9c544d
commit 4f76f05003
4 changed files with 23 additions and 21 deletions

View File

@ -9,7 +9,7 @@ export const PICTURES_COUNT = 7
interface Props { interface Props {
skin?: string skin?: string
cape?: string cape?: string
isAlex?: boolean isAlex: boolean
showIndicator?: boolean showIndicator?: boolean
initPositionZ?: number initPositionZ?: number
} }
@ -120,7 +120,7 @@ const Viewer: React.FC<Props> = props => {
useEffect(() => { useEffect(() => {
const viewer = viewRef.current const viewer = viewRef.current
viewer.playerObject.skin.slim = !!props.isAlex viewer.playerObject.skin.slim = props.isAlex
}, [props.isAlex]) }, [props.isAlex])
useEffect(() => { useEffect(() => {

View File

@ -27,7 +27,7 @@ const Previewer: React.FC<Props> = props => {
return ReactDOM.createPortal( return ReactDOM.createPortal(
<React.Suspense fallback={<ViewerSkeleton />}> <React.Suspense fallback={<ViewerSkeleton />}>
<Viewer skin={skin} cape={cape} showIndicator> <Viewer skin={skin} cape={cape} isAlex={props.isAlex} showIndicator>
{props.children} {props.children}
</Viewer> </Viewer>
</React.Suspense>, </React.Suspense>,

View File

@ -116,9 +116,7 @@ const Closet: React.FC = () => {
if (code === 0) { if (code === 0) {
toast.success(message) toast.success(message)
setItems(items => { setItems(items => {
items[index] = Object.assign({}, item, { items[index] = { ...item, pivot: { ...item.pivot, item_name: name } }
pivot: Object.assign({}, item.pivot, { item_name: name }),
})
return items.slice() return items.slice()
}) })
} else { } else {

View File

@ -4,37 +4,41 @@ import { t } from '@/scripts/i18n'
import Viewer, { PICTURES_COUNT } from '@/components/Viewer' import Viewer, { PICTURES_COUNT } from '@/components/Viewer'
test('custom footer', () => { test('custom footer', () => {
const { queryByText } = render(<Viewer>footer</Viewer>) const { queryByText } = render(<Viewer isAlex={false}>footer</Viewer>)
expect(queryByText('footer')).toBeInTheDocument() expect(queryByText('footer')).toBeInTheDocument()
}) })
describe('indicator', () => { describe('indicator', () => {
it('hidden by default', () => { it('hidden by default', () => {
const { queryByText } = render(<Viewer skin="skin" />) const { queryByText } = render(<Viewer skin="skin" isAlex={false} />)
expect(queryByText(t('general.skin'))).not.toBeInTheDocument() expect(queryByText(t('general.skin'))).not.toBeInTheDocument()
}) })
it('nothing', () => { it('nothing', () => {
const { queryByText } = render(<Viewer showIndicator />) const { queryByText } = render(<Viewer isAlex={false} showIndicator />)
expect(queryByText(t('general.skin'))).not.toBeInTheDocument() expect(queryByText(t('general.skin'))).not.toBeInTheDocument()
expect(queryByText(t('general.cape'))).not.toBeInTheDocument() expect(queryByText(t('general.cape'))).not.toBeInTheDocument()
}) })
it('skin only', () => { it('skin only', () => {
const { queryByText } = render(<Viewer skin="skin" showIndicator />) const { queryByText } = render(
<Viewer skin="skin" isAlex={false} showIndicator />,
)
expect(queryByText(t('general.skin'))).toBeInTheDocument() expect(queryByText(t('general.skin'))).toBeInTheDocument()
expect(queryByText(t('general.cape'))).not.toBeInTheDocument() expect(queryByText(t('general.cape'))).not.toBeInTheDocument()
}) })
it('cape only', () => { it('cape only', () => {
const { queryByText } = render(<Viewer cape="cape" showIndicator />) const { queryByText } = render(
<Viewer cape="cape" isAlex={false} showIndicator />,
)
expect(queryByText(t('general.skin'))).not.toBeInTheDocument() expect(queryByText(t('general.skin'))).not.toBeInTheDocument()
expect(queryByText(t('general.cape'))).toBeInTheDocument() expect(queryByText(t('general.cape'))).toBeInTheDocument()
}) })
it('skin and cape', () => { it('skin and cape', () => {
const { queryByText } = render( const { queryByText } = render(
<Viewer skin="skin" cape="cape" showIndicator />, <Viewer skin="skin" cape="cape" isAlex={false} showIndicator />,
) )
expect( expect(
queryByText(`${t('general.skin')} & ${t('general.cape')}`), queryByText(`${t('general.skin')} & ${t('general.cape')}`),
@ -46,31 +50,31 @@ describe('indicator', () => {
describe('actions', () => { describe('actions', () => {
it('toggle run', () => { it('toggle run', () => {
const { getByTitle } = render(<Viewer />) const { getByTitle } = render(<Viewer isAlex={false} />)
fireEvent.click(getByTitle(`${t('general.walk')} / ${t('general.run')}`)) fireEvent.click(getByTitle(`${t('general.walk')} / ${t('general.run')}`))
}) })
it('toggle rotation', () => { it('toggle rotation', () => {
const { getByTitle } = render(<Viewer />) const { getByTitle } = render(<Viewer isAlex={false} />)
fireEvent.click(getByTitle(t('general.rotation'))) fireEvent.click(getByTitle(t('general.rotation')))
}) })
it('toggle pause', () => { it('toggle pause', () => {
const { getByTitle } = render(<Viewer />) const { getByTitle } = render(<Viewer isAlex={false} />)
const icon = getByTitle(t('general.pause')) const icon = getByTitle(t('general.pause'))
fireEvent.click(icon) fireEvent.click(icon)
expect(icon).toHaveClass('fa-play') expect(icon).toHaveClass('fa-play')
}) })
it('reset', () => { it('reset', () => {
const { getByTitle } = render(<Viewer />) const { getByTitle } = render(<Viewer isAlex={false} />)
fireEvent.click(getByTitle(t('general.reset'))) fireEvent.click(getByTitle(t('general.reset')))
}) })
}) })
describe('background', () => { describe('background', () => {
it('white', () => { it('white', () => {
const { getByTitle, baseElement } = render(<Viewer />) const { getByTitle, baseElement } = render(<Viewer isAlex={false} />)
fireEvent.click(getByTitle(t('colors.white'))) fireEvent.click(getByTitle(t('colors.white')))
expect( expect(
baseElement.querySelector<HTMLDivElement>('.card-body')!.style.background, baseElement.querySelector<HTMLDivElement>('.card-body')!.style.background,
@ -78,7 +82,7 @@ describe('background', () => {
}) })
it('black', () => { it('black', () => {
const { getByTitle, baseElement } = render(<Viewer />) const { getByTitle, baseElement } = render(<Viewer isAlex={false} />)
fireEvent.click(getByTitle(t('colors.black'))) fireEvent.click(getByTitle(t('colors.black')))
expect( expect(
baseElement.querySelector<HTMLDivElement>('.card-body')!.style.background, baseElement.querySelector<HTMLDivElement>('.card-body')!.style.background,
@ -86,7 +90,7 @@ describe('background', () => {
}) })
it('white', () => { it('white', () => {
const { getByTitle, baseElement } = render(<Viewer />) const { getByTitle, baseElement } = render(<Viewer isAlex={false} />)
fireEvent.click(getByTitle(t('colors.gray'))) fireEvent.click(getByTitle(t('colors.gray')))
expect( expect(
baseElement.querySelector<HTMLDivElement>('.card-body')!.style.background, baseElement.querySelector<HTMLDivElement>('.card-body')!.style.background,
@ -94,7 +98,7 @@ describe('background', () => {
}) })
it('previous picture', () => { it('previous picture', () => {
const { getByTitle, baseElement } = render(<Viewer />) const { getByTitle, baseElement } = render(<Viewer isAlex={false} />)
fireEvent.click(getByTitle(t('colors.prev'))) fireEvent.click(getByTitle(t('colors.prev')))
expect( expect(
@ -108,7 +112,7 @@ describe('background', () => {
}) })
it('next picture', () => { it('next picture', () => {
const { getByTitle, baseElement } = render(<Viewer />) const { getByTitle, baseElement } = render(<Viewer isAlex={false} />)
fireEvent.click(getByTitle(t('colors.next'))) fireEvent.click(getByTitle(t('colors.next')))
expect( expect(