import { beforeEach, describe, expect, it, vi } from 'vitest' import { elementUpdated, fixture, html } from '@open-wc/testing-helpers' import './UsSnackbar' import type { UsSnackbar } from './UsSnackbar' describe('UsSnackbar', () => { let usSnackbar: UsSnackbar const snackbarContainer = () => { const wrapper = usSnackbar.shadowRoot?.querySelector('.snackbar__container') return wrapper } const snackbarTitleDescriptionBlock = () => { const wrapper = usSnackbar.shadowRoot?.querySelector('.snackbar__wrapper-for-title-description') return wrapper } beforeEach(async () => { usSnackbar = await fixture(html``) }) it('should be defined', async () => { expect(usSnackbar).toBeDefined() expect(usSnackbar.tagName).toBe('US-SNACKBAR') }) it('should has correct initial properties', () => { expect(usSnackbar.items).toEqual([]) expect(usSnackbar.dataTestId).toBe('snackbar') }) it('should has one child snackbar-container into snackbar__wrapper-for-title-description if don`t recieve captionText', async () => { usSnackbar.items = [{ variant: 'success', mainText: 'Some title text' }] await elementUpdated(usSnackbar) expect(snackbarTitleDescriptionBlock()?.children.length).toBe(1) }) it('snackbar-container should has class "show"', async () => { usSnackbar.items = [{ variant: 'success', mainText: 'Some title text' }] await elementUpdated(usSnackbar) expect(snackbarContainer()?.className).toContain('show') }) it('snackbar-container should\'n be has class "show" with default property "delay" equal 3000ms for automatically close it', async () => { const delay = 3000 usSnackbar.items = [{ variant: 'success', mainText: 'Some title text' }] const testFunc = vi.fn(async () => { usSnackbar.items[0].show = false }) setTimeout(async () => { testFunc() await elementUpdated(usSnackbar) expect(snackbarContainer()?.children[0].className).not.toContain('show') }, delay) }) })