import type { SpecPage } from '@stencil/core/testing'; import { newSpecPage } from '@stencil/core/testing'; import { ODS_LINK_COLOR, ODS_LINK_ICON_ALIGNMENT, OdsLink } from '../../src'; describe('ods-link rendering', () => { let page: SpecPage; let root: HTMLElement | undefined; let iconElement: HTMLElement | undefined; async function setup(html: string): Promise { page = await newSpecPage({ components: [OdsLink], html, }); root = page.root; iconElement = root?.shadowRoot?.querySelector('ods-icon') ?? undefined; } describe('color', () => { it('should be reflected', async() => { const colorValue = ODS_LINK_COLOR.primary; await setup(``); expect(root?.getAttribute('color')).toBe(colorValue); }); it('should render with expected default value', async() => { await setup(``); expect(root?.getAttribute('color')).toBe( ODS_LINK_COLOR.primary); }); }); describe('disabled', () => { it('should be reflected', async() => { await setup(``); expect(root?.getAttribute('is-disabled')).toBe(''); }); it('should render with expected default value', async() => { await setup(``); expect(root?.getAttribute('is-disabled')).toBe(null); }); }); describe('download', () => { it('should be reflected', async() => { const downloadValue = 'filename'; await setup(``); expect(root?.getAttribute('download')).toBe(downloadValue); }); it('should render with expected default value', async() => { await setup(``); expect(root?.getAttribute('download')).toBe(null); }); }); describe('href', () => { it('should be reflected', async() => { const hrefValue = 'https://www.ovhcloud.com/fr/'; await setup(``); expect(root?.getAttribute('href')).toBe(hrefValue); }); it('should render with expected default value', async() => { await setup(``); expect(root?.getAttribute('href')).toBe(null); }); }); describe('icon', () => { it('should be reflected', async() => { const iconValue = 'warning'; await setup(``); expect(root?.getAttribute('icon')).toBe(iconValue); expect(iconElement).toBeDefined(); expect(iconElement?.getAttribute('name')).toBe(iconValue); }); it('should render with expected default value', async() => { await setup(``); expect(root?.getAttribute('icon')).toBe(null); expect(iconElement).not.toBeDefined(); }); }); describe('iconAlignment', () => { it('should be reflected', async() => { const dummyValue = 'dummy value'; await setup(`Dummy Link`); expect(root?.getAttribute('icon-alignment')).toBe(dummyValue); }); it('should render with expected default value', async() => { await setup('Dummy Link'); expect(root?.getAttribute('icon-alignment')).toBe(ODS_LINK_ICON_ALIGNMENT.right); }); }); describe('label', () => { it('should be reflected', async() => { const labelValue = 'lorem ipsum'; await setup(``); expect(root?.getAttribute('label')).toBe(labelValue); }); it('should render with expected default value', async() => { await setup(``); expect(root?.getAttribute('label')).toBe(null); }); }); describe('referrerPolicy', () => { it('should be reflected', async() => { const referrerpolicyValue = 'origin'; await setup(``); expect(root?.getAttribute('referrerpolicy')).toBe(referrerpolicyValue); }); it('should render with expected default value', async() => { await setup(``); expect(root?.getAttribute('referrerpolicy')).toBe(null); }); }); describe('rel', () => { it('should be reflected', async() => { const relValue = 'stylesheet'; await setup(``); expect(root?.getAttribute('rel')).toBe(relValue); }); it('should render with expected default value', async() => { await setup(``); expect(root?.getAttribute('rel')).toBe(null); }); }); describe('target', () => { it('should be reflected', async() => { const targetValue = '_blank'; await setup(``); expect(root?.getAttribute('target')).toBe(targetValue); }); it('should render with expected default value', async() => { await setup(``); expect(root?.getAttribute('target')).toBe(null); }); }); });