@thorprovider/create-thor-app 4.1.9 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -470
- package/dist/index.js +1 -2
- package/package.json +1 -1
- package/templates/default/.env.example +1 -1
- package/templates/default/.eslintrc.json +0 -4
- package/templates/default/README.md +2 -2
- package/templates/default/ai-validator.json +2 -2
- package/templates/default/app/cart/page.tsx +114 -0
- package/templates/default/app/checkout/page.tsx +395 -0
- package/templates/default/app/checkout/success/page.tsx +43 -0
- package/templates/default/app/layout.tsx +31 -7
- package/templates/default/app/products/[handle]/add-to-cart-button.tsx +85 -0
- package/templates/default/app/products/[handle]/page.tsx +108 -0
- package/templates/default/docs/README.md +0 -1
- package/templates/default/docs/project-structure.md +16 -6
- package/templates/default/docs/rules.md +1 -2
- package/templates/default/lib/commerce-client.ts +2 -3
- package/templates/default/lib/commerce.ts +1 -2
- package/templates/default/lib/env.ts +2 -2
- package/templates/default/lib/theme.ts +40 -0
- package/templates/default/package.json +7 -3
- package/templates/default/playwright.config.ts +86 -0
- package/templates/default/tests/e2e/auth.spec.ts +80 -0
- package/templates/default/tests/e2e/backend-unavailable.spec.ts +25 -0
- package/templates/default/tests/e2e/cart.spec.ts +79 -0
- package/templates/default/tests/e2e/checkout.spec.ts +95 -0
- package/templates/default/tests/e2e/global-setup.ts +42 -0
- package/templates/default/tests/e2e/product.spec.ts +53 -0
- package/templates/default/tests/e2e/smoke.spec.ts +48 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkout tests — 4-step wizard flow.
|
|
3
|
+
*
|
|
4
|
+
* Uses authenticated storage state (customer logged in via global-setup).
|
|
5
|
+
*
|
|
6
|
+
* NOTE: The dev backend has no fulfillment/shipping options configured on the
|
|
7
|
+
* Default Sales Channel. The checkout test validates:
|
|
8
|
+
* 1. Redirect to /cart when cart is empty
|
|
9
|
+
* 2. Address form renders and submits correctly
|
|
10
|
+
* 3. Shipping step shows "No shipping methods available" when backend has none
|
|
11
|
+
* (integration signal: we reached the backend and got a real response)
|
|
12
|
+
*
|
|
13
|
+
* When shipping is configured on the backend, the full checkout flow can be
|
|
14
|
+
* exercised by enabling the skipped tests below.
|
|
15
|
+
*/
|
|
16
|
+
import { test, expect } from '@playwright/test'
|
|
17
|
+
|
|
18
|
+
const PRODUCT_HANDLE =
|
|
19
|
+
'tel-fono-xiaomi-redmi-15c-4gb-ram-4gb-virtual-total-8gb-128gb-almacenamiento-con-cover-mica-y-aud-fonos-negro-e8d4a168'
|
|
20
|
+
|
|
21
|
+
/** Add a product to cart and wait until the cart ID is stored in localStorage */
|
|
22
|
+
async function addProductAndWaitForCart(page: import('@playwright/test').Page) {
|
|
23
|
+
// Clear cart on /cart (lightweight — no getProducts call)
|
|
24
|
+
await page.goto('/cart')
|
|
25
|
+
await page.evaluate(() => localStorage.removeItem('thor-cart-id'))
|
|
26
|
+
await page.goto(`/products/${PRODUCT_HANDLE}`)
|
|
27
|
+
await expect(page.getByRole('button', { name: /add to cart/i })).toBeVisible({ timeout: 25_000 })
|
|
28
|
+
await page.getByRole('button', { name: /add to cart/i }).click()
|
|
29
|
+
await expect(page.getByRole('button', { name: /added to cart/i })).toBeVisible({ timeout: 25_000 })
|
|
30
|
+
// Wait for the cart ID to be persisted so checkout won't redirect
|
|
31
|
+
await page.waitForFunction(() => !!localStorage.getItem('thor-cart-id'), { timeout: 10_000 })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test.describe('Checkout', () => {
|
|
35
|
+
test.setTimeout(60_000)
|
|
36
|
+
|
|
37
|
+
test('empty cart redirects from /checkout to /cart', async ({ page }) => {
|
|
38
|
+
// Clear cart on /cart (lightweight — no getProducts call)
|
|
39
|
+
await page.goto('/cart')
|
|
40
|
+
await page.evaluate(() => localStorage.removeItem('thor-cart-id'))
|
|
41
|
+
|
|
42
|
+
await page.goto('/checkout')
|
|
43
|
+
|
|
44
|
+
// Should redirect to /cart
|
|
45
|
+
await expect(page).toHaveURL('/cart', { timeout: 10_000 })
|
|
46
|
+
await expect(page.getByText('Your cart is empty')).toBeVisible()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('checkout page renders step indicator', async ({ page }) => {
|
|
50
|
+
await addProductAndWaitForCart(page)
|
|
51
|
+
await page.goto('/checkout')
|
|
52
|
+
|
|
53
|
+
// Step indicator should show address / shipping / payment / confirm
|
|
54
|
+
await expect(page.getByText('Address', { exact: true })).toBeVisible({ timeout: 10_000 })
|
|
55
|
+
await expect(page.getByText(/shipping/i).first()).toBeVisible()
|
|
56
|
+
await expect(page.getByText(/payment/i)).toBeVisible()
|
|
57
|
+
await expect(page.getByText(/confirm/i)).toBeVisible()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('address step — form fields are present and required', async ({ page }) => {
|
|
61
|
+
await addProductAndWaitForCart(page)
|
|
62
|
+
await page.goto('/checkout')
|
|
63
|
+
|
|
64
|
+
// Required fields visible
|
|
65
|
+
await expect(page.getByLabel(/first name/i)).toBeVisible({ timeout: 10_000 })
|
|
66
|
+
await expect(page.getByLabel(/last name/i)).toBeVisible()
|
|
67
|
+
await expect(page.getByLabel(/email/i)).toBeVisible()
|
|
68
|
+
await expect(page.getByLabel(/address/i).first()).toBeVisible()
|
|
69
|
+
await expect(page.getByRole('button', { name: /continue to shipping/i })).toBeVisible()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('address step submits and advances to shipping step', async ({ page }) => {
|
|
73
|
+
await addProductAndWaitForCart(page)
|
|
74
|
+
await page.goto('/checkout')
|
|
75
|
+
await expect(page.getByLabel(/first name/i)).toBeVisible({ timeout: 10_000 })
|
|
76
|
+
|
|
77
|
+
// Fill address form
|
|
78
|
+
await page.getByLabel(/first name/i).fill('Test')
|
|
79
|
+
await page.getByLabel(/last name/i).fill('E2E')
|
|
80
|
+
await page.getByLabel(/email/i).fill('test.e2e@thorprovider.com')
|
|
81
|
+
await page.getByLabel(/^address$/i).fill('123 Test Street')
|
|
82
|
+
await page.getByLabel(/city/i).fill('Mexico City')
|
|
83
|
+
await page.getByLabel(/state/i).fill('CDMX')
|
|
84
|
+
await page.getByLabel(/postal code/i).fill('06600')
|
|
85
|
+
await page.getByLabel(/country code/i).fill('MX')
|
|
86
|
+
|
|
87
|
+
// Submit address
|
|
88
|
+
await page.getByRole('button', { name: /continue to shipping/i }).click()
|
|
89
|
+
|
|
90
|
+
// Should advance to shipping step (either shows methods or "no shipping methods")
|
|
91
|
+
await expect(
|
|
92
|
+
page.getByText(/select a shipping method/i).or(page.getByText(/no shipping methods available/i))
|
|
93
|
+
).toBeVisible({ timeout: 15_000 })
|
|
94
|
+
})
|
|
95
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global setup: logs in the test customer once and saves browser storage state.
|
|
3
|
+
* All suites that require auth reuse this state (no repeated logins).
|
|
4
|
+
*
|
|
5
|
+
* Auth strategy:
|
|
6
|
+
* - Use Playwright's `request` API context (server-side, bypasses CORS) to obtain
|
|
7
|
+
* the JWT from Medusa.
|
|
8
|
+
* - Inject the token into localStorage via page.evaluate so the commerce adapter
|
|
9
|
+
* picks it up on subsequent requests.
|
|
10
|
+
*
|
|
11
|
+
* The commerce adapter stores the JWT in localStorage under key `thor_auth_token`.
|
|
12
|
+
*/
|
|
13
|
+
import { test as setup, expect, request } from '@playwright/test'
|
|
14
|
+
import { STORAGE_STATE } from '../../playwright.config'
|
|
15
|
+
|
|
16
|
+
const EMAIL = process.env.TEST_CUSTOMER_EMAIL ?? 'test.e2e@thorprovider.com'
|
|
17
|
+
const PASSWORD = process.env.TEST_CUSTOMER_PASSWORD ?? 'TestE2E#2026!'
|
|
18
|
+
const API_URL = 'https://dev.erpthor.com'
|
|
19
|
+
|
|
20
|
+
setup('authenticate as test customer', async ({ page }) => {
|
|
21
|
+
// Step 1: Get JWT from Medusa using server-side request (no CORS)
|
|
22
|
+
const apiContext = await request.newContext({ baseURL: API_URL })
|
|
23
|
+
const loginRes = await apiContext.post('/auth/customer/emailpass', {
|
|
24
|
+
data: { email: EMAIL, password: PASSWORD },
|
|
25
|
+
})
|
|
26
|
+
expect(loginRes.ok(), `Login failed: ${loginRes.status()}`).toBe(true)
|
|
27
|
+
const { token } = await loginRes.json()
|
|
28
|
+
expect(token).toBeTruthy()
|
|
29
|
+
await apiContext.dispose()
|
|
30
|
+
|
|
31
|
+
// Step 2: Visit storefront to initialize browser context
|
|
32
|
+
await page.goto('/')
|
|
33
|
+
await page.waitForLoadState('domcontentloaded')
|
|
34
|
+
|
|
35
|
+
// Step 3: Inject the JWT into localStorage so the commerce adapter uses it
|
|
36
|
+
await page.evaluate((jwt: string) => {
|
|
37
|
+
localStorage.setItem('thor_auth_token', jwt)
|
|
38
|
+
}, token)
|
|
39
|
+
|
|
40
|
+
// Persist storage state for reuse in authenticated suites
|
|
41
|
+
await page.context().storageState({ path: STORAGE_STATE })
|
|
42
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Product tests — PDP rendering and add-to-cart against real backend.
|
|
3
|
+
*
|
|
4
|
+
* Uses the first real product handle exposed by the Default Sales Channel.
|
|
5
|
+
*/
|
|
6
|
+
import { test, expect } from '@playwright/test'
|
|
7
|
+
|
|
8
|
+
// Real product from Default Sales Channel
|
|
9
|
+
const PRODUCT_HANDLE =
|
|
10
|
+
'tel-fono-xiaomi-redmi-15c-4gb-ram-4gb-virtual-total-8gb-128gb-almacenamiento-con-cover-mica-y-aud-fonos-negro-e8d4a168'
|
|
11
|
+
|
|
12
|
+
test.describe('Product Detail Page', () => {
|
|
13
|
+
test('PDP renders product title and price', async ({ page }) => {
|
|
14
|
+
await page.goto(`/products/${PRODUCT_HANDLE}`)
|
|
15
|
+
|
|
16
|
+
// Title visible
|
|
17
|
+
await expect(page.locator('h1')).toBeVisible({ timeout: 15_000 })
|
|
18
|
+
const title = await page.locator('h1').textContent()
|
|
19
|
+
expect(title?.length).toBeGreaterThan(3)
|
|
20
|
+
|
|
21
|
+
// Price visible
|
|
22
|
+
await expect(page.locator('main').getByText(/\$|MXN|USD/i)).toBeVisible()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('PDP has an "Add to cart" button', async ({ page }) => {
|
|
26
|
+
await page.goto(`/products/${PRODUCT_HANDLE}`)
|
|
27
|
+
|
|
28
|
+
const addBtn = page.getByRole('button', { name: /add to cart/i })
|
|
29
|
+
await expect(addBtn).toBeVisible({ timeout: 15_000 })
|
|
30
|
+
await expect(addBtn).toBeEnabled()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('add to cart updates cart and redirects / shows cart link', async ({ page }) => {
|
|
34
|
+
// Clear localStorage to start with a fresh cart
|
|
35
|
+
await page.goto('/')
|
|
36
|
+
await page.evaluate(() => localStorage.removeItem('thor-cart-id'))
|
|
37
|
+
|
|
38
|
+
await page.goto(`/products/${PRODUCT_HANDLE}`)
|
|
39
|
+
const addBtn = page.getByRole('button', { name: /add to cart/i })
|
|
40
|
+
await expect(addBtn).toBeVisible({ timeout: 15_000 })
|
|
41
|
+
await addBtn.click()
|
|
42
|
+
|
|
43
|
+
// Should show cart link or navigate to cart
|
|
44
|
+
await expect(page.getByRole('link', { name: /view cart/i }).or(page.locator('a[href="/cart"]'))).toBeVisible({
|
|
45
|
+
timeout: 10_000,
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('non-existent product returns 404', async ({ page }) => {
|
|
50
|
+
const res = await page.goto('/products/this-handle-does-not-exist-xyz-abc')
|
|
51
|
+
expect(res?.status()).toBe(404)
|
|
52
|
+
})
|
|
53
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smoke tests — verify the storefront loads against the real Medusa backend.
|
|
3
|
+
* No auth required. Covers: homepage, navigation, no console errors.
|
|
4
|
+
*/
|
|
5
|
+
import { test, expect } from '@playwright/test'
|
|
6
|
+
|
|
7
|
+
test.describe('Smoke', () => {
|
|
8
|
+
test('homepage loads and shows products', async ({ page }) => {
|
|
9
|
+
const consoleErrors: string[] = []
|
|
10
|
+
page.on('console', (msg) => {
|
|
11
|
+
if (msg.type() === 'error') consoleErrors.push(msg.text())
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
await page.goto('/')
|
|
15
|
+
await expect(page.locator('main')).toBeVisible()
|
|
16
|
+
|
|
17
|
+
// Should show product grid (at least 1 product from backend)
|
|
18
|
+
const productCards = page.locator('main article')
|
|
19
|
+
await expect(productCards.first()).toBeVisible({ timeout: 15_000 })
|
|
20
|
+
const count = await productCards.count()
|
|
21
|
+
expect(count).toBeGreaterThan(0)
|
|
22
|
+
|
|
23
|
+
// Should show "Connected to live commerce data" (not mock)
|
|
24
|
+
await expect(page.getByText('Connected to live commerce data.')).toBeVisible()
|
|
25
|
+
|
|
26
|
+
// No unexpected console errors (filter known benign 404s like missing images/icons)
|
|
27
|
+
const unexpectedErrors = consoleErrors.filter(
|
|
28
|
+
(e) => !e.includes('favicon') && !e.includes('404') && !e.includes('Not Found'),
|
|
29
|
+
)
|
|
30
|
+
expect(unexpectedErrors).toHaveLength(0)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('navigating to /cart shows empty cart', async ({ page }) => {
|
|
34
|
+
await page.goto('/cart')
|
|
35
|
+
await expect(page.locator('main')).toBeVisible()
|
|
36
|
+
await expect(page.getByText('Your cart is empty')).toBeVisible()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('navigating to a non-existent product shows 404', async ({ page }) => {
|
|
40
|
+
const res = await page.goto('/products/this-product-does-not-exist-xyz')
|
|
41
|
+
expect(res?.status()).toBe(404)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('/backend-unavailable renders fallback page', async ({ page }) => {
|
|
45
|
+
await page.goto('/backend-unavailable')
|
|
46
|
+
await expect(page.getByRole('heading', { name: /service temporarily unavailable/i })).toBeVisible()
|
|
47
|
+
})
|
|
48
|
+
})
|