import { test, expect } from 'vitest'; import { render, screen } from '@testing-library/react'; import NotificationTag from './NotificationTag'; const NOTIFICATION_TAG_LABEL = '11'; const NOTIFICATION_TAG_DESCRIPTION = 'new messages'; const NOTIFICATION_TAG_ICON = 'SVG icon'; test('notification tag renders correctly', () => { render( {NOTIFICATION_TAG_ICON} ); const notificationTag = screen.getByTestId('notification-tag'); const notificationTagWrapper = notificationTag.parentElement; const notificationTagDescription = notificationTag.lastChild; expect(notificationTag).toHaveClass('ds_notification-tag'); expect(notificationTag.nodeName).toEqual('SPAN'); expect(notificationTag).not.toHaveAttribute('aria-hidden'); expect(notificationTagWrapper).toHaveClass('ds_notification-tag__wrapper'); expect(notificationTagWrapper?.nodeName).toEqual('SPAN'); expect(notificationTagDescription).toHaveClass('visually-hidden'); expect(notificationTagDescription?.nodeName).toEqual('SPAN'); }); test('notification tag with dot', () => { render( {NOTIFICATION_TAG_ICON} ); const notificationTag = screen.getByTestId('notification-tag'); expect(notificationTag).toHaveClass('ds_notification-tag--dot'); }); test('aria-hidden on notification tag', () => { render( {NOTIFICATION_TAG_ICON} ); const notificationTag = screen.getByTestId('notification-tag'); expect(notificationTag.getAttribute('aria-hidden')).toEqual('true'); }); test('passing additional props', () => { render( {NOTIFICATION_TAG_ICON} ); const notificationTag = screen.getByTestId('notification-tag'); expect(notificationTag?.dataset.test).toEqual('foo'); }); test('passing additional CSS class', () => { render( {NOTIFICATION_TAG_ICON} ); const notificationTag = screen.getByTestId('notification-tag'); expect(notificationTag).toHaveClass('foo', 'ds_notification-tag'); });