Files
pawol.nu/components/teks/__tests__/komante.test.jsx

38 lines
1.5 KiB
React

import {describe, it, expect} from 'vitest'
import {render, screen} from '@testing-library/react'
import Komante from '../komante'
describe('Komante', () => {
it('ne rend rien quand il n\'y a aucun commentaire', () => {
const {container} = render(<Komante commentaires={[]} />)
expect(container).toBeEmptyDOMElement()
})
it('affiche un commentaire local avec le pseudo pawol.nu', () => {
render(<Komante commentaires={[
{id: 1, contenu: 'Bèl tèks', origine: 'local', user: {username: 'foo'}}
]} />)
expect(screen.getByText('foo')).toBeInTheDocument()
expect(screen.getByText('Bèl tèks')).toBeInTheDocument()
expect(screen.queryByText('Mastodon')).not.toBeInTheDocument()
})
it('affiche un commentaire fédéré avec le badge et le lien Mastodon', () => {
render(<Komante commentaires={[{
id: 2,
contenu: 'Trè bèl',
origine: 'activitypub',
auteurNom: 'Quelqu\'un',
auteurHandle: '@quelqun@mastodon.social',
auteurProfilUrl: 'https://mastodon.social/@quelqun',
remoteUrl: 'https://bokante.o-k-i.net/@quelqun/1'
}]} />)
expect(screen.getByText('Quelqu\'un')).toBeInTheDocument()
expect(screen.getByText('Mastodon')).toBeInTheDocument()
expect(screen.getByRole('link', {name: 'Quelqu\'un'})).toHaveAttribute('href', 'https://mastodon.social/@quelqun')
expect(screen.getByRole('link', {name: /voir sur mastodon/i})).toHaveAttribute('href', 'https://bokante.o-k-i.net/@quelqun/1')
})
})