From f914ff8376dd91c4f6f8ca149e1cb6becb622d88 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Mon, 2 Oct 2023 18:45:30 +0200
Subject: refactor(components): rewrite Link component

* rename `external` prop to `isExternal`
* rename `download` prop to `isDownload`
* rewrite CSS to reduce code length and complexity
* move link styles in Sass placeholders to avoid repeats because of WordPress
articles
* move NavLink component to molecules
---
 src/components/atoms/links/link/link.test.tsx | 47 +++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 src/components/atoms/links/link/link.test.tsx

(limited to 'src/components/atoms/links/link/link.test.tsx')

diff --git a/src/components/atoms/links/link/link.test.tsx b/src/components/atoms/links/link/link.test.tsx
new file mode 100644
index 0000000..ad1951d
--- /dev/null
+++ b/src/components/atoms/links/link/link.test.tsx
@@ -0,0 +1,47 @@
+import { describe, expect, it } from '@jest/globals';
+import { render, screen as rtlScreen } from '@testing-library/react';
+import { Link } from './link';
+
+describe('Link', () => {
+  it('renders a link', () => {
+    const anchor = 'porro';
+    const target = '/tempora';
+
+    render(<Link href={target}>{anchor}</Link>);
+
+    expect(rtlScreen.getByRole('link', { name: anchor })).toHaveAttribute(
+      'href',
+      target
+    );
+  });
+
+  it('can render an external link', () => {
+    const anchor = 'accusamus';
+    const target = 'https://www.example.com';
+
+    render(
+      <Link href={target} isExternal>
+        {anchor}
+      </Link>
+    );
+
+    expect(rtlScreen.getByRole('link', { name: anchor })).toHaveClass(
+      'link--external'
+    );
+  });
+
+  it('can render a download link', () => {
+    const anchor = 'dolor';
+    const target = '/officiis.pdf';
+
+    render(
+      <Link href={target} isDownload>
+        {anchor}
+      </Link>
+    );
+
+    expect(rtlScreen.getByRole('link', { name: anchor })).toHaveClass(
+      'link--download'
+    );
+  });
+});
-- 
cgit v1.2.3

