Skip to content

Commit ea2e600

Browse files
committed
Create mocks for the entire point-of-sale extension API
1 parent c3884f2 commit ea2e600

27 files changed

Lines changed: 4117 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ jobs:
6262
run: npm install && npm run typecheck && npm test
6363
working-directory: examples/testing/checkout-basic-testing-example
6464

65+
- name: Testing example (point-of-sale)
66+
run: npm install && npm run typecheck && npm test
67+
working-directory: examples/testing/point-of-sale-testing-example
68+
6569
test-build:
6670
runs-on: ubuntu-latest
6771

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Environment Configuration
2+
.env
3+
.env.*
4+
5+
# Dependency directory
6+
node_modules
7+
8+
# Test coverage directory
9+
coverage
10+
11+
# Ignore Apple macOS Desktop Services Store
12+
.DS_Store
13+
14+
# Logs
15+
logs
16+
*.log
17+
18+
# extensions build output
19+
extensions/*/build
20+
extensions/*/dist
21+
22+
# lock files
23+
24+
25+
26+
# Ignore shopify files created during app dev
27+
.shopify/*
28+
.shopify.lock
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require("node:fs");
2+
3+
function getConfig() {
4+
const config = {
5+
projects: {},
6+
};
7+
8+
let extensions = [];
9+
try {
10+
extensions = fs.readdirSync("./extensions");
11+
} catch {
12+
// ignore if no extensions
13+
}
14+
15+
for (const entry of extensions) {
16+
const extensionPath = `./extensions/${entry}`;
17+
const schema = `${extensionPath}/schema.graphql`;
18+
if (!fs.existsSync(schema)) {
19+
continue;
20+
}
21+
config.projects[entry] = {
22+
schema,
23+
documents: [`${extensionPath}/**/*.graphql`],
24+
};
25+
}
26+
27+
return config;
28+
}
29+
30+
module.exports = getConfig();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This extension was created with:
2+
3+
```
4+
shopify app init --name point-of-sale-testing-example
5+
cd point-of-sale-testing-example
6+
shopify app generate extension
7+
# I chose 'POS block'
8+
```
9+
10+
See it in action:
11+
12+
Build the root package:
13+
14+
```
15+
yarn build
16+
```
17+
18+
Change into this example package and run:
19+
20+
```
21+
npm install
22+
npm run typecheck
23+
npm test
24+
```

examples/testing/point-of-sale-testing-example/extensions/.gitkeep

Whitespace-only changes.

examples/testing/point-of-sale-testing-example/extensions/point-of-sale-testing-example/package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "point-of-sale-testing-example-ext",
3+
"private": true,
4+
"version": "1.0.0",
5+
"license": "UNLICENSED",
6+
"dependencies": {
7+
"@shopify/ui-extensions": "file:../../../../packages/ui-extensions",
8+
"preact": "^10.10.x"
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import '@shopify/ui-extensions';
2+
3+
//@ts-ignore
4+
declare module './src/Tile.jsx' {
5+
const shopify: import('@shopify/ui-extensions/pos.home.tile.render').Api;
6+
const globalThis: { shopify: typeof shopify };
7+
}
8+
9+
//@ts-ignore
10+
declare module './src/Modal.jsx' {
11+
const shopify: import('@shopify/ui-extensions/pos.home.modal.render').Api;
12+
const globalThis: { shopify: typeof shopify };
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Learn more about configuring your POS UI extension:
2+
# https://shopify.dev/docs/api/pos-ui-extensions
3+
4+
# The version of APIs your extension will receive. Learn more:
5+
# https://shopify.dev/docs/api/usage/versioning
6+
api_version = "2026-04"
7+
8+
[[extensions]]
9+
uid = "80f617f3-cfaf-bcfc-f4bd-8bf4faabbc38dc0e7226"
10+
type = "ui_extension"
11+
name = "point-of-sale-testing-example"
12+
handle = "point-of-sale-testing-example"
13+
description = "A preact POS UI extension"
14+
15+
[[extensions.targeting]]
16+
module = "./src/Tile.jsx"
17+
target = "pos.home.tile.render"
18+
19+
[[extensions.targeting]]
20+
module = "./src/Modal.jsx"
21+
target = "pos.home.modal.render"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {render} from 'preact';
2+
3+
export default async () => {
4+
render(<Extension />, document.body);
5+
};
6+
7+
function Extension() {
8+
const cart = shopify.cart.current.value;
9+
const lineItems = cart ? cart.lineItems : [];
10+
11+
return (
12+
<s-page heading="Cart details">
13+
<s-stack direction="block">
14+
{lineItems.length === 0 ? (
15+
<s-text>No items in cart</s-text>
16+
) : (
17+
lineItems.map((item) => (
18+
<s-stack key={item.uuid} direction="inline">
19+
<s-text>{item.title}</s-text>
20+
<s-text>Qty: {item.quantity}</s-text>
21+
</s-stack>
22+
))
23+
)}
24+
</s-stack>
25+
</s-page>
26+
);
27+
}

0 commit comments

Comments
 (0)