overleaf-cep/services/web/test/frontend/shared/components/notification.test.tsx
Alf Eaton 2fbb4615f9 Convert utility functions to TypeScript (#22658)
* Convert event-tracking to TypeScript

* Convert local-storage to TypeScript

* Convert mapSeries to TypeScript

* Convert SessionStorage to TypeScript

* Convert account-upgrade to TypeScript

* Convert isValidTeXFile to TypeScript

* Convert date functions to TypeScript

* Convert EventEmitter to TypeScript

* Convert isNetworkError to TypeScript

* Convert webpack-public-path to TypeScript

* Convert displayNameForUser to TypeScript

GitOrigin-RevId: 79c5a2d1101fcd520f3116f0f4af29d974189d94
2025-01-16 09:05:36 +00:00

62 lines
1.7 KiB
TypeScript

import { expect } from 'chai'
import { screen, render } from '@testing-library/react'
import Notification from '../../../../frontend/js/shared/components/notification'
import * as eventTracking from '@/infrastructure/event-tracking'
import sinon from 'sinon'
describe('<Notification />', function () {
let sendMBSpy: sinon.SinonSpy
beforeEach(function () {
sendMBSpy = sinon.spy(eventTracking, 'sendMB')
})
afterEach(function () {
sendMBSpy.restore()
})
it('renders and is not dismissible by default', function () {
render(<Notification type="info" content={<p>A notification</p>} />)
screen.getByText('A notification')
expect(screen.queryByRole('button', { name: 'Close' })).to.be.null
})
it('renders with action', function () {
render(
<Notification
type="info"
content={<p>A notification</p>}
action={<a href="/">Action</a>}
/>
)
screen.getByText('A notification')
screen.getByRole('link', { name: 'Action' })
})
it('renders with close button', function () {
render(
<Notification type="info" content={<p>A notification</p>} isDismissible />
)
screen.getByText('A notification')
screen.getByRole('button', { name: 'Close' })
})
it('renders with title and content passed as HTML', function () {
render(
<Notification
type="info"
content={<p>A notification</p>}
title="A title"
/>
)
screen.getByText('A title')
screen.getByText('A notification')
})
it('renders with content when passed as a string', function () {
render(
<Notification type="info" content="A notification" title="A title" />
)
screen.getByText('A notification')
})
})