Skip to content

Commit

Permalink
Add Playwright tests for the built package to ensure that both import…
Browse files Browse the repository at this point in the history
… methods work
  • Loading branch information
alextompkins committed Nov 21, 2024
1 parent f5d2722 commit 581cf05
Show file tree
Hide file tree
Showing 8 changed files with 439 additions and 29 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ node_modules
.idea
dist
adyen-document-viewer.iml
package-lock.json
package-lock.json

# Playwright
test-results/
playwright-report/
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"prettier": "prettier --config ./prettier.config.js --ignore-unknown --check \"**/*\"",
"prettier:fix": "prettier --config ./prettier.config.js --ignore-unknown --write \"**/*\"",
"fix:all": "npm run prettier:fix && npm run lint:fix",
"test": "playwright test",
"test:debug": "playwright test --debug",
"test:ui": "playwright test --ui",
"types:build": "tsc --project tsconfig-build.json",
"types:check": "tsc && tsc-strict",
"types:watch": "tsc --watch --preserveWatchOutput"
Expand All @@ -30,6 +33,7 @@
"preact": "10.19.3"
},
"devDependencies": {
"@playwright/test": "^1.45.3",
"@preact/preset-vite": "^2.8.1",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
Expand Down
3 changes: 2 additions & 1 deletion index.html → playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</head>
<body>
<div id="document-viewer"></div>
<script defer type="module" src="/playground/example.js"></script>

<script type="module" src="./example.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions playground/loadViaEsModuleImport.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Adyen Document Viewer Example</title>

<link rel="stylesheet" href="/adyen-document-viewer.min.css" />
</head>
<body>
<div id="document-viewer"></div>

<script type="module">
import AdyenDocumentViewer from '/adyen-document-viewer.min.mjs?url';
import exampleDocument from './mock-data';

const documentViewer = new AdyenDocumentViewer('#document-viewer', {
onExpandSection: (sectionTitle) => console.log(`${sectionTitle} expanded`),
multiple: false,
});

documentViewer.render(exampleDocument);
</script>
</body>
</html>
312 changes: 312 additions & 0 deletions playground/loadViaUmdScript.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Adyen Document Viewer Example</title>

<link rel="stylesheet" href="/adyen-document-viewer.min.css" />
</head>
<body>
<div id="document-viewer"></div>

<script src="/adyen-document-viewer.min.js"></script>
<script>
const exampleDocument = {
title: {
type: 'text',
content: 'Example document',
styles: [],
},
contentElements: [
{
type: 'chapter',
title: {
type: 'text',
content: 'First chapter',
styles: [],
},
contentElements: [
{
type: 'section',
title: {
type: 'text',
content: 'First section',
styles: [],
},
label: '1',
contentElements: [
{
type: 'paragraph',
contentElements: [
{
type: 'text',
content:
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. ',
styles: [],
},
{
type: 'weblink',
url: 'https://www.lipsum.com',
displayText: {
type: 'text',
content: 'Lorem Ipsum',
styles: [],
},
},
{
type: 'text',
content:
' has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.',
styles: [],
},
{
type: 'text',
content: ' This is a bold and italic example. ',
styles: ['BOLD', 'ITALIC'],
},
{
type: 'internalReference',
referencedLabel: 'tableReference',
displayText: {
type: 'text',
content: 'This should take you to the table in the section below.',
styles: [],
},
},
{
type: 'paragraph',
contentElements: [
{
type: 'text',
content: 'Below we have a list:',
styles: [],
},
],
},
{
type: 'list',
style: {
ordered: true,
},
items: [
{
content: [
{
type: 'text',
content: 'first item in BI.',
styles: ['BOLD', 'ITALIC'],
},
],
subList: null,
},
{
content: [
{
type: 'text',
content: 'Second item:',
styles: [],
},
],
subList: {
type: 'list',
style: {
ordered: false,
},
items: [
{
content: [
{
type: 'text',
content: 'First Sub item:',
styles: [],
},
],
subList: null,
},
{
content: [
{
type: 'internalReference',
referencedLabel: '2',
displayText: {
type: 'text',
content: 'Second section',
styles: [],
},
},
],
subList: null,
},
{
content: [
{
type: 'text',
content: 'Third List item:',
styles: [],
},
],
subList: {
type: 'list',
style: {
ordered: true,
},
items: [
{
content: [
{
type: 'text',
content: 'First Sub Sub item:',
styles: '[Array(0)]',
},
],
subList: null,
},
],
},
},
],
},
},
],
},
],
},
],
},
{
type: 'section',
title: {
type: 'text',
content: 'Second section',
styles: [],
},
label: '2',
contentElements: [
{
type: 'paragraph',
contentElements: [
{
type: 'internalReference',
referencedLabel: 'tableReference',
displayText: {
type: 'text',
content: 'This should take you to the table below.',
styles: [],
},
},
{
type: 'text',
content:
' Lorem Ipsum is simply dummy text of the printing and typesetting industry. ',
styles: [],
},
{
type: 'weblink',
url: 'https://www.lipsum.com',
displayText: {
type: 'text',
content: 'Lorem Ipsum',
styles: [],
},
},
{
type: 'text',
content:
' has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.',
styles: [],
},
{
type: 'table',
rows: [
[
{
elements: [
{
type: 'text',
content: 'Row 1',
styles: ['BOLD'],
},
],
},
{
elements: [
{
type: 'text',
content: 'We have a website here',
styles: [],
},
{
type: 'breakline',
},
{
type: 'weblink',
url: 'https://www.exampleurlgoeshere.com',
displayText: null,
},
],
},
],
[
{
elements: [
{
type: 'text',
content: 'Row 2',
styles: ['BOLD'],
},
],
},
{
elements: [
{
type: 'text',
content: 'Just some text on the first line',
styles: [],
},
{
type: 'breakline',
},
{
type: 'text',
content: 'Just some text on the next line',
styles: [],
},
],
},
],
],
titlePrefix: {
type: 'text',
content: '1.',
styles: [],
},
title: {
type: 'text',
content: 'Lorem Ipsum',
styles: [],
},
style: {
columnSizes: ['SMALL', 'LARGE'],
alignment: 'LEFT',
},
label: 'tableReference',
},
],
},
],
},
],
},
],
};

const documentViewer = new AdyenDocumentViewer('#document-viewer', {
onExpandSection: (sectionTitle) => console.log(`${sectionTitle} expanded`),
multiple: false,
});

documentViewer.render(exampleDocument);
</script>
</body>
</html>
Loading

0 comments on commit 581cf05

Please sign in to comment.