Skip to content

Commit

Permalink
fixup! feat: add PDF component library
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed Sep 8, 2024
1 parent f63a4c6 commit 770fcfc
Show file tree
Hide file tree
Showing 30 changed files with 410 additions and 57 deletions.
1 change: 1 addition & 0 deletions packages/component-library-pdf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Bekijk elke test in `*.test.tsx`. Bekijk het PDF document dat correspondeert met

- [Tagged PDF Best Practice Guide: Syntax For developers implementing ISO 14289-1 (PDF/UA) — PDF download](https://pdfa.org/wp-content/uploads/2019/06/TaggedPDFBestPracticeGuideSyntax.pdf)
- [Deterministic output: a way to specify the PDF File Identifier (/ID) property](https://www.princexml.com/forum/topic/4931/deterministic-output-a-way-to-specify-the-pdf-file?p=1#24826)
- [Convert PDF to HTML](https://pdfix.io/convert-pdf-to-html/). Gebruik de optie "Layout defined by PDF Tags" om te zien welke tags er in een PDF zitten, via de developer tools. Bijvoorbeeld: `data-pdf-se-type-original="Link"`.

## PDF/UA-1 in vergelijking met design system components

Expand Down
1 change: 1 addition & 0 deletions packages/component-library-pdf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"clean": "rimraf dist/",
"build": "tsx src/index.tsx",
"install-prince": "( cd node_modules/prince && npm run install )",
"lint-build": "tsc --noEmit --project tsconfig.json",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
"test:watch": "jest --watch"
},
Expand Down
21 changes: 21 additions & 0 deletions packages/component-library-pdf/src/Article.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-env jest */

import { describe, expect, it } from '@jest/globals';
import { Article, Paragraph } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Article', () => {
it('renders a <Art> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-article',
render: () => (
<Article>
<Paragraph>The quick brown fox jumps over the lazy dog</Paragraph>
</Article>
),
});

expect(sha256).toBe('3a94e1e570c85d3c0d1c35589b65a6f1a690e8c581bed5a217d4713abc2d1dac');
});
});
21 changes: 21 additions & 0 deletions packages/component-library-pdf/src/Blockquote.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-env jest */

import { describe, expect, it } from '@jest/globals';
import { Blockquote, Paragraph } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Blockquote', () => {
it('renders a <BlockQuote> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-blockquote',
render: () => (
<Blockquote>
<Paragraph>The quick brown fox jumps over the lazy dog.</Paragraph>
</Blockquote>
),
});

expect(sha256).toBe('1565b0f7dd9ae4121654f76836cba952321e1d3110c7a910f2563d18a664eda8');
});
});
17 changes: 17 additions & 0 deletions packages/component-library-pdf/src/Checkbox.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-env jest */

import { describe, expect, it } from '@jest/globals';
import { Checkbox } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Checkbox', () => {
it('renders a <Form> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-checkbox',
render: () => <Checkbox />,
});

expect(sha256).toBe('16860207ce8377c3b11bd31d676efba22d10f8eedacdf9098b702c2743fc512b');
});
});
21 changes: 21 additions & 0 deletions packages/component-library-pdf/src/Code.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-env jest */

import { describe, expect, it } from '@jest/globals';
import { Code, Paragraph } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Code', () => {
it('renders a <Code> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-code',
render: () => (
<Paragraph>
Use <Code>{'/* Hello world */'}</Code> to create a code comment.
</Paragraph>
),
});

expect(sha256).toBe('f8104c20620bcf4c4e9a63f83c88d32841fef9f6ec481fb3de238d97997d134a');
});
});
28 changes: 28 additions & 0 deletions packages/component-library-pdf/src/CodeBlock.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-env jest */

import { describe, expect, it } from '@jest/globals';
import { CodeBlock } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Code block', () => {
it('renders a <Code> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-code-block',
render: () => (
<CodeBlock>{`<!DOCTYPE html>
<html lang="nl" dir="ltr">
<head>
<title>NL Design System</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>NL Design System</h1>
</body>
</html>`}</CodeBlock>
),
});

expect(sha256).toBe('46986780cbaeba8d2b585dc2d244f68a273121c8e831f1dba10912c968cfc0a8');
});
});
42 changes: 42 additions & 0 deletions packages/component-library-pdf/src/DataList.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-env jest */

import { beforeAll, describe, expect, it } from '@jest/globals';
import { DataList, DataListItem, DataListKey, DataListValue } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Data list', () => {
let sha256: string;

