Files
gui/apps/kitchen-sink/tests/ToastMultiple.test.tsx
zeekayandHanzo Dev 69c6e860d7 transplant onto tamagui v2.6.0, brand as a re-runnable transform
This repo could never sync. There was NO merge-base with tamagui — 372 commits
here against 15,791 there, unrelated histories — because it began as a
copy-paste rebrand with a flattened layout. Every "sync" since was a hand
re-application that drifted, which is why the tree sat on 7.3.1 while upstream
shipped fixes we then rediscovered by hand.

This commit's PARENT IS TAMAGUI. A future sync is `git merge tama/main` then
`node scripts/rebrand.mjs` — a real merge, because the history is now shared.

174 packages: 166 upstream, our 8 restored (chrome, shell, telemetry, recipes,
get, font-geist-{sans,mono}, @hanzo/booker), bento-get gained. 170/170 build.

Our patches to files UPSTREAM ALSO OWNS are carried, which the package-level
delta missed and which was where the value actually was:
  - useMedia's server snapshot (`initState ?? getMedia()`). Upstream still
    returns undefined there, so every Tamagui Dialog kills a prerender — the
    exact crash hanzo.app spent a day on.
  - data-slot on web host nodes, absent upstream entirely.
Both applied ONTO upstream's newer files (it rewrote useMedia +150/-63 and
createComponent +160/-55), marked `PATCH (ours, carried across the transplant)`.

Seven traps are encoded in scripts/rebrand.mjs, each found by a gate:
skip itself and lockfiles; special-case the double-branded names in BOTH scoped
and bare form; map path strings, not just paths; drop a level for the flattened
group; check disk rather than a stale index.

Rust build artifacts are NOT committed. An earlier draft of this commit swept
apps/desktop/src-tauri/target/debug in via `git add -A` — 3,859 files including
a 272MB .a, over GitHub's 100MB cap, so the push could never have landed. They
are gitignored now.

Co-Authored-By: Hanzo Dev <[email protected]>
2026-07-30 18:25:06 -07:00

176 lines
5.6 KiB
TypeScript

import { expect, test } from '@playwright/test'
import { setupPage } from './test-utils'
// single test run with CSS driver (no need to run with all drivers for this test)
test.describe('Toast v2 API', () => {
test.beforeEach(async ({ page }) => {
await setupPage(page, {
name: 'ToastMultipleCase',
type: 'useCase',
searchParams: { animationDriver: 'css' },
})
// remove react-refresh overlay iframe that intercepts pointer events in dev mode
await page.evaluate(() => {
document.getElementById('react-refresh-overlay')?.remove()
})
await page.waitForSelector('[data-testid="toast-default"]', { timeout: 10000 })
})
test('shows default toast when clicking Default button', async ({ page }) => {
await page.click('[data-testid="toast-default"]')
// wait for toast to appear
const toast = await page.waitForSelector('[role="status"]', { timeout: 5000 })
expect(toast).toBeTruthy()
// check toast content
const toastText = await toast.textContent()
expect(toastText).toContain('This is a default toast')
})
test('shows success toast with correct icon', async ({ page }) => {
await page.click('[data-testid="toast-success"]')
const toast = await page.waitForSelector('[data-type="success"]', { timeout: 5000 })
expect(toast).toBeTruthy()
const toastText = await toast.textContent()
expect(toastText).toContain('Operation completed successfully')
})
test('shows error toast', async ({ page }) => {
await page.click('[data-testid="toast-error"]')
const toast = await page.waitForSelector('[data-type="error"]', { timeout: 5000 })
expect(toast).toBeTruthy()
})
test('shows warning toast', async ({ page }) => {
await page.click('[data-testid="toast-warning"]')
const toast = await page.waitForSelector('[data-type="warning"]', { timeout: 5000 })
expect(toast).toBeTruthy()
})
test('shows info toast', async ({ page }) => {
await page.click('[data-testid="toast-info"]')
const toast = await page.waitForSelector('[data-type="info"]', { timeout: 5000 })
expect(toast).toBeTruthy()
})
test('shows loading toast', async ({ page }) => {
await page.click('[data-testid="toast-loading"]')
const toast = await page.waitForSelector('[data-type="loading"]', { timeout: 5000 })
expect(toast).toBeTruthy()
})
test('shows toast with description', async ({ page }) => {
await page.click('[data-testid="toast-with-desc"]')
const toast = await page.waitForSelector('[role="status"]', { timeout: 5000 })
expect(toast).toBeTruthy()
const toastText = await toast.textContent()
expect(toastText).toContain('File uploaded')
expect(toastText).toContain('Your file has been uploaded to the cloud')
})
test('shows multiple toasts stacked', async ({ page }) => {
await page.click('[data-testid="toast-multiple"]')
// wait for all 4 toasts to appear (they have staggered delays)
await page.waitForTimeout(1000)
const toasts = await page.$$('[role="status"]')
expect(toasts.length).toBeGreaterThanOrEqual(4)
// check front toast has data-front="true"
const frontToast = await page.$('[data-front="true"]')
expect(frontToast).toBeTruthy()
})
test('dismiss all toasts', async ({ page }) => {
// first add some toasts
await page.click('[data-testid="toast-multiple"]')
await page.waitForTimeout(1000)
// verify toasts exist
let toasts = await page.$$('[role="status"]')
expect(toasts.length).toBeGreaterThanOrEqual(1)
// dismiss all
await page.click('[data-testid="toast-dismiss-all"]')
// wait for animation
await page.waitForTimeout(500)
// verify all toasts are gone
toasts = await page.$$('[role="status"]')
expect(toasts.length).toBe(0)
})
test('toast with action button', async ({ page }) => {
await page.click('[data-testid="toast-action"]')
const toast = await page.waitForSelector('[role="status"]', { timeout: 5000 })
expect(toast).toBeTruthy()
// look for action button
const actionButton = await toast.$('button')
expect(actionButton).toBeTruthy()
})
test('promise toast transitions from loading to success', async ({ page }) => {
await page.click('[data-testid="toast-promise-success"]')
// should show loading first
const loadingToast = await page.waitForSelector('[data-type="loading"]', {
timeout: 5000,
})
expect(loadingToast).toBeTruthy()
// wait for promise to resolve (2s + some buffer)
await page.waitForTimeout(2500)
// should show success
const successToast = await page.$('[data-type="success"]')
expect(successToast).toBeTruthy()
})
test('promise toast transitions from loading to error', async ({ page }) => {
await page.click('[data-testid="toast-promise-error"]')
// should show loading first
const loadingToast = await page.waitForSelector('[data-type="loading"]', {
timeout: 5000,
})
expect(loadingToast).toBeTruthy()
// wait for promise to reject (2s + some buffer)
await page.waitForTimeout(2500)
// should show error
const errorToast = await page.$('[data-type="error"]')
expect(errorToast).toBeTruthy()
})
test('toast can be updated with same id', async ({ page }) => {
await page.click('[data-testid="toast-update"]')
// should show loading first
const loadingToast = await page.waitForSelector('[data-type="loading"]', {
timeout: 5000,
})
expect(loadingToast).toBeTruthy()
// wait for update (2s + some buffer)
await page.waitForTimeout(2500)
// should show success
const successToast = await page.$('[data-type="success"]')
expect(successToast).toBeTruthy()
})
})