Skip to content

Commit

Permalink
add simple HTML tests
Browse files Browse the repository at this point in the history
  • Loading branch information
levalleux-ludo committed Nov 17, 2023
1 parent d73dd7a commit d97ad01
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/www/test1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html PUBLIC>
<html>
<head>
<title>Widget Integration Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://localhost:3000/styles.css">
<link
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;800&display=swap"
rel="stylesheet"
/>
<script async type="text/javascript" src="http://localhost:3000/scripts/boson-widgets.js"></script>
<style>
div {
margin: 1rem;
}
</style>
</head>
<body>
<button type="button" id="boson-redeem-1" class="bosonButton" data-config-id="testing-80001-0">Redeem (Mumbai)</button>
<button type="button" id="boson-redeem-2" class="bosonButton" data-config-id="testing-5-0">Redeem (Goerli)</button>
</body>
</html>
65 changes: 65 additions & 0 deletions tests/www/test2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html PUBLIC>
<html>
<head>
<title>Widget Integration Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://localhost:3000/styles.css">
<link
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;800&display=swap"
rel="stylesheet"
/>
<script async type="text/javascript" src="http://localhost:3000/scripts/boson-widgets.js"></script>
<style>
div {
margin: 1rem;
}
</style>
</head>
<body>
<button type="button" id="boson-redeem-1" class="bosonButton" data-config-id="testing-80001-0" data-target-origin="http://127.0.0.1:5500" data-wait-for-response="true" data-send-delivery-info-XMTP="false">Redeem</button>
</body>
<script>
window.addEventListener("message", (event) => {
if (event.data.type === constants.deliveryInfoMessage) {
console.log(
`Received message '${event.data.type}' from '${event.origin}'. Content: '${JSON.stringify(event.data.message)}'`
);
// wait for a bit and send a response to the iFrame (only relevant when data-wait-for-response=="true")
setTimeout(() => {
const el = getIFrame();
if (el) {
const target = event.origin;
console.log(
`Post response message '${constants.deliveryInfoMessageResponse}' to the iFrame '${target}'`
);
// https://stackoverflow.com/questions/40991114/issue-communication-with-postmessage-from-parent-to-child-iframe
el.contentWindow.postMessage(
{
type: constants.deliveryInfoMessageResponse,
message: {
accepted: true,
reason: "",
resume: true
}
},
target
);
} else {
console.error("Unable to retrieve the iFrame");
}
}, 5000);
}
if (event.data.type === constants.redemptionSubmittedMessage) {
console.log(
`Received message '${event.data.type}' from '${event.origin}'. Content: '${JSON.stringify(event.data.message)}'`
);
}
if (event.data.type === constants.redemptionConfirmedMessage) {
console.log(
`Received message '${event.data.type}' from '${event.origin}'. Content: '${JSON.stringify(event.data.message)}'`
);
}
});
</script>
</html>
22 changes: 22 additions & 0 deletions tests/www/test3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html PUBLIC>
<html>
<head>
<title>Widget Integration Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://localhost:3000/styles.css">
<link
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;800&display=swap"
rel="stylesheet"
/>
<script async type="text/javascript" src="http://localhost:3000/scripts/boson-widgets.js"></script>
<style>
div {
margin: 1rem;
}
</style>
</head>
<body>
<button type="button" id="boson-redeem-1" class="bosonButton" data-config-id="testing-80001-0" data-send-delivery-info-XMTP="false" data-post-delivery-info-url="http://localhost:3666/deliveryInfo">Redeem</button>
</body>
</html>

0 comments on commit d97ad01

Please sign in to comment.