beforeAll(async () => {
({ sha256 } = await renderPdf({
id: 'pdf-data-list',
render: () => (
<DataList>
<DataListItem>
<DataListKey>Pangram</DataListKey>
<DataListValue>The quick brown fox jumps over the lazy dog</DataListValue>
</DataListItem>
</DataList>
),
}));
});

it('renders a <L> tag', async () => {
expect(sha256).toBe('1ef37478b0c027f45c557c94ca9c4d237860baf121f02d482e45b85c43348134');
});

describe('list item', () => {
it('renders a <LI> tag', async () => {
expect(sha256).toBe('1ef37478b0c027f45c557c94ca9c4d237860baf121f02d482e45b85c43348134');
});

it('renders a <Lbl> tag with the key', async () => {
expect(sha256).toBe('1ef37478b0c027f45c557c94ca9c4d237860baf121f02d482e45b85c43348134');
});

it('renders a <LBody> tag with the value', async () => {
expect(sha256).toBe('1ef37478b0c027f45c557c94ca9c4d237860baf121f02d482e45b85c43348134');
});
});
});
22 changes: 22 additions & 0 deletions packages/component-library-pdf/src/FormFieldTextbox.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-env jest */

import { describe, expect, it } from '@jest/globals';
import { FormFieldTextbox } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Form field with textbox', () => {
it('renders a <Form> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-form-field-textbox',
render: () => (
<FormFieldTextbox
label="Postcode"
description="Nederlandse postcode met 4 cijfers en 2 letters, bijvoorbeeld: 1234 AB."
></FormFieldTextbox>
),
});

expect(sha256).toBe('d79ea42074650594beb4266345e09cabeb9a437ed13d66ac6f40527b715ec62b');
});
});
17 changes: 17 additions & 0 deletions packages/component-library-pdf/src/FormLabel.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-env jest */

import { describe, expect, it } from '@jest/globals';
import { FormLabel } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Form label', () => {
it.skip('renders a <Lbl> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-form-label',
render: () => <FormLabel>Name</FormLabel>,
});

expect(sha256).toBe('');
});
});
4 changes: 2 additions & 2 deletions packages/component-library-pdf/src/Heading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import React from 'react';
import { renderPdf } from './lib';

describe('Heading with variable heading level', () => {
it('renders a <H7> tag', async () => {
it.skip('renders a <H7> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-heading',
render: () => (
Expand All @@ -32,6 +32,6 @@ describe('Heading with variable heading level', () => {
),
});

expect(sha256).toBe('90df84a649e31187a33eebdbbe0136ed8ffcf3ac872f4d29d77c4a3053f1f5fb');
expect(sha256).toBe('');
});
});
2 changes: 1 addition & 1 deletion packages/component-library-pdf/src/Heading1.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ describe('Heading 1', () => {
render: () => <Heading1>Heading 1: The quick brown fox jumps over the lazy dog</Heading1>,
});

expect(sha256).toBe('8fe3ac6c1c0d81bffa47c0ba01ca001dbc303126f2d9340d948ce15883456922');
expect(sha256).toBe('f7922ee3cbbe73b7aff8b2532aedacb6a254f2b673591b360b6656154a18b6ba');
});
});
2 changes: 1 addition & 1 deletion packages/component-library-pdf/src/Heading2.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ describe('Heading 2', () => {
),
});

expect(sha256).toBe('47e2b852ce5c3ac5a44d87e5becae04e5d7b55aaf6c0240163640115a6d08683');
expect(sha256).toBe('8facfd10a62f642565c95c1c69575d3cbc81f841c9a69fc230ec5d2e85410c4d');
});
});
2 changes: 1 addition & 1 deletion packages/component-library-pdf/src/Heading3.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ describe('Heading 3', () => {
),
});

expect(sha256).toBe('c9ec84295cdd4b5a7d1c444e1524ebda9d93d7f1e55d503bc5d0cf68c06c9053');
expect(sha256).toBe('dce041d710cc1e2b14f842806fd198b9ace85b34b92ed439ff2b54c9843e18a9');
});
});
2 changes: 1 addition & 1 deletion packages/component-library-pdf/src/Heading4.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ describe('Heading 4', () => {
),
});

expect(sha256).toBe('8e28b82b0d3926a2b5c9c66491360de191469141013cf9ee31556663095690e3');
expect(sha256).toBe('16f18aaec4180ddb54c99066f125298f980dfd00fc3ef9d0113d094fd27498eb');
});
});
2 changes: 1 addition & 1 deletion packages/component-library-pdf/src/Heading5.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ describe('Heading 5', () => {
),
});

