fix installing plugin

This commit is contained in:
Pig Fang 2020-06-09 10:23:26 +08:00
parent 44a86e70c5
commit 1a914b0db6
3 changed files with 27 additions and 5 deletions

View File

@ -142,8 +142,8 @@ const PluginsMarket: React.FC = () => {
key={plugin.name}
plugin={plugin}
isInstalling={installings.has(plugin.name)}
onInstall={() => handleInstall(plugin, i)}
onUpdate={() => handleUpdate(plugin, i)}
onInstall={() => handleInstall(plugin, (page - 1) * 10 + i)}
onUpdate={() => handleUpdate(plugin, (page - 1) * 10 + i)}
/>
))}
</tbody>

View File

@ -35,8 +35,6 @@ Object.assign(window, { Headers, Request })
const noop = () => undefined
Object.assign(console, {
log: noop,
info: noop,
warn: noop,
error: noop,
})

View File

@ -34,6 +34,30 @@ test('search plugins', async () => {
expect(queryByText('yggdrasil-api')).not.toBeInTheDocument()
})
test('install a plugin after first page', async () => {
const plugins = Array.from({ length: 10 }).map(() => {
return { ...fixture, name: `${fixture.name}_${Math.random()}` }
})
plugins.push(fixture)
fetch.get.mockResolvedValue(plugins)
fetch.post.mockResolvedValue({ code: 0, message: 'ok' })
const { getByText, queryByText, queryAllByText } = render(<PluginsMarket />)
await waitFor(() => expect(fetch.get).toBeCalled())
fireEvent.click(getByText('2'))
fireEvent.click(getByText(t('admin.installPlugin')))
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/admin/plugins/market/download', {
name: fixture.name,
}),
)
expect(queryByText(t('admin.installPlugin'))).toBeDisabled()
fireEvent.click(getByText('1'))
expect(queryAllByText(t('admin.installPlugin'))[0]).toBeEnabled()
})
describe('dependencies', () => {
it('no dependencies', async () => {
fetch.get.mockResolvedValue([
@ -78,7 +102,7 @@ describe('dependencies', () => {
})
})
describe('install plugin', async () => {
describe('install plugin', () => {
beforeEach(() => {
fetch.get.mockResolvedValue([fixture])
})