2026-07-05 01:15:55 +04:00
|
|
|
import {describe, it, expect, vi, afterEach} from 'vitest'
|
|
|
|
|
import {render, screen} from '@testing-library/react'
|
|
|
|
|
import userEvent from '@testing-library/user-event'
|
|
|
|
|
import ReponsMastodon from '../repons-mastodon'
|
|
|
|
|
|
|
|
|
|
describe('ReponsMastodon', () => {
|
|
|
|
|
const originalOpen = window.open
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
window.open = originalOpen
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('ne rend rien sans bokanteStatusId', () => {
|
|
|
|
|
const {container} = render(<ReponsMastodon bokanteStatusId={null} />)
|
|
|
|
|
expect(container).toBeEmptyDOMElement()
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-07 16:11:46 +04:00
|
|
|
it('affiche un lien direct vers le fil BOKANTE', () => {
|
2026-07-05 01:15:55 +04:00
|
|
|
render(<ReponsMastodon bokanteStatusId='112233' />)
|
2026-07-07 16:11:46 +04:00
|
|
|
const lien = screen.getByRole('link', {name: 'BOKANTE (Mastodon)'})
|
2026-07-05 01:15:55 +04:00
|
|
|
expect(lien).toHaveAttribute('href', 'https://bokante.o-k-i.net/@pawol_nu/112233')
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-07 16:11:46 +04:00
|
|
|
it('redirige vers BOKANTE par défaut quand on continue', async () => {
|
2026-07-05 01:15:55 +04:00
|
|
|
window.open = vi.fn()
|
|
|
|
|
const user = userEvent.setup()
|
|
|
|
|
render(<ReponsMastodon bokanteStatusId='112233' />)
|
|
|
|
|
|
2026-07-07 16:11:46 +04:00
|
|
|
await user.click(screen.getByRole('button', {name: /répondre sur mastodon/i}))
|
2026-07-05 01:15:55 +04:00
|
|
|
await user.click(screen.getByRole('button', {name: /continuer/i}))
|
|
|
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalledWith(
|
2026-07-07 16:11:46 +04:00
|
|
|
'https://bokante.o-k-i.net/authorize_interaction?uri=' + encodeURIComponent('https://bokante.o-k-i.net/@pawol_nu/112233'),
|
2026-07-05 01:15:55 +04:00
|
|
|
'_blank',
|
|
|
|
|
'noopener,noreferrer'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-07 16:11:46 +04:00
|
|
|
it('permet de choisir une autre instance dans le select', async () => {
|
2026-07-05 01:15:55 +04:00
|
|
|
window.open = vi.fn()
|
|
|
|
|
const user = userEvent.setup()
|
|
|
|
|
render(<ReponsMastodon bokanteStatusId='112233' />)
|
|
|
|
|
|
2026-07-07 16:11:46 +04:00
|
|
|
await user.click(screen.getByRole('button', {name: /répondre sur mastodon/i}))
|
|
|
|
|
await user.click(screen.getByLabelText(/instance mastodon/i))
|
|
|
|
|
await user.click(screen.getByRole('option', {name: /autre instance/i}))
|
2026-07-05 01:15:55 +04:00
|
|
|
await user.type(screen.getByLabelText(/@vous@votre-instance/i), 'mastodon.social')
|
|
|
|
|
await user.click(screen.getByRole('button', {name: /continuer/i}))
|
|
|
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalledWith(
|
2026-07-07 16:11:46 +04:00
|
|
|
'https://mastodon.social/authorize_interaction?uri=' + encodeURIComponent('https://bokante.o-k-i.net/@pawol_nu/112233'),
|
|
|
|
|
'_blank',
|
|
|
|
|
'noopener,noreferrer'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('accepte un identifiant complet pour une autre instance', async () => {
|
|
|
|
|
window.open = vi.fn()
|
|
|
|
|
const user = userEvent.setup()
|
|
|
|
|
render(<ReponsMastodon bokanteStatusId='112233' />)
|
|
|
|
|
|
|
|
|
|
await user.click(screen.getByRole('button', {name: /répondre sur mastodon/i}))
|
|
|
|
|
await user.click(screen.getByLabelText(/instance mastodon/i))
|
|
|
|
|
await user.click(screen.getByRole('option', {name: /autre instance/i}))
|
|
|
|
|
await user.type(screen.getByLabelText(/@vous@votre-instance/i), '@quelqun@mastodon.social')
|
|
|
|
|
await user.click(screen.getByRole('button', {name: /continuer/i}))
|
|
|
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalledWith(
|
|
|
|
|
'https://mastodon.social/authorize_interaction?uri=' + encodeURIComponent('https://bokante.o-k-i.net/@pawol_nu/112233'),
|
2026-07-05 01:15:55 +04:00
|
|
|
'_blank',
|
|
|
|
|
'noopener,noreferrer'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|