import { beforeEach, describe, expect, it, vi } from 'vitest' import { fixture, html } from '@open-wc/testing-helpers' import './UsPolicy' import type { LitElement } from 'lit' import type { IPolicyProp } from './model/IPolicyProp' import { ETextVariant } from './model/ETextVariant' type ITestUsPolicy = LitElement & IPolicyProp const policySettings: IPolicyProp = { textVariant: ETextVariant.DEFAULT, textAlign: 'center', buttonName: 'testButtonName', url: 'testUrl', policy: 'testPolicy', terms: 'testTerms', openInPopup: true, } describe('UsPolicy', () => { let el: ITestUsPolicy const getElShadowRoot = (): HTMLElement => { return el.shadowRoot?.querySelector('div.us-policy') as HTMLElement } let mockHandleChange: Function beforeEach(async () => { el = await fixture(html`Text`) mockHandleChange = vi.fn() }) it('should has default structure', async () => { expect(el).toBeDefined() expect(getElShadowRoot().tagName).toBe('DIV') expect(getElShadowRoot().children[0].tagName).toBe('DIV') }) it('should has default props and classes', () => { expect(el.indeterminate).toBeFalsy() expect(el.policySettings).toBeTypeOf('object') expect(el.dataTestId).toBe('policy') expect(getElShadowRoot().className).toContain('us-policy') }) it('should dispatch event on change', async () => { el.addEventListener('click', () => mockHandleChange()) el.click() expect(mockHandleChange).toHaveBeenCalled() }) it('should be created component us-policy', () => { const testSwitch = document.querySelector('us-policy') expect(testSwitch).not.toBeNull() }) it('should display two a tags with Privacy Policy and Terms of Use text', () => { expect(getElShadowRoot().children[1].children[0].tagName).toBe('A') expect(getElShadowRoot().children[1].children[0].innerText.trim()).toContain('Privacy Policy') expect(getElShadowRoot().children[1].children[1].tagName).toBe('A') expect(getElShadowRoot().children[1].children[1].innerText.trim()).toContain('Terms of Use') }) })