@thorprovider/create-thor-app 4.1.9 → 4.2.1
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 +47 -473
- package/package.json +1 -1
- package/templates/default/.env.example +1 -1
- package/templates/default/README.md +2 -1
- 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/project-structure.md +16 -6
- package/templates/default/lib/commerce-client.ts +1 -1
- 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,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
|
+
})
|