when parent is
', async () => {
+ const wrapper = await fixture(html``);
const el = wrapper.querySelector('nve-link-card') as NveLinkCard;
- const linkCard = el.shadowRoot?.querySelector('[part="link-card"]');
- expect(linkCard?.tagName.toLowerCase()).toBe('div');
- }); */
+ const div = el.shadowRoot?.querySelector('div[part="link-card"]');
+ expect(div).not.toBeNull();
+ });
+
+ it('should render nve-icon for clickAction', async () => {
+ const el = await fixture
(html``);
+ const icon = el.shadowRoot?.querySelector('nve-icon[slot="suffix"]');
+ expect(icon).not.toBeNull();
+ expect(icon?.getAttribute('name')).toBe('arrow_forward');
+ expect(icon?.getAttribute('aria-hidden')).toBe('true');
+ });
+
+ it('should set testid attribute', async () => {
+ const el = await fixture(html``);
+ const a = el.shadowRoot?.querySelector('[part="link-card"]');
+ expect(a?.getAttribute('testid')).toBe('123');
+ });
+
+ describe('clickAction', () => {
+ it('should render with clickAction="internal"', async () => {
+ const el = await fixture(
+ html``
+ );
+ const a = el.shadowRoot?.querySelector('a.link-card');
+ expect(a).not.toBeNull();
+ expect(a?.getAttribute('href')).toBe('/intern');
+ expect(a?.hasAttribute('download')).toBe(false);
+ expect(a?.getAttribute('target')).toBeNull();
+ const icon = el.shadowRoot?.querySelector('nve-icon[slot="suffix"]');
+ expect(icon?.getAttribute('name')).toBe('arrow_forward');
+ });
+
+ it('should render with clickAction="download"', async () => {
+ const el = await fixture(
+ html``
+ );
+ const a = el.shadowRoot?.querySelector('a.link-card');
+ expect(a).not.toBeNull();
+ expect(a?.getAttribute('href')).toBe('/fil.pdf');
+ expect(a?.hasAttribute('download')).toBe(true);
+ expect(a?.getAttribute('target')).toBeNull();
+ const icon = el.shadowRoot?.querySelector('nve-icon[slot="suffix"]');
+ expect(icon?.getAttribute('name')).toBe('download');
+ });
+
+ it('should render with clickAction="external"', async () => {
+ const el = await fixture(
+ html``
+ );
+ const a = el.shadowRoot?.querySelector('a.link-card');
+ expect(a).not.toBeNull();
+ expect(a?.getAttribute('href')).toBe('https://nve.no');
+ expect(a?.hasAttribute('download')).toBe(false);
+ expect(a?.getAttribute('target')).toBe('_blank');
+ const icon = el.shadowRoot?.querySelector('nve-icon[slot="suffix"]');
+ expect(icon?.getAttribute('name')).toBe('open_in_new');
+ });
+
+ it('should render with clickAction="mail"', async () => {
+ const el = await fixture(
+ html``
+ );
+ const a = el.shadowRoot?.querySelector('a.link-card');
+ expect(a).not.toBeNull();
+ expect(a?.getAttribute('href')).toBe('mailto:test@nve.no');
+ expect(a?.hasAttribute('download')).toBe(false);
+ expect(a?.getAttribute('target')).toBeNull();
+ const icon = el.shadowRoot?.querySelector('nve-icon[slot="suffix"]');
+ expect(icon?.getAttribute('name')).toBe('mail');
+ });
+ });
});