mirror of
https://git.shipoclu.com/moon/plspace.git
synced 2026-08-13 02:42:30 +00:00
paste images attachment
This commit is contained in:
@@ -102,4 +102,81 @@ describe('Composer', () => {
|
||||
await waitFor(() => expect(postStatus).toHaveBeenCalledOnce())
|
||||
expect(postStatus.mock.calls[0][1].status).toBe('Keyboard-posted entry')
|
||||
})
|
||||
|
||||
it('uploads a pasted clipboard image and attaches it to the post', async () => {
|
||||
const pastedImage = new File(['image bytes'], 'pasted-image.png', { type: 'image/png' })
|
||||
const uploadMedia = vi.fn().mockResolvedValue({
|
||||
id: 'pasted-media',
|
||||
type: 'image',
|
||||
url: 'https://media.example/pasted-image.png',
|
||||
preview_url: 'https://media.example/pasted-image-preview.png',
|
||||
description: null,
|
||||
})
|
||||
const postStatus = vi.fn().mockResolvedValue(status())
|
||||
const services = testServices({
|
||||
session: session({
|
||||
token: 'token',
|
||||
me: account(),
|
||||
signedIn: true,
|
||||
instance: {
|
||||
title: 'Test server',
|
||||
version: '1.0.0',
|
||||
configuration: { statuses: { max_media_attachments: 4 } },
|
||||
},
|
||||
}),
|
||||
endpoints: { uploadMedia, postStatus },
|
||||
})
|
||||
const view = render(Composer, {
|
||||
props: { initialText: 'A pasted picture' },
|
||||
context: new Map([[APP_SERVICES, services]]),
|
||||
})
|
||||
const textarea = view.getByRole('textbox', { name: 'Entry text' })
|
||||
|
||||
await fireEvent.paste(textarea, {
|
||||
clipboardData: {
|
||||
items: [
|
||||
{
|
||||
kind: 'file',
|
||||
type: 'image/png',
|
||||
getAsFile: () => pastedImage,
|
||||
},
|
||||
],
|
||||
files: [pastedImage],
|
||||
},
|
||||
})
|
||||
|
||||
await waitFor(() => expect(uploadMedia).toHaveBeenCalledOnce())
|
||||
expect(uploadMedia.mock.calls[0][1]).toBe(pastedImage)
|
||||
expect(view.container.querySelector('.composer-attachment img')).toHaveAttribute(
|
||||
'src',
|
||||
'https://media.example/pasted-image-preview.png',
|
||||
)
|
||||
|
||||
await fireEvent.click(view.getByRole('button', { name: 'Post Entry' }))
|
||||
|
||||
await waitFor(() => expect(postStatus).toHaveBeenCalledOnce())
|
||||
expect(postStatus.mock.calls[0][1].media_ids).toEqual(['pasted-media'])
|
||||
})
|
||||
|
||||
it('leaves ordinary text-only paste alone', async () => {
|
||||
const uploadMedia = vi.fn()
|
||||
const services = testServices({
|
||||
session: session({ token: 'token', me: account(), signedIn: true }),
|
||||
endpoints: { uploadMedia },
|
||||
})
|
||||
const view = render(Composer, {
|
||||
context: new Map([[APP_SERVICES, services]]),
|
||||
})
|
||||
const textarea = view.getByRole('textbox', { name: 'Entry text' })
|
||||
|
||||
const wasNotCancelled = await fireEvent.paste(textarea, {
|
||||
clipboardData: {
|
||||
items: [{ kind: 'string', type: 'text/plain', getAsFile: () => null }],
|
||||
files: [],
|
||||
},
|
||||
})
|
||||
|
||||
expect(wasNotCancelled).toBe(true)
|
||||
expect(uploadMedia).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user