upgrade deps

This commit is contained in:
Pig Fang 2020-03-28 12:18:52 +08:00
parent aa835f7d03
commit 6dc22f73f7
15 changed files with 1884 additions and 1534 deletions

View File

@ -47,11 +47,11 @@
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.7",
"@gplane/tsconfig": "^1.0.0",
"@testing-library/jest-dom": "^5.0.2",
"@testing-library/react": "^9.4.0",
"@testing-library/jest-dom": "^5.3.0",
"@testing-library/react": "^10.0.1",
"@types/bootstrap": "^4.3.1",
"@types/echarts": "^4.4.2",
"@types/jest": "^24.0.25",
"@types/jest": "^25.1.4",
"@types/jquery": "^3.3.29",
"@types/js-yaml": "^3.12.2",
"@types/lodash.debounce": "^4.0.6",
@ -64,7 +64,7 @@
"@typescript-eslint/parser": "^2.8.0",
"@vue/test-utils": "^1.0.0-beta.29",
"autoprefixer": "^9.7.3",
"babel-jest": "^24.9.0",
"babel-jest": "^25.2.3",
"babel-loader": "^8.0.6",
"babel-plugin-dynamic-import-node": "^2.3.0",
"cache-loader": "^4.1.0",
@ -74,8 +74,8 @@
"eslint-formatter-beauty": "^3.0.0",
"eslint-plugin-vue": "^6.1.2",
"file-loader": "^5.0.2",
"jest": "^24.9.0",
"jest-extended": "^0.11.2",
"jest": "^25.2.3",
"jest-extended": "^0.11.5",
"js-yaml": "^3.13.1",
"mini-css-extract-plugin": "^0.9.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
@ -86,7 +86,7 @@
"style-loader": "^1.1.2",
"stylus": "^0.54.7",
"stylus-loader": "^3.0.2",
"ts-jest": "^24.3.0",
"ts-jest": "^25.2.1",
"ts-loader": "^6.2.1",
"typescript": "^3.8.3",
"url-loader": "^3.0.0",
@ -99,7 +99,8 @@
"webpack-manifest-plugin": "^2.2.0"
},
"resolutions": {
"caniuse-lite": "*"
"caniuse-lite": "*",
"@types/testing-library__dom": "^7.0.0"
},
"browserslist": [
"> 1%",

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, wait, fireEvent } from '@testing-library/react'
import { render, waitFor, fireEvent } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import PluginsManagement from '@/views/admin/PluginsManagement'
@ -37,7 +37,7 @@ test('plugin info box', async () => {
])
const { queryByTitle, queryByText } = render(<PluginsManagement />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(queryByTitle(t('admin.configurePlugin'))).not.toBeNull()
expect(queryByTitle(t('admin.pluginReadme'))).not.toBeNull()
@ -68,15 +68,15 @@ describe('enable plugin', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'success' })
const { getByTitle, getByRole, queryByText } = render(<PluginsManagement />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('admin.enablePlugin')))
await wait()
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'enable',
name: 'a',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'enable',
name: 'a',
}),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(getByTitle(t('admin.disablePlugin'))).toBeChecked()
@ -90,11 +90,15 @@ describe('enable plugin', () => {
})
const { getByTitle, getByText, queryByText } = render(<PluginsManagement />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('admin.enablePlugin')))
await wait()
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'enable',
name: 'a',
}),
)
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'enable',
name: 'a',
@ -121,15 +125,15 @@ describe('disable plugin', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'success' })
const { getByTitle, getByRole, queryByText } = render(<PluginsManagement />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('admin.disablePlugin')))
await wait()
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'disable',
name: 'a',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'disable',
name: 'a',
}),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(getByTitle(t('admin.enablePlugin'))).not.toBeChecked()
@ -139,11 +143,15 @@ describe('disable plugin', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByTitle, getByRole, queryByText } = render(<PluginsManagement />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('admin.disablePlugin')))
await wait()
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'disable',
name: 'a',
}),
)
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'disable',
name: 'a',
@ -167,13 +175,11 @@ describe('delete plugin', () => {
it('rejected by user', async () => {
const { getByTitle, getByText } = render(<PluginsManagement />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('admin.deletePlugin')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
})
it('succeeded', async () => {
@ -182,16 +188,16 @@ describe('delete plugin', () => {
const { getByTitle, getByText, getByRole, queryByText } = render(
<PluginsManagement />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('admin.deletePlugin')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'delete',
name: 'a',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'delete',
name: 'a',
}),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(queryByText('My Plugin')).toBeNull()
@ -203,12 +209,16 @@ describe('delete plugin', () => {
const { getByTitle, getByText, getByRole, queryByText } = render(
<PluginsManagement />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('admin.deletePlugin')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'delete',
name: 'a',
}),
)
expect(fetch.post).toBeCalledWith('/admin/plugins/manage', {
action: 'delete',
name: 'a',
@ -224,7 +234,7 @@ describe('upload plugin archive', () => {
fetch.get.mockResolvedValue([])
const { getAllByText } = render(<PluginsManagement />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getAllByText(t('general.submit'))[0])
expect(fetch.post).not.toBeCalled()
@ -237,20 +247,20 @@ describe('upload plugin archive', () => {
const { getByTitle, getAllByText, getByRole, queryByText } = render(
<PluginsManagement />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
const file = new File([], 'plugin.zip')
fireEvent.change(getByTitle(t('skinlib.upload.select-file')), {
target: { files: [file] },
})
fireEvent.click(getAllByText(t('general.submit'))[0])
await wait()
expect(fetch.get).toBeCalledTimes(2)
expect(fetch.post).toBeCalledWith(
'/admin/plugins/upload',
expect.any(FormData),
)
await waitFor(() => {
expect(fetch.get).toBeCalledTimes(2)
expect(fetch.post).toBeCalledWith(
'/admin/plugins/upload',
expect.any(FormData),
)
})
const formData: FormData = fetch.post.mock.calls[0][1]
expect(formData.get('file')).toStrictEqual(file)
expect(queryByText('plugin.zip')).not.toBeInTheDocument()
@ -265,20 +275,20 @@ describe('upload plugin archive', () => {
const { getByTitle, getAllByText, getByRole, queryByText } = render(
<PluginsManagement />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
const file = new File([], 'plugin.zip')
fireEvent.change(getByTitle(t('skinlib.upload.select-file')), {
target: { files: [file] },
})
fireEvent.click(getAllByText(t('general.submit'))[0])
await wait()
expect(fetch.get).toBeCalledTimes(1)
expect(fetch.post).toBeCalledWith(
'/admin/plugins/upload',
expect.any(FormData),
)
await waitFor(() => {
expect(fetch.get).toBeCalledTimes(1)
expect(fetch.post).toBeCalledWith(
'/admin/plugins/upload',
expect.any(FormData),
)
})
expect(queryByText('plugin.zip')).toBeInTheDocument()
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
@ -297,17 +307,17 @@ describe('submit remote URL', () => {
queryByText,
queryByDisplayValue,
} = render(<PluginsManagement />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.input(getByLabelText('URL'), {
target: { value: 'https://example.com/a.zip' },
})
fireEvent.click(getAllByText(t('general.submit'))[1])
await wait()
expect(fetch.get).toBeCalledTimes(2)
expect(fetch.post).toBeCalledWith('/admin/plugins/wget', {
url: 'https://example.com/a.zip',
await waitFor(() => {
expect(fetch.get).toBeCalledTimes(2)
expect(fetch.post).toBeCalledWith('/admin/plugins/wget', {
url: 'https://example.com/a.zip',
})
})
expect(
queryByDisplayValue('https://example.com/a.zip'),
@ -327,17 +337,17 @@ describe('submit remote URL', () => {
queryByText,
queryByDisplayValue,
} = render(<PluginsManagement />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.input(getByLabelText('URL'), {
target: { value: 'https://example.com/a.zip' },
})
fireEvent.click(getAllByText(t('general.submit'))[1])
await wait()
expect(fetch.get).toBeCalledTimes(1)
expect(fetch.post).toBeCalledWith('/admin/plugins/wget', {
url: 'https://example.com/a.zip',
await waitFor(() => {
expect(fetch.get).toBeCalledTimes(1)
expect(fetch.post).toBeCalledWith('/admin/plugins/wget', {
url: 'https://example.com/a.zip',
})
})
expect(queryByDisplayValue('https://example.com/a.zip')).toBeInTheDocument()
expect(queryByText('failed')).toBeInTheDocument()

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, wait, fireEvent } from '@testing-library/react'
import { render, waitFor, fireEvent } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import Forgot from '@/views/auth/Forgot'
@ -19,12 +19,12 @@ describe('submit', () => {
target: { value: 'abc' },
})
fireEvent.click(getByText(t('auth.forgot.button')))
await wait()
expect(fetch.post).toBeCalledWith('/auth/forgot', {
email: 'a@b.c',
captcha: 'abc',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/auth/forgot', {
email: 'a@b.c',
captcha: 'abc',
}),
)
expect(queryByText('ok')).toBeInTheDocument()
})
@ -40,12 +40,12 @@ describe('submit', () => {
target: { value: 'abc' },
})
fireEvent.click(getByText(t('auth.forgot.button')))
await wait()
expect(fetch.post).toBeCalledWith('/auth/forgot', {
email: 'a@b.c',
captcha: 'abc',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/auth/forgot', {
email: 'a@b.c',
captcha: 'abc',
}),
)
expect(queryByText('failed')).toBeInTheDocument()
})
})

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, wait, fireEvent } from '@testing-library/react'
import { render, waitFor, fireEvent } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import Login from '@/views/auth/Login'
@ -32,13 +32,13 @@ describe('submit form', () => {
target: { value: 'password' },
})
fireEvent.click(getByText(t('auth.login')))
await wait()
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
}),
)
})
it('remember me', async () => {
@ -59,13 +59,13 @@ describe('submit form', () => {
})
fireEvent.click(getByLabelText(t('auth.keep')))
fireEvent.click(getByText(t('auth.login')))
await wait()
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: true,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: true,
}),
)
})
it('failed', async () => {
@ -83,13 +83,13 @@ describe('submit form', () => {
target: { value: 'password' },
})
fireEvent.click(getByText(t('auth.login')))
await wait()
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
}),
)
expect(queryByText('failed')).toBeInTheDocument()
})
@ -113,13 +113,13 @@ describe('submit form', () => {
target: { value: 'password' },
})
fireEvent.click(getByText(t('auth.login')))
await wait()
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(queryByText(t('auth.tooManyFails.captcha'))).toBeInTheDocument()
expect(queryByAltText(t('auth.captcha'))).toBeInTheDocument()
@ -129,14 +129,14 @@ describe('submit form', () => {
target: { value: 'captcha' },
})
fireEvent.click(getByText(t('auth.login')))
await wait()
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
captcha: 'captcha',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
captcha: 'captcha',
}),
)
})
it('too many fails with normal recaptcha', async () => {
@ -155,13 +155,13 @@ describe('submit form', () => {
target: { value: 'password' },
})
fireEvent.click(getByText(t('auth.login')))
await wait()
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
}),
)
expect(queryByText('failed')).toBeInTheDocument()
})
@ -182,13 +182,13 @@ describe('submit form', () => {
target: { value: 'password' },
})
fireEvent.click(getByText(t('auth.login')))
await wait()
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/auth/login', {
identification: 'a@b.c',
password: 'password',
keep: false,
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(queryByText(t('auth.tooManyFails.recaptcha'))).toBeInTheDocument()

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import { Texture } from '@/scripts/types'
@ -55,7 +55,7 @@ test('without authenticated', async () => {
fetch.get.mockResolvedValue({ data: fixtureSkin })
const { queryByText, queryByTitle } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(queryByText(fixtureSkin.name)).toBeInTheDocument()
expect(queryByText('steve')).toBeInTheDocument()
@ -73,7 +73,7 @@ test('authenticated but not uploader', async () => {
fetch.get.mockResolvedValue({ data: fixtureCape })
const { queryByText, queryByTitle } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(queryByText(fixtureCape.name)).toBeInTheDocument()
expect(queryByText(t('general.cape'))).toBeInTheDocument()
@ -92,8 +92,7 @@ test('uploader is not existed', async () => {
fetch.get.mockResolvedValue({ data: fixtureSkin })
const { queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(queryByText(t('general.unexistent-user'))).toBeInTheDocument()
})
@ -104,8 +103,7 @@ test('badges', async () => {
fetch.get.mockResolvedValue({ data: fixtureSkin })
const { queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(queryByText('STAFF')).toBeInTheDocument()
})
@ -117,7 +115,7 @@ test('apply to player', async () => {
.mockResolvedValueOnce({ data: [] })
const { getByText, getByLabelText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.apply')))
fireEvent.click(getByLabelText('Close'))
@ -131,11 +129,11 @@ test('set as avatar', async () => {
fetch.post.mockResolvedValue({ code: 0, message: 'ok' })
const { getByText, getByRole, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.setAsAvatar')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
await waitFor(() => expect(fetch.post).toBeCalledTimes(1))
expect(queryByText('ok')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
@ -149,7 +147,7 @@ describe('download texture', () => {
it('allowed', async () => {
const { getByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.show.download')))
})
@ -157,7 +155,7 @@ describe('download texture', () => {
it('not allowed', async () => {
window.blessing.extra.download = false
const { queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(queryByText(t('skinlib.show.download'))).not.toBeInTheDocument()
})
@ -172,7 +170,7 @@ describe('operation panel', () => {
window.blessing.extra.currentUid = fixtureSkin.uploader
const { queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(queryByText(t('skinlib.show.manage-notice'))).toBeInTheDocument()
})
@ -182,7 +180,7 @@ describe('operation panel', () => {
window.blessing.extra.admin = true
const { queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(queryByText(t('skinlib.show.manage-notice'))).toBeInTheDocument()
})
@ -198,7 +196,7 @@ describe('edit texture name', () => {
const { getByText, getAllByTitle, getByDisplayValue, queryByText } = render(
<Show />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getAllByTitle(t('skinlib.show.edit'))[0])
fireEvent.input(getByDisplayValue(fixtureSkin.name), {
@ -208,9 +206,7 @@ describe('edit texture name', () => {
expect(queryByText(t('skinlib.emptyNewTextureName'))).toBeInTheDocument()
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(fixtureSkin.name)).toBeInTheDocument()
})
@ -224,19 +220,19 @@ describe('edit texture name', () => {
getByRole,
queryByText,
} = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getAllByTitle(t('skinlib.show.edit'))[0])
fireEvent.input(getByDisplayValue(fixtureSkin.name), {
target: { value: 't' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/rename', {
tid: fixtureSkin.tid,
new_name: 't',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/rename', {
tid: fixtureSkin.tid,
new_name: 't',
}),
)
expect(queryByText('ok')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(queryByText('t')).toBeInTheDocument()
@ -252,19 +248,19 @@ describe('edit texture name', () => {
getByRole,
queryByText,
} = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getAllByTitle(t('skinlib.show.edit'))[0])
fireEvent.input(getByDisplayValue(fixtureSkin.name), {
target: { value: 't' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/rename', {
tid: fixtureSkin.tid,
new_name: 't',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/rename', {
tid: fixtureSkin.tid,
new_name: 't',
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
expect(queryByText(fixtureSkin.name)).toBeInTheDocument()
@ -281,14 +277,12 @@ describe('edit texture type', () => {
const { getByText, getAllByTitle, getByLabelText, queryByText } = render(
<Show />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getAllByTitle(t('skinlib.show.edit'))[1])
fireEvent.click(getByLabelText('Alex'))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText('steve')).toBeInTheDocument()
})
@ -302,17 +296,17 @@ describe('edit texture type', () => {
getByRole,
queryByText,
} = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getAllByTitle(t('skinlib.show.edit'))[1])
fireEvent.click(getByLabelText('Alex'))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/model', {
tid: fixtureSkin.tid,
model: 'alex',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/model', {
tid: fixtureSkin.tid,
model: 'alex',
}),
)
expect(queryByText('ok')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(queryByText('alex')).toBeInTheDocument()
@ -328,17 +322,17 @@ describe('edit texture type', () => {
getByRole,
queryByText,
} = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getAllByTitle(t('skinlib.show.edit'))[1])
fireEvent.click(getByLabelText('Alex'))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/model', {
tid: fixtureSkin.tid,
model: 'alex',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/model', {
tid: fixtureSkin.tid,
model: 'alex',
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
expect(queryByText('steve')).toBeInTheDocument()
@ -353,7 +347,7 @@ describe('add to closet', () => {
it('cancelled', async () => {
const { getByText, getByDisplayValue, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.addToCloset')))
fireEvent.input(getByDisplayValue(fixtureSkin.name), {
@ -363,9 +357,7 @@ describe('add to closet', () => {
expect(queryByText(t('skinlib.emptyItemName'))).toBeInTheDocument()
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
})
it('succeeded', async () => {
@ -374,19 +366,19 @@ describe('add to closet', () => {
const { getByText, getByDisplayValue, getByRole, queryByText } = render(
<Show />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.addToCloset')))
fireEvent.input(getByDisplayValue(fixtureSkin.name), {
target: { value: 't' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/user/closet/add', {
tid: fixtureSkin.tid,
name: 't',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/closet/add', {
tid: fixtureSkin.tid,
name: 't',
}),
)
expect(queryByText('ok')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(queryByText('2')).toBeInTheDocument()
@ -398,19 +390,19 @@ describe('add to closet', () => {
const { getByText, getByDisplayValue, getByRole, queryByText } = render(
<Show />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.addToCloset')))
fireEvent.input(getByDisplayValue(fixtureSkin.name), {
target: { value: 't' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/user/closet/add', {
tid: fixtureSkin.tid,
name: 't',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/closet/add', {
tid: fixtureSkin.tid,
name: 't',
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
expect(queryByText('1')).toBeInTheDocument()
@ -428,13 +420,15 @@ describe('remove from closet', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'ok' })
const { getByText, getByRole, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.removeFromCloset')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(`/user/closet/remove/${fixtureSkin.tid}`)
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/closet/remove/${fixtureSkin.tid}`,
),
)
expect(queryByText('ok')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(queryByText('0')).toBeInTheDocument()
@ -444,13 +438,15 @@ describe('remove from closet', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByText, getByRole, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.removeFromCloset')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(`/user/closet/remove/${fixtureSkin.tid}`)
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/closet/remove/${fixtureSkin.tid}`,
),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
expect(queryByText('1')).toBeInTheDocument()
@ -467,7 +463,7 @@ describe('report texture', () => {
window.blessing.extra.report = 5
const { getByText, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.report.title')))
expect(queryByText(t('skinlib.report.positive', { score: 5 })))
@ -480,7 +476,7 @@ describe('report texture', () => {
window.blessing.extra.report = -5
const { getByText, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.report.title')))
expect(queryByText(t('skinlib.report.negative', { score: 5 })))
@ -495,19 +491,19 @@ describe('report texture', () => {
const { getByText, getByPlaceholderText, getByRole, queryByText } = render(
<Show />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.report.title')))
fireEvent.input(getByPlaceholderText(t('skinlib.report.reason')), {
target: { value: 'illegal' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/report', {
tid: fixtureSkin.tid,
reason: 'illegal',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/report', {
tid: fixtureSkin.tid,
reason: 'illegal',
}),
)
expect(queryByText('ok')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
})
@ -518,19 +514,19 @@ describe('report texture', () => {
const { getByText, getByPlaceholderText, getByRole, queryByText } = render(
<Show />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.report.title')))
fireEvent.input(getByPlaceholderText(t('skinlib.report.reason')), {
target: { value: 'illegal' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/report', {
tid: fixtureSkin.tid,
reason: 'illegal',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/report', {
tid: fixtureSkin.tid,
reason: 'illegal',
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
})
@ -545,13 +541,11 @@ describe('change privacy', () => {
fetch.get.mockResolvedValue({ data: fixtureSkin })
const { getByText, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.setAsPrivate')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(t('skinlib.setAsPrivate'))).toBeInTheDocument()
})
@ -560,15 +554,15 @@ describe('change privacy', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'ok' })
const { getByText, getByRole, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.setAsPrivate')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/privacy', {
tid: fixtureSkin.tid,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/privacy', {
tid: fixtureSkin.tid,
}),
)
expect(queryByText('ok')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(queryByText(t('skinlib.setAsPublic'))).toBeInTheDocument()
@ -579,15 +573,15 @@ describe('change privacy', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByText, getByRole, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.setAsPublic')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/privacy', {
tid: fixtureSkin.tid,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/privacy', {
tid: fixtureSkin.tid,
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
expect(queryByText(t('skinlib.setAsPublic'))).toBeInTheDocument()
@ -602,28 +596,26 @@ describe('delete texture', () => {
it('cancelled', async () => {
const { getByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.show.delete-texture')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
})
it('succeeded', async () => {
fetch.post.mockResolvedValue({ code: 0, message: 'ok' })
const { getByText, getByRole, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.show.delete-texture')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/delete', {
tid: fixtureSkin.tid,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/delete', {
tid: fixtureSkin.tid,
}),
)
expect(queryByText('ok')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
@ -634,15 +626,15 @@ describe('delete texture', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByText, getByRole, queryByText } = render(<Show />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('skinlib.show.delete-texture')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/skinlib/delete', {
tid: fixtureSkin.tid,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/skinlib/delete', {
tid: fixtureSkin.tid,
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
})

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import { Paginator } from '@/scripts/types'
@ -37,7 +37,7 @@ test('without authenticated', async () => {
fetch.get.mockResolvedValue(createPaginator([]))
const { queryByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
expect(fetch.get).toBeCalledWith(
'/skinlib/list',
@ -56,20 +56,20 @@ test('search by keyword', async () => {
fetch.get.mockResolvedValue(createPaginator([]))
const { getByText, getByPlaceholderText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.input(getByPlaceholderText(t('vendor.datatable.search')), {
target: { value: 'k' },
})
fireEvent.click(getByText(t('general.submit')))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('keyword')).toBe('k')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('keyword')).toBe('k')
return true
}),
),
)
})
@ -78,17 +78,17 @@ test('select uploaded by self', async () => {
fetch.get.mockResolvedValue(createPaginator([]))
const { getByText, queryByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('skinlib.seeMyUpload')))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('uploader')).toBe('1')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('uploader')).toBe('1')
return true
}),
),
)
expect(queryByText(t('skinlib.filter.uploader', { uid: 1 })))
})
@ -100,32 +100,32 @@ test('reset query', async () => {
const { getByText, getByPlaceholderText, queryByText } = render(
<SkinLibrary />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText('Steve'))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.input(getByPlaceholderText(t('vendor.datatable.search')), {
target: { value: 'k' },
})
fireEvent.click(getByText(t('general.submit')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('skinlib.seeMyUpload')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('skinlib.sort.likes')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('skinlib.reset')))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('skin')
expect(search.get('keyword')).toBeNull()
expect(search.get('uploader')).toBeNull()
expect(search.get('sort')).toBe('time')
expect(search.get('page')).toBe('1')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('skin')
expect(search.get('keyword')).toBeNull()
expect(search.get('uploader')).toBeNull()
expect(search.get('sort')).toBe('time')
expect(search.get('page')).toBe('1')
return true
}),
),
)
expect(queryByText(t('skinlib.filter.uploader', { uid: 1 })))
})
@ -134,24 +134,24 @@ test('browser goes back', async () => {
fetch.get.mockResolvedValue(createPaginator([]))
const { getByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText('Steve'))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
const state: string = window.history.state
const event = new PopStateEvent('popstate', {
state: state.replace('steve', 'skin'),
})
window.dispatchEvent(event)
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('skin')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('skin')
return true
}),
),
)
})
@ -160,7 +160,7 @@ test('pagination', async () => {
fetch.get.mockResolvedValue(response)
const { getByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText('2'))
@ -179,7 +179,7 @@ test('library item', async () => {
const { getByText, queryByText, queryAllByText, queryByAltText } = render(
<SkinLibrary />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
expect(queryAllByText('Steve')).toHaveLength(2)
expect(queryByText(fixtureItem.name)).toBeInTheDocument()
@ -190,14 +190,14 @@ test('library item', async () => {
expect(queryByText(fixtureItem.nickname)).toBeInTheDocument()
fireEvent.click(getByText(fixtureItem.nickname))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('uploader')).toBe(fixtureItem.uploader.toString())
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('uploader')).toBe(fixtureItem.uploader.toString())
return true
}),
),
)
const search = new URLSearchParams(location.search)
expect(search.get('uploader')).toBe(fixtureItem.uploader.toString())
@ -208,7 +208,7 @@ test('private texture', async () => {
fetch.get.mockResolvedValue(createPaginator([item]))
const { queryByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
expect(queryByText(t('skinlib.private'))).toBeInTheDocument()
})
@ -220,19 +220,19 @@ describe('by filter', () => {
it('skin', async () => {
const { getByText, queryAllByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText('Steve'))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('general.skin')))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('skin')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('skin')
return true
}),
),
)
expect(queryAllByText(t('general.skin'))).toHaveLength(2)
const search = new URLSearchParams(location.search)
@ -241,17 +241,17 @@ describe('by filter', () => {
it('steve', async () => {
const { getByText, queryAllByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText('Steve'))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('steve')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('steve')
return true
}),
),
)
expect(queryAllByText('Steve')).toHaveLength(2)
const search = new URLSearchParams(location.search)
@ -260,17 +260,17 @@ describe('by filter', () => {
it('alex', async () => {
const { getByText, queryAllByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText('Alex'))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('alex')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('alex')
return true
}),
),
)
expect(queryAllByText('Alex')).toHaveLength(2)
const search = new URLSearchParams(location.search)
@ -279,17 +279,17 @@ describe('by filter', () => {
it('cape', async () => {
const { getByText, queryAllByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('general.cape')))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('cape')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('filter')).toBe('cape')
return true
}),
),
)
expect(queryAllByText(t('general.cape'))).toHaveLength(2)
const search = new URLSearchParams(location.search)
@ -304,19 +304,19 @@ describe('sorting', () => {
it('by time', async () => {
const { getByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('skinlib.sort.likes')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('skinlib.sort.time')))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('sort')).toBe('time')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('sort')).toBe('time')
return true
}),
),
)
const search = new URLSearchParams(location.search)
expect(search.get('sort')).toBe('time')
@ -324,17 +324,17 @@ describe('sorting', () => {
it('by likes', async () => {
const { getByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('skinlib.sort.likes')))
await wait()
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('sort')).toBe('likes')
return true
}),
await waitFor(() =>
expect(fetch.get).toHaveBeenLastCalledWith(
'/skinlib/list',
expect.toSatisfy((search: URLSearchParams) => {
expect(search.get('sort')).toBe('likes')
return true
}),
),
)
const search = new URLSearchParams(location.search)
expect(search.get('sort')).toBe('likes')
@ -354,7 +354,7 @@ describe('add to closet', () => {
it('without authenticated', async () => {
const { getByText, queryByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(fixtureItem.likes.toString()))
expect(queryByText(t('skinlib.anonymous'))).toBeInTheDocument()
@ -366,13 +366,11 @@ describe('add to closet', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'ok' })
const { getByText, queryByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(fixtureItem.likes.toString()))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalled()
await waitFor(() => expect(fetch.post).toBeCalled())
expect(queryByText((fixtureItem.likes + 1).toString())).toBeInTheDocument()
})
@ -381,13 +379,11 @@ describe('add to closet', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByText, queryByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(fixtureItem.likes.toString()))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalled()
await waitFor(() => expect(fetch.post).toBeCalled())
expect(queryByText(fixtureItem.likes.toString())).toBeInTheDocument()
})
})
@ -408,13 +404,11 @@ describe('remove from closet', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'ok' })
const { getByText, queryByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(fixtureItem.likes.toString()))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalled()
await waitFor(() => expect(fetch.post).toBeCalled())
expect(queryByText((fixtureItem.likes - 1).toString())).toBeInTheDocument()
})
@ -422,13 +416,11 @@ describe('remove from closet', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByText, queryByText } = render(<SkinLibrary />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(fixtureItem.likes.toString()))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalled()
await waitFor(() => expect(fetch.post).toBeCalled())
expect(queryByText(fixtureItem.likes.toString())).toBeInTheDocument()
})
})

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import { isAlex } from '@/scripts/textureUtils'
@ -103,30 +103,28 @@ describe('input file', () => {
it('select skin type automatically', async () => {
isAlex.mockResolvedValue(true)
const { getByTitle, getByLabelText } = render(<Upload />)
const { getByTitle, findByLabelText } = render(<Upload />)
const file = new File([], 't.png')
fireEvent.change(getByTitle(t('skinlib.upload.select-file')), {
target: { files: [file] },
})
await wait()
expect(getByLabelText('Alex')).toBeChecked()
expect(await findByLabelText('Alex')).toBeChecked()
})
it('do not overwrite "cape" type', async () => {
const { getByTitle, getByLabelText } = render(<Upload />)
const { getByTitle, getByLabelText, findByLabelText } = render(<Upload />)
fireEvent.click(getByLabelText(t('general.cape')))
await wait()
await waitFor(() => {})
const file = new File([], 't.png')
fireEvent.change(getByTitle(t('skinlib.upload.select-file')), {
target: { files: [file] },
})
await wait()
expect(getByLabelText(t('general.cape'))).toBeChecked()
expect(await findByLabelText(t('general.cape'))).toBeChecked()
})
})
@ -234,7 +232,7 @@ describe('upload texture', () => {
})
fireEvent.click(getByText(t('skinlib.upload.button')))
await wait()
await waitFor(() => expect(fetch.post).toBeCalled())
})
it('duplicated texture detected', async () => {
@ -248,7 +246,7 @@ describe('upload texture', () => {
})
fireEvent.click(getByText(t('skinlib.upload.button')))
await wait()
await waitFor(() => expect(fetch.post).toBeCalled())
expect(queryByText('dup')).toBeInTheDocument()
fireEvent.click(getByText(t('user.viewInSkinlib')))
@ -265,7 +263,7 @@ describe('upload texture', () => {
})
fireEvent.click(getByText(t('skinlib.upload.button')))
await wait()
await waitFor(() => expect(fetch.post).toBeCalled())
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
})

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import BindPlayers from '@/views/user/BindPlayers'
@ -20,13 +20,15 @@ describe('submit', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'success' })
const { getByText, getByLabelText, queryByText } = render(<BindPlayers />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByLabelText('reina'))
fireEvent.click(getByText(t('general.submit')))
await wait()
expect(fetch.post).toBeCalledWith('/user/player/bind', { player: 'reina' })
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/player/bind', {
player: 'reina',
}),
)
expect(queryByText('success')).toBeInTheDocument()
fireEvent.click(getByText(t('general.confirm')))
@ -39,15 +41,17 @@ describe('submit', () => {
const { getByText, getByPlaceholderText, queryByText } = render(
<BindPlayers />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.input(getByPlaceholderText(t('general.player.player-name')), {
target: { value: 'kumiko' },
})
fireEvent.click(getByText(t('general.submit')))
await wait()
expect(fetch.post).toBeCalledWith('/user/player/bind', { player: 'kumiko' })
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/player/bind', {
player: 'kumiko',
}),
)
expect(queryByText('success')).toBeInTheDocument()
fireEvent.click(getByText(t('general.confirm')))
@ -60,15 +64,17 @@ describe('submit', () => {
const { getByText, getByPlaceholderText, queryByText } = render(
<BindPlayers />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.input(getByPlaceholderText(t('general.player.player-name')), {
target: { value: 'kumiko' },
})
fireEvent.click(getByText(t('general.submit')))
await wait()
expect(fetch.post).toBeCalledWith('/user/player/bind', { player: 'kumiko' })
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/player/bind', {
player: 'kumiko',
}),
)
expect(queryByText('failed')).toBeInTheDocument()
fireEvent.click(getByText(t('general.confirm')))

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import $ from 'jquery'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
@ -80,7 +80,7 @@ test('empty closet', async () => {
fetch.get.mockResolvedValue(createPaginator([]))
const { queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(queryByText(/skin library/i)).toBeInTheDocument()
})
@ -91,17 +91,17 @@ test('categories', async () => {
.mockResolvedValueOnce(createPaginator([fixtureSkin]))
const { getByText, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
expect(queryByText(fixtureSkin.pivot.item_name)).toBeInTheDocument()
expect(queryByText(fixtureCape.pivot.item_name)).not.toBeInTheDocument()
fireEvent.click(getByText(t('general.cape')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
expect(queryByText(fixtureSkin.pivot.item_name)).not.toBeInTheDocument()
expect(queryByText(fixtureCape.pivot.item_name)).toBeInTheDocument()
fireEvent.click(getByText(t('general.skin')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
expect(queryByText(fixtureSkin.pivot.item_name)).toBeInTheDocument()
expect(queryByText(fixtureCape.pivot.item_name)).not.toBeInTheDocument()
})
@ -111,15 +111,13 @@ test('search textures', async () => {
.mockResolvedValueOnce(createPaginator([fixtureSkin]))
.mockResolvedValueOnce(createPaginator([]))
const { getByPlaceholderText, queryByText } = render(<Closet />)
await wait()
const { getByPlaceholderText, findByText } = render(<Closet />)
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.input(getByPlaceholderText(t('user.typeToSearch')), {
target: { value: 'abc' },
})
await wait()
expect(queryByText(/no result/i)).toBeInTheDocument()
expect(await findByText(/no result/i)).toBeInTheDocument()
})
test('switch page', async () => {
@ -127,12 +125,10 @@ test('switch page', async () => {
.mockResolvedValueOnce({ ...createPaginator([]), last_page: 2 })
.mockResolvedValueOnce({ ...createPaginator([fixtureSkin]), last_page: 2 })
const { getByText, queryByText } = render(<Closet />)
await wait()
const { getByText, findByText } = render(<Closet />)
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText('2'))
await wait()
expect(queryByText(fixtureSkin.pivot.item_name)).toBeInTheDocument()
expect(await findByText(fixtureSkin.pivot.item_name)).toBeInTheDocument()
})
describe('rename item', () => {
@ -146,18 +142,20 @@ describe('rename item', () => {
const { getByText, getByDisplayValue, getByRole, queryByText } = render(
<Closet />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.renameItem')))
fireEvent.input(getByDisplayValue(fixtureSkin.pivot.item_name), {
target: { value: 'my skin' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(
`/user/closet/rename/${fixtureSkin.tid}`,
{ name: 'my skin' },
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/closet/rename/${fixtureSkin.tid}`,
{
name: 'my skin',
},
),
)
expect(queryByText('my skin')).toBeInTheDocument()
expect(queryByText('success')).toBeInTheDocument()
@ -168,16 +166,14 @@ describe('rename item', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'success' })
const { getByText, getByDisplayValue, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.renameItem')))
fireEvent.input(getByDisplayValue(fixtureSkin.pivot.item_name), {
target: { value: '' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(t('skinlib.emptyNewTextureName'))).toBeInTheDocument()
fireEvent.click(getByText(t('general.cancel')))
@ -189,18 +185,20 @@ describe('rename item', () => {
const { getByText, getByDisplayValue, getByRole, queryByText } = render(
<Closet />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.renameItem')))
fireEvent.input(getByDisplayValue(fixtureSkin.pivot.item_name), {
target: { value: 'my skin' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(
`/user/closet/rename/${fixtureSkin.tid}`,
{ name: 'my skin' },
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/closet/rename/${fixtureSkin.tid}`,
{
name: 'my skin',
},
),
)
expect(queryByText(fixtureSkin.pivot.item_name)).toBeInTheDocument()
expect(queryByText('failed')).toBeInTheDocument()
@ -209,16 +207,14 @@ describe('rename item', () => {
it('cancelled', async () => {
const { getByText, getByDisplayValue, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.renameItem')))
fireEvent.input(getByDisplayValue(fixtureSkin.pivot.item_name), {
target: { value: 'my skin' },
})
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(fixtureSkin.pivot.item_name)).toBeInTheDocument()
})
})
@ -232,13 +228,15 @@ describe('remove item', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'success' })
const { getByText, getByRole, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.removeItem')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(`/user/closet/remove/${fixtureSkin.tid}`)
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/closet/remove/${fixtureSkin.tid}`,
),
)
expect(queryByText(/skin library/i)).toBeInTheDocument()
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
@ -248,13 +246,15 @@ describe('remove item', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByText, getByRole, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.removeItem')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(`/user/closet/remove/${fixtureSkin.tid}`)
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/closet/remove/${fixtureSkin.tid}`,
),
)
expect(queryByText(fixtureSkin.pivot.item_name)).toBeInTheDocument()
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
@ -262,13 +262,11 @@ describe('remove item', () => {
it('cancelled', async () => {
const { getByText, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.removeItem')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(fixtureSkin.pivot.item_name)).toBeInTheDocument()
})
})
@ -282,7 +280,7 @@ describe('select textures', () => {
it('select skin', async () => {
const { getByAltText, queryAllByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByAltText(fixtureSkin.pivot.item_name))
expect(queryAllByText(t('general.skin'))).toHaveLength(2)
@ -290,10 +288,10 @@ describe('select textures', () => {
it('select cape', async () => {
const { getByText, getByAltText, queryAllByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText(t('general.cape')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByAltText(fixtureCape.pivot.item_name))
expect(queryAllByText(t('general.cape'))).toHaveLength(2)
@ -301,11 +299,11 @@ describe('select textures', () => {
it('reset selected', async () => {
const { getByText, getByAltText, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByAltText(fixtureSkin.pivot.item_name))
fireEvent.click(getByText(t('general.cape')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByAltText(fixtureCape.pivot.item_name))
expect(
@ -336,15 +334,15 @@ describe('set avatar', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'success' })
const { getByText, getByRole, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.setAsAvatar')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/user/profile/avatar', {
tid: fixtureSkin.tid,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/profile/avatar', {
tid: fixtureSkin.tid,
}),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(document.querySelector('[alt="User Image"]')).toHaveAttribute('src')
@ -354,28 +352,26 @@ describe('set avatar', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByText, getByRole, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.setAsAvatar')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/user/profile/avatar', {
tid: fixtureSkin.tid,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/profile/avatar', {
tid: fixtureSkin.tid,
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
})
it('cancelled', async () => {
const { getByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.setAsAvatar')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
})
})
@ -384,7 +380,7 @@ describe('apply textures to player', () => {
fetch.get.mockResolvedValue(createPaginator([]))
const { getByText, getByRole, queryByText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.useAs')))
@ -402,14 +398,14 @@ describe('apply textures to player', () => {
getByAltText,
getAllByPlaceholderText,
queryByText,
findByText,
} = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByAltText(fixtureSkin.pivot.item_name))
fireEvent.click(getByText(t('user.useAs')))
await wait()
expect(queryByText(fixturePlayer.name)).toBeInTheDocument()
expect(await findByText(fixturePlayer.name)).toBeInTheDocument()
fireEvent.input(getAllByPlaceholderText(t('user.typeToSearch'))[1], {
target: { value: 'reina' },
@ -430,17 +426,20 @@ describe('apply textures to player', () => {
getByRole,
queryByText,
} = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByAltText(fixtureSkin.pivot.item_name))
fireEvent.click(getByText(t('user.useAs')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByTitle(fixturePlayer.name))
await wait()
expect(fetch.post).toBeCalledWith(`/user/player/set/${fixturePlayer.pid}`, {
skin: fixtureSkin.tid,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/player/set/${fixturePlayer.pid}`,
{
skin: fixtureSkin.tid,
},
),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
})
@ -458,17 +457,20 @@ describe('apply textures to player', () => {
getByRole,
queryByText,
} = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByAltText(fixtureSkin.pivot.item_name))
fireEvent.click(getByText(t('user.useAs')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByTitle(fixturePlayer.name))
await wait()
expect(fetch.post).toBeCalledWith(`/user/player/set/${fixturePlayer.pid}`, {
skin: fixtureSkin.tid,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/player/set/${fixturePlayer.pid}`,
{
skin: fixtureSkin.tid,
},
),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
})
@ -479,15 +481,13 @@ describe('apply textures to player', () => {
.mockResolvedValueOnce({ data: [fixturePlayer] })
const { getByText, getByAltText } = render(<Closet />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByAltText(fixtureSkin.pivot.item_name))
fireEvent.click(getByText(t('user.useAs')))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
$('#modal-apply')
.modal('hide')
.trigger('hidden.bs.modal')
$('#modal-apply').modal('hide').trigger('hidden.bs.modal')
expect(fetch.post).not.toBeCalled()
})

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import * as fetch from '@/scripts/net'
import { trans } from '@/scripts/i18n'
import Dashboard from '@/views/user/Dashboard'
@ -29,7 +29,7 @@ describe('info box', () => {
)
const { getByText } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(getByText('13')).toBeInTheDocument()
expect(getByText(/21/)).toBeInTheDocument()
})
@ -41,7 +41,7 @@ describe('info box', () => {
)
const { getByText } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(getByText('700')).toBeInTheDocument()
expect(getByText(/800/)).toBeInTheDocument()
expect(getByText(/KB/)).toBeInTheDocument()
@ -53,7 +53,7 @@ describe('info box', () => {
)
const { getByText } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(getByText('7')).toBeInTheDocument()
expect(getByText(/10/)).toBeInTheDocument()
expect(getByText(/MB/)).toBeInTheDocument()
@ -74,13 +74,11 @@ describe('sign', () => {
})
const { getByRole, getByText, queryByText } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
const button = getByRole('button')
fireEvent.click(button)
await wait()
expect(fetch.post).toBeCalledWith('/user/sign')
await waitFor(() => expect(fetch.post).toBeCalledWith('/user/sign'))
expect(getByText('ok')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(button).toBeDisabled()
@ -91,12 +89,10 @@ describe('sign', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'f', data: {} })
const { getByRole, getByText } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByRole('button'))
await wait()
expect(fetch.post).toBeCalledWith('/user/sign')
await waitFor(() => expect(fetch.post).toBeCalledWith('/user/sign'))
expect(getByText('f')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-warning')
})
@ -112,7 +108,7 @@ describe('sign button', () => {
it('sign is allowed', async () => {
fetch.get.mockResolvedValue(scoreInfo())
const { getByRole } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
const button = getByRole('button')
expect(button).toBeEnabled()
@ -122,7 +118,7 @@ describe('sign button', () => {
it('sign is allowed if last sign is yesterday', async () => {
fetch.get.mockResolvedValue(scoreInfo({ signAfterZero: true }))
const { getByRole } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(getByRole('button')).toBeEnabled()
})
@ -131,7 +127,7 @@ describe('sign button', () => {
scoreInfo({ signAfterZero: true }, { lastSignAt: Date.now() }),
)
const { getByRole } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(getByRole('button')).toBeDisabled()
})
@ -139,7 +135,7 @@ describe('sign button', () => {
fetch.get.mockResolvedValue(scoreInfo({}, { lastSignAt: Date.now() }))
const { getByRole } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
const button = getByRole('button')
expect(button).toBeDisabled()
@ -152,7 +148,7 @@ describe('sign button', () => {
)
const { getByRole } = render(<Dashboard />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
const button = getByRole('button')
expect(button).toBeDisabled()

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import * as fetch from '@/scripts/net'
import { t } from '@/scripts/i18n'
import OAuth from '@/views/user/OAuth'
@ -28,7 +28,7 @@ describe('create app', () => {
it('succeeded', async () => {
fetch.post.mockResolvedValue(fixture)
const { getByLabelText, getByText, queryByText } = render(<OAuth />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.oauth.create')))
fireEvent.input(getByLabelText(t('user.oauth.name')), {
@ -38,12 +38,12 @@ describe('create app', () => {
target: { value: 'http://url.test/' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/oauth/clients', {
name: 'My App',
redirect: 'http://url.test/',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/oauth/clients', {
name: 'My App',
redirect: 'http://url.test/',
}),
)
expect(queryByText(fixture.id.toString())).toBeInTheDocument()
expect(queryByText(fixture.name)).toBeInTheDocument()
expect(queryByText(fixture.redirect)).toBeInTheDocument()
@ -55,7 +55,7 @@ describe('create app', () => {
const { getByLabelText, getByText, getByRole, queryByText } = render(
<OAuth />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.oauth.create')))
fireEvent.input(getByLabelText(t('user.oauth.name')), {
@ -65,12 +65,12 @@ describe('create app', () => {
target: { value: 'http://url.test/' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/oauth/clients', {
name: 'My App',
redirect: 'http://url.test/',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/oauth/clients', {
name: 'My App',
redirect: 'http://url.test/',
}),
)
expect(queryByText(fixture.name)).not.toBeInTheDocument()
expect(queryByText(fixture.redirect)).not.toBeInTheDocument()
expect(queryByText('exception')).toBeInTheDocument()
@ -79,7 +79,7 @@ describe('create app', () => {
it('cancel dialog', async () => {
const { getByLabelText, getByText } = render(<OAuth />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.oauth.create')))
fireEvent.input(getByLabelText(t('user.oauth.name')), {
@ -90,8 +90,7 @@ describe('create app', () => {
})
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
fireEvent.click(getByText(t('user.oauth.create')))
expect(getByLabelText(t('user.oauth.name'))).toHaveValue('')
@ -111,19 +110,19 @@ describe('edit app', () => {
const { getByTitle, getByText, getByDisplayValue, queryByText } = render(
<OAuth />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.oauth.modifyName')))
fireEvent.input(getByDisplayValue(fixture.name), {
target: { value: 'new name' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.put).toBeCalledWith(`/oauth/clients/${fixture.id}`, {
...fixture,
name: 'new name',
})
await waitFor(() =>
expect(fetch.put).toBeCalledWith(`/oauth/clients/${fixture.id}`, {
...fixture,
name: 'new name',
}),
)
expect(queryByText('new name')).toBeInTheDocument()
})
@ -137,19 +136,19 @@ describe('edit app', () => {
getByRole,
queryByText,
} = render(<OAuth />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.oauth.modifyName')))
fireEvent.input(getByDisplayValue(fixture.name), {
target: { value: 'new name' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.put).toBeCalledWith(`/oauth/clients/${fixture.id}`, {
...fixture,
name: 'new name',
})
await waitFor(() =>
expect(fetch.put).toBeCalledWith(`/oauth/clients/${fixture.id}`, {
...fixture,
name: 'new name',
}),
)
expect(queryByText(fixture.name)).toBeInTheDocument()
expect(queryByText('exception')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
@ -157,13 +156,11 @@ describe('edit app', () => {
it('cancel dialog', async () => {
const { getByTitle, getByText, queryByText } = render(<OAuth />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.oauth.modifyName')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.put).not.toBeCalled()
await waitFor(() => expect(fetch.put).not.toBeCalled())
expect(queryByText(fixture.name)).toBeInTheDocument()
})
})
@ -175,19 +172,19 @@ describe('edit app', () => {
const { getByTitle, getByDisplayValue, getByText, queryByText } = render(
<OAuth />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.oauth.modifyUrl')))
fireEvent.input(getByDisplayValue(fixture.redirect), {
target: { value: 'http://new.test/' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.put).toBeCalledWith(`/oauth/clients/${fixture.id}`, {
...fixture,
redirect: 'http://new.test/',
})
await waitFor(() =>
expect(fetch.put).toBeCalledWith(`/oauth/clients/${fixture.id}`, {
...fixture,
redirect: 'http://new.test/',
}),
)
expect(queryByText('http://new.test/')).toBeInTheDocument()
})
@ -201,19 +198,19 @@ describe('edit app', () => {
getByRole,
queryByText,
} = render(<OAuth />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.oauth.modifyUrl')))
fireEvent.input(getByDisplayValue(fixture.redirect), {
target: { value: 'http://new.test/' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.put).toBeCalledWith(`/oauth/clients/${fixture.id}`, {
...fixture,
redirect: 'http://new.test/',
})
await waitFor(() =>
expect(fetch.put).toBeCalledWith(`/oauth/clients/${fixture.id}`, {
...fixture,
redirect: 'http://new.test/',
}),
)
expect(queryByText(fixture.redirect)).toBeInTheDocument()
expect(queryByText('exception')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
@ -221,13 +218,11 @@ describe('edit app', () => {
it('cancel dialog', async () => {
const { getByTitle, getByText, queryByText } = render(<OAuth />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.oauth.modifyUrl')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.put).not.toBeCalled()
await waitFor(() => expect(fetch.put).not.toBeCalled())
expect(queryByText(fixture.redirect)).toBeInTheDocument()
})
})
@ -240,26 +235,24 @@ describe('delete app', () => {
it('succeeded', async () => {
const { getByText, queryByText } = render(<OAuth />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('report.delete')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.del).toBeCalledWith(`/oauth/clients/${fixture.id}`)
await waitFor(() =>
expect(fetch.del).toBeCalledWith(`/oauth/clients/${fixture.id}`),
)
expect(queryByText(fixture.name)).not.toBeInTheDocument()
expect(queryByText(fixture.redirect)).not.toBeInTheDocument()
})
it('cancel dialog', async () => {
const { getByText, queryByText } = render(<OAuth />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('report.delete')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.del).not.toBeCalled())
expect(queryByText(fixture.name)).toBeInTheDocument()
expect(queryByText(fixture.redirect)).toBeInTheDocument()
})

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import { Player } from '@/scripts/types'
@ -42,7 +42,7 @@ test('search players', async () => {
fetch.get.mockResolvedValue({ data: [fixture, fixture2] })
const { getByPlaceholderText, queryByText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.input(getByPlaceholderText(t('user.typeToSearch')), {
target: { value: 'k' },
@ -56,7 +56,7 @@ describe('select player automatically', () => {
it('only one player', async () => {
fetch.get.mockResolvedValue({ data: [fixture] })
render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(fetch.get).toBeCalledWith(`/skinlib/info/${fixture.tid_skin}`)
expect(fetch.get).toBeCalledWith(`/skinlib/info/${fixture.tid_cape}`)
@ -66,7 +66,7 @@ describe('select player automatically', () => {
const fixture2: Player = { pid: 2, name: 'reina', tid_skin: 3, tid_cape: 4 }
fetch.get.mockResolvedValue({ data: [fixture, fixture2] })
render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
expect(fetch.get).not.toBeCalledWith(`/skinlib/info/${fixture.tid_skin}`)
expect(fetch.get).not.toBeCalledWith(`/skinlib/info/${fixture.tid_cape}`)
@ -81,7 +81,7 @@ describe('2d preview', () => {
.mockResolvedValueOnce({ data: { hash: 'b', type: 'cape' } })
const { getByAltText, getByText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.switch2dPreview')))
@ -103,7 +103,7 @@ describe('2d preview', () => {
const { getByAltText, queryByAltText, getByText, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.switch2dPreview')))
@ -123,7 +123,7 @@ describe('2d preview', () => {
const { getByAltText, queryByAltText, getByText, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.switch2dPreview')))
@ -143,7 +143,7 @@ describe('create player', () => {
it('alert if score is enough', async () => {
const { getByRole, getByText, queryByText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.add-player')))
@ -156,7 +156,7 @@ describe('create player', () => {
it('alert if lack of score', async () => {
blessing.extra.score = 0
const { getByRole, getByText, queryByText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.add-player')))
@ -172,18 +172,18 @@ describe('create player', () => {
const { getByText, getByLabelText, getByRole, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.add-player')))
fireEvent.input(getByLabelText(t('general.player.player-name')), {
target: { value: fixture.name },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/user/player/add', {
name: fixture.name,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/player/add', {
name: fixture.name,
}),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(queryByText(fixture.pid.toString())).toBeInTheDocument()
@ -196,18 +196,18 @@ describe('create player', () => {
const { getByText, getByLabelText, getByRole, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.add-player')))
fireEvent.input(getByLabelText(t('general.player.player-name')), {
target: { value: fixture.name },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith('/user/player/add', {
name: fixture.name,
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/player/add', {
name: fixture.name,
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
expect(queryByText(fixture.name)).not.toBeInTheDocument()
@ -215,22 +215,20 @@ describe('create player', () => {
it('cancelled', async () => {
const { getByText, getByLabelText, queryByText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.add-player')))
fireEvent.input(getByLabelText(t('general.player.player-name')), {
target: { value: fixture.name },
})
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(fixture.name)).not.toBeInTheDocument()
})
it('clear form on close', async () => {
const { getByText, getByLabelText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.add-player')))
fireEvent.input(getByLabelText(t('general.player.player-name')), {
@ -258,18 +256,18 @@ describe('edit player name', () => {
getByRole,
queryByText,
} = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.player.edit-pname')))
fireEvent.input(getByDisplayValue(fixture.name), {
target: { value: 'reina' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(`/user/player/rename/${fixture.pid}`, {
name: 'reina',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith(`/user/player/rename/${fixture.pid}`, {
name: 'reina',
}),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(queryByText('reina')).toBeInTheDocument()
@ -279,16 +277,14 @@ describe('edit player name', () => {
const { getByText, getByTitle, getByDisplayValue, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.player.edit-pname')))
fireEvent.input(getByDisplayValue(fixture.name), {
target: { value: '' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(t('user.emptyPlayerName'))).toBeInTheDocument()
fireEvent.click(getByText(t('general.cancel')))
@ -304,18 +300,18 @@ describe('edit player name', () => {
getByRole,
queryByText,
} = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.player.edit-pname')))
fireEvent.input(getByDisplayValue(fixture.name), {
target: { value: 'reina' },
})
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(`/user/player/rename/${fixture.pid}`, {
name: 'reina',
})
await waitFor(() =>
expect(fetch.post).toBeCalledWith(`/user/player/rename/${fixture.pid}`, {
name: 'reina',
}),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
expect(queryByText(fixture.name)).toBeInTheDocument()
@ -325,16 +321,14 @@ describe('edit player name', () => {
const { getByText, getByTitle, getByDisplayValue, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByTitle(t('user.player.edit-pname')))
fireEvent.input(getByDisplayValue(fixture.name), {
target: { value: 'reina' },
})
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(fixture.name)).toBeInTheDocument()
})
})
@ -350,19 +344,19 @@ describe('reset texture', () => {
const { getByText, getByRole, getByLabelText, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.delete-texture')))
fireEvent.click(getByLabelText(t('general.skin')))
fireEvent.click(getByLabelText(t('general.cape')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(
`/user/player/texture/clear/${fixture.pid}`,
{
type: ['skin', 'cape'],
},
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/player/texture/clear/${fixture.pid}`,
{
type: ['skin', 'cape'],
},
),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
@ -374,18 +368,18 @@ describe('reset texture', () => {
const { getByText, getByRole, getByLabelText, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.delete-texture')))
fireEvent.click(getByLabelText(t('general.skin')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(
`/user/player/texture/clear/${fixture.pid}`,
{
type: ['skin'],
},
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/player/texture/clear/${fixture.pid}`,
{
type: ['skin'],
},
),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
@ -397,18 +391,18 @@ describe('reset texture', () => {
const { getByText, getByRole, getByLabelText, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.delete-texture')))
fireEvent.click(getByLabelText(t('general.cape')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(
`/user/player/texture/clear/${fixture.pid}`,
{
type: ['cape'],
},
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/player/texture/clear/${fixture.pid}`,
{
type: ['cape'],
},
),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
@ -416,13 +410,11 @@ describe('reset texture', () => {
it('select nothing', async () => {
const { getByText, getByRole, queryByText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.delete-texture')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(t('user.noClearChoice'))).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-warning')
})
@ -433,18 +425,18 @@ describe('reset texture', () => {
const { getByText, getByRole, getByLabelText, queryByText } = render(
<Players />,
)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.delete-texture')))
fireEvent.click(getByLabelText(t('general.skin')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(
`/user/player/texture/clear/${fixture.pid}`,
{
type: ['skin'],
},
await waitFor(() =>
expect(fetch.post).toBeCalledWith(
`/user/player/texture/clear/${fixture.pid}`,
{
type: ['skin'],
},
),
)
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
@ -452,14 +444,12 @@ describe('reset texture', () => {
it('cancelled', async () => {
const { getByText, getByLabelText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.delete-texture')))
fireEvent.click(getByLabelText(t('general.skin')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
})
})
@ -472,13 +462,13 @@ describe('delete player', () => {
fetch.post.mockResolvedValue({ code: 0, message: 'success' })
const { getByText, getByRole, queryByText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.delete-player')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(`/user/player/delete/${fixture.pid}`)
await waitFor(() =>
expect(fetch.post).toBeCalledWith(`/user/player/delete/${fixture.pid}`),
)
expect(getByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
expect(queryByText(fixture.name)).not.toBeInTheDocument()
@ -488,13 +478,13 @@ describe('delete player', () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByText, getByRole, queryByText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.delete-player')))
fireEvent.click(getByText(t('general.confirm')))
await wait()
expect(fetch.post).toBeCalledWith(`/user/player/delete/${fixture.pid}`)
await waitFor(() =>
expect(fetch.post).toBeCalledWith(`/user/player/delete/${fixture.pid}`),
)
expect(getByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
expect(queryByText(fixture.name)).toBeInTheDocument()
@ -502,13 +492,11 @@ describe('delete player', () => {
it('cancelled', async () => {
const { getByText, queryByText } = render(<Players />)
await wait()
await waitFor(() => expect(fetch.get).toBeCalledTimes(1))
fireEvent.click(getByText(t('user.player.delete-player')))
fireEvent.click(getByText(t('general.cancel')))
await wait()
expect(fetch.post).not.toBeCalled()
await waitFor(() => expect(fetch.post).not.toBeCalled())
expect(queryByText(fixture.name)).toBeInTheDocument()
})
})

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import EmailVerification from '@/views/widgets/EmailVerification'
@ -13,9 +13,9 @@ describe('send email', () => {
const { getByText, getByRole, queryByText } = render(<EmailVerification />)
fireEvent.click(getByText(t('user.verification.resend')))
await wait()
expect(fetch.post).toBeCalledWith('/user/email-verification')
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/email-verification'),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
})
@ -26,8 +26,9 @@ describe('send email', () => {
const { getByText, getByRole, queryByText } = render(<EmailVerification />)
fireEvent.click(getByText(t('user.verification.resend')))
await wait()
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/email-verification'),
)
expect(fetch.post).toBeCalledWith('/user/email-verification')
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, fireEvent, wait } from '@testing-library/react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import NotificationsList, {
@ -54,7 +54,7 @@ test('read notification', async () => {
const { getByText, queryByText } = render(<NotificationsList />)
fireEvent.click(getByText('hi'))
await wait()
await waitFor(() => expect(fetch.get).toBeCalled())
expect(queryByText(fixture.title)).toBeInTheDocument()
expect(queryByText(fixture.content)).toBeInTheDocument()

2057
yarn.lock

File diff suppressed because it is too large Load Diff