A downstream fork of Tranquil PDS for use in margin.cafe margin.cafe
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import { beforeEach, describe, expect, it, vi } from 'vitest'import { fireEvent, render, screen, waitFor } from '@testing-library/svelte'import RepoContent from '../components/dashboard/RepoContent.svelte'import DidDocumentContent from '../components/dashboard/DidDocumentContent.svelte'import { clearMocks, setupAuthenticatedUser, setupDefaultMocks, mockData, mockEndpoint, jsonResponse } from './mocks'
describe('redesigned technical workspaces', () => { beforeEach(() => { clearMocks(); setupDefaultMocks(); setupAuthenticatedUser() })
it('opens records read-only and protects the editor from list navigation', async () => { const session = mockData.session() mockEndpoint('com.atproto.repo.describeRepo', () => jsonResponse({ collections: ['app.bsky.feed.post'] })) mockEndpoint('com.atproto.repo.listRecords', () => jsonResponse({ records: [{ uri: `at://${session.did}/app.bsky.feed.post/post1`, cid: 'cid1', value: { text: 'Hello' } }] })) const put = vi.fn(() => jsonResponse({})) mockEndpoint('com.atproto.repo.putRecord', put) render(RepoContent, { session }) await fireEvent.click(await screen.findByRole('button', { name: /app.bsky.feed.post/ })) const row = await screen.findByRole('button', { name: /post1.*Hello/ }) await fireEvent.click(row) expect(screen.queryByRole('textbox', { name: /record json/i })).not.toBeInTheDocument() await fireEvent.click(screen.getByRole('button', { name: /^edit$/i })) expect(row).toBeDisabled() expect(screen.getByRole('button', { name: /create record/i })).toBeDisabled() const editor = screen.getByRole('textbox', { name: /record json/i }) await fireEvent.input(editor, { target: { value: '[]' } }) await fireEvent.click(screen.getByRole('button', { name: /update record/i })) expect(await screen.findByText(/Enter a JSON object/)).toBeInTheDocument() expect(put).not.toHaveBeenCalled() await fireEvent.click(screen.getByRole('button', { name: /^cancel$/i })) expect(row).not.toBeDisabled() })
it('keeps DID saves disabled until the draft has a valid change', async () => { const session = mockData.session() mockEndpoint('_account.getDidDocument', () => jsonResponse({ id: session.did, verificationMethod: [], alsoKnownAs: [], service: [{ type: 'AtprotoPersonalDataServer', serviceEndpoint: 'https://old.example' }] })) render(DidDocumentContent, { session }) const endpoint = await screen.findByLabelText(/current pds/i) const save = screen.getByRole('button', { name: /save/i }) expect(save).toBeDisabled() await fireEvent.input(endpoint, { target: { value: 'javascript:alert(1)' } }) expect(save).toBeDisabled() expect(endpoint).toHaveAttribute('aria-invalid', 'true') await fireEvent.input(endpoint, { target: { value: 'https://new.example' } }) await waitFor(() => expect(save).not.toBeDisabled()) expect(screen.getByRole('region', { name: 'Document draft' })).toHaveTextContent('https://new.example') })
it('shows retry instead of an empty editable DID document after a failed load', async () => { mockEndpoint('_account.getDidDocument', () => jsonResponse({ error: 'Unavailable', message: 'Try later' }, 503)) render(DidDocumentContent, { session: mockData.session() }) expect(await screen.findByRole('alert')).toBeInTheDocument() expect(screen.getByRole('button', { name: /refresh/i })).toBeInTheDocument() expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument() })})