| import { faker } from '@faker-js/faker'
|
| import { test, expect } from '@playwright/test'
|
| import { signInAsAdmin } from './auth.utils'
|
|
|
|
|
| declare const process: {
|
| env: Record<string, string | undefined>
|
| }
|
|
|
| |
| |
| |
|
|
| test.describe.configure({ mode: 'serial' })
|
|
|
| test.describe('System Setup', () => {
|
| test('initialize system with owner account', async ({ page }) => {
|
|
|
| page.on('console', (msg) => {
|
| if (msg.type() === 'error') {
|
| console.log(`Browser console error: ${msg.text()}`)
|
| }
|
| })
|
|
|
|
|
| page.on('pageerror', (error) => {
|
| console.log(`Page error: ${error.message}`)
|
| })
|
|
|
|
|
| page.on('requestfailed', (request) => {
|
| console.log(`Request failed: ${request.url()} - ${request.failure()?.errorText}`)
|
| })
|
|
|
|
|
| const ownerEmail = process.env.AXONHUB_ADMIN_EMAIL || 'my@example.com'
|
| const ownerPassword = process.env.AXONHUB_ADMIN_PASSWORD || 'pwd123456'
|
|
|
|
|
| process.env.AXONHUB_ADMIN_EMAIL = ownerEmail
|
|
|
| console.log(`Initializing system with owner: ${ownerEmail}`)
|
|
|
|
|
| await page.goto('/', { waitUntil: 'domcontentloaded' })
|
| await page.waitForTimeout(2000)
|
|
|
|
|
| const currentUrl = page.url()
|
|
|
| if (currentUrl.includes('/initialization')) {
|
|
|
| console.log('System requires initialization')
|
|
|
|
|
| await page.getByRole('textbox', { name: /Owner First Name/i }).waitFor({ timeout: 10000 })
|
|
|
|
|
| await page.getByRole('textbox', { name: /Owner First Name/i }).fill('Admin')
|
| await page.getByRole('textbox', { name: /Owner Last Name/i }).fill('User')
|
| await page.getByRole('textbox', { name: /Owner Email/i }).fill(ownerEmail)
|
| await page.getByLabel(/Owner Password/i).fill(ownerPassword)
|
| await page.getByRole('textbox', { name: /Brand Name/i }).fill('AxonHub')
|
|
|
|
|
| const submitButton = page.getByRole('button', { name: /Initialize System|初始化系统/i })
|
| await expect(submitButton).toBeVisible()
|
|
|
|
|
| await Promise.all([
|
| page.waitForURL((url) => url.toString().includes('/sign-in'), {
|
| timeout: 15000,
|
| }),
|
| submitButton.click(),
|
| ])
|
|
|
| console.log('System initialized successfully, now on sign-in page')
|
|
|
|
|
| await signInAsAdmin(page, { email: ownerEmail, password: ownerPassword })
|
| console.log('Signed in successfully after initialization')
|
| } else if (currentUrl.includes('/sign-in')) {
|
|
|
| console.log('System already initialized, signing in')
|
|
|
| await signInAsAdmin(page, { email: ownerEmail, password: ownerPassword })
|
| console.log('Signed in successfully')
|
| } else {
|
|
|
| console.log('System already initialized and logged in')
|
| }
|
|
|
|
|
| await expect(page.url()).not.toContain('/500')
|
| await expect(page.url()).not.toContain('/sign-in')
|
| await expect(page.url()).not.toContain('/initialization')
|
|
|
|
|
| console.log('Checking for onboarding dialog...')
|
| try {
|
|
|
| const skipButton = page.getByTestId('onboarding-skip-tour')
|
| await skipButton.waitFor({ timeout: 5000 })
|
|
|
|
|
| await skipButton.click()
|
| console.log('Onboarding dialog skipped successfully')
|
|
|
|
|
| await page.waitForTimeout(1000)
|
| } catch (error) {
|
|
|
| console.log('No onboarding dialog found or already handled')
|
| }
|
|
|
| console.log(`Setup complete. Owner email: ${ownerEmail}`)
|
| })
|
| })
|
|
|