mirror of
https://git.shipoclu.com/moon/plspace.git
synced 2026-08-13 02:42:30 +00:00
44 lines
1.8 KiB
TypeScript
44 lines
1.8 KiB
TypeScript
import { render, waitFor } from '@testing-library/svelte'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import { APP_SERVICES } from '$lib/app-services'
|
|
import { account, session, status, testServices } from '$test/fixtures'
|
|
import Compose from './Compose.svelte'
|
|
|
|
describe('Compose route', () => {
|
|
it('resets addressing and defaults to direct when the recipient changes', async () => {
|
|
const services = testServices({
|
|
session: session({ token: 'token', me: account(), signedIn: true }),
|
|
})
|
|
const view = render(Compose, {
|
|
props: { to: 'alice@example.test' },
|
|
context: new Map([[APP_SERVICES, services]]),
|
|
})
|
|
|
|
expect(view.getByRole('textbox', { name: 'Entry text' })).toHaveValue('@alice@example.test ')
|
|
expect(view.getByRole('combobox', { name: 'Who can see this' })).toHaveValue('direct')
|
|
|
|
await view.rerender({ to: 'bob@example.test' })
|
|
|
|
expect(view.getByRole('textbox', { name: 'Entry text' })).toHaveValue('@bob@example.test ')
|
|
expect(view.getByRole('combobox', { name: 'Who can see this' })).toHaveValue('direct')
|
|
})
|
|
|
|
it('loads and previews a quote target without a backend', async () => {
|
|
const fetchStatus = vi.fn().mockResolvedValue(
|
|
status({ id: 'quoted-entry', content: '<p>Loaded quote target</p>' }),
|
|
)
|
|
const services = testServices({
|
|
session: session({ token: 'token', me: account(), signedIn: true }),
|
|
endpoints: { fetchStatus },
|
|
})
|
|
const view = render(Compose, {
|
|
props: { quoteId: 'quoted-entry' },
|
|
context: new Map([[APP_SERVICES, services]]),
|
|
})
|
|
|
|
await waitFor(() => expect(fetchStatus).toHaveBeenCalledOnce())
|
|
expect(await view.findByText('Loaded quote target')).toBeInTheDocument()
|
|
expect(view.getByRole('button', { name: 'Post Quote' })).toBeEnabled()
|
|
})
|
|
})
|