expect(sha256).toBe('19dc5443153516d489baac2e16823b291d80a65f0e2b4b683dac2f7d0734c389');
expect(sha256).toBe('0cc780670d80a4579ac73d6d61a026f9fec1d1a6e2fc0876068e6c26cce84df2');
});
});
2 changes: 1 addition & 1 deletion packages/component-library-pdf/src/Heading6.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ describe('Heading 6', () => {
),
});

expect(sha256).toBe('bfb75d4176247439d0aa9101c664552d20af3e0ae6126046367ad5c8390543d1');
expect(sha256).toBe('518e7313d993ccc7e6b9f922aac4cc87ea31afaafe8a5740df0bdfab7196bff0');
});
});
29 changes: 29 additions & 0 deletions packages/component-library-pdf/src/LangSpan.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-env jest */

import { beforeAll, describe, expect, it } from '@jest/globals';
import { Paragraph } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Language span', () => {
let sha256: string;

beforeAll(async () => {
({ sha256 } = await renderPdf({
id: 'pdf-span-lang',
render: () => (
<Paragraph>
Learn about <span lang="fr">joi de vivre</span>, an essential foreign phrase!
</Paragraph>
),
}));
});

it('renders a <Span> tag', async () => {
expect(sha256).toBe('99db074fa02bc374efb1b74f388c93627100b0048e04dd986e003ab0ae88ea92');
});

it('renders a <Span> tag with the language set to French', async () => {
expect(sha256).toBe('99db074fa02bc374efb1b74f388c93627100b0048e04dd986e003ab0ae88ea92');
});
});
21 changes: 21 additions & 0 deletions packages/component-library-pdf/src/Link.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-env jest */

import { describe, expect, it } from '@jest/globals';
import { Link, Paragraph } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Link', () => {
it('renders a <Link> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-link',
render: () => (
<Paragraph>
Go to <Link href="https://example.com/">example.com</Link>.
</Paragraph>
),
});

expect(sha256).toBe('cfb53b1c5cdc2d5efc4b2cc2c933bfb8ef8d9fee0ec9ce7c2897f080189c9369');
});
});
31 changes: 17 additions & 14 deletions packages/component-library-pdf/src/OrderedList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
/* eslint-env jest */

import { describe, expect, it } from '@jest/globals';
import { beforeAll, describe, expect, it } from '@jest/globals';
import { OrderedList, OrderedListItem } from '@utrecht/component-library-react';
import React from 'react';
import { renderPdf } from './lib';

describe('Ordered list', () => {
it('renders a <L> tag', async () => {
const { sha256 } = await renderPdf({
let sha256: string;

beforeAll(async () => {
({ sha256 } = await renderPdf({
id: 'pdf-ordered-list',
render: () => (
<OrderedList>
<OrderedListItem>The quick brown fox jumps over the lazy dog</OrderedListItem>
</OrderedList>
),
});
}));
});

expect(sha256).toBe('07fc6915a511ebf3fe9116a57bf6b5fc1bb3c597402a54a9c4a6f328453a6312');
it('renders a <L> tag', async () => {
expect(sha256).toBe('051ffdb077ac93f772bd55f208bcf86a9c18d8c80da2e17ebba37665d7e1bdf6');
});

describe('list item', () => {
it('renders a <LI> tag', async () => {
const { sha256 } = await renderPdf({
id: 'pdf-ordered-list-item',
render: () => (
<OrderedList>
<OrderedListItem>The quick brown fox jumps over the lazy dog</OrderedListItem>
</OrderedList>
),
});
expect(sha256).toBe('051ffdb077ac93f772bd55f208bcf86a9c18d8c80da2e17ebba37665d7e1bdf6');
});

it('renders a <Lbl> tag with list item counter', async () => {
expect(sha256).toBe('051ffdb077ac93f772bd55f208bcf86a9c18d8c80da2e17ebba37665d7e1bdf6');
});

expect(sha256).toBe('61b4a7f5c904a9fc98cecf5da39fa9dde37ada56d9a1a3fbda46c1a275fdd8e2');
it('renders a <LBody> tag with the text content', async () => {
expect(sha256).toBe('051ffdb077ac93f772bd55f208bcf86a9c18d8c80da2e17ebba37665d7e1bdf6');
});
});
});
Loading

0 comments on commit 770fcfc

Please sign in to comment.