test: add taro h5 interaction smoke

This commit is contained in:
Codex
2026-07-01 02:37:43 +08:00
parent c3e1f27a0a
commit ad1c69037b
20 changed files with 1052 additions and 36 deletions

View File

@@ -7,6 +7,7 @@ import {
loadSchoolRecommendationReports,
type SchoolRecommendationReport,
} from '@/services/ai';
import { isH5Runtime } from '@/env';
import { loadProfile, type StudentProfile } from '@/services/profile';
import '../student.css';
@@ -25,7 +26,7 @@ function recommendationRows(report: SchoolRecommendationReport | null) {
}
function saveExportFile(fileName: string, content: string, mimeType: string) {
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' && typeof document !== 'undefined') {
if (isH5Runtime() && typeof window !== 'undefined' && typeof document !== 'undefined') {
const blob = new Blob([content], { type: mimeType });
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
@@ -94,7 +95,7 @@ export default function StudentAiSchoolPage() {
const payload = await exportSchoolRecommendationReport(current.id, format);
if (!payload.item?.contentText) throw new Error('后端未返回报告内容');
saveExportFile(payload.item.fileName, payload.item.contentText, payload.item.mimeType);
if (process.env.TARO_ENV === 'h5') Taro.showToast({ title: '报告已导出', icon: 'success' });
if (isH5Runtime()) Taro.showToast({ title: '报告已导出', icon: 'success' });
} catch (nextError) {
setError(nextError instanceof Error ? nextError.message : '导出失败');
} finally {

View File

@@ -9,6 +9,7 @@ import {
type ContentAsset,
type SignedAssetLink,
} from '@/services/catalog';
import { isH5Runtime } from '@/env';
import '../student.css';
type PreviewState = {
@@ -20,7 +21,7 @@ type PreviewState = {
function openUrl(url?: string, copiedText = '签名链接已复制,请在浏览器中打开') {
if (!url) return;
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
if (isH5Runtime() && typeof window !== 'undefined') {
window.open(url, '_blank', 'noopener,noreferrer');
return;
}
@@ -129,10 +130,10 @@ export default function StudentAssetsPage() {
<Text className='row-meta'> URL </Text>
</View>
) : null}
{previewState.kind === 'preview' && process.env.TARO_ENV === 'h5' ? (
{previewState.kind === 'preview' && isH5Runtime() ? (
<WebView className='asset-preview-iframe' src={previewState.link.url || ''} />
) : null}
{previewState.kind === 'preview' && process.env.TARO_ENV !== 'h5' ? (
{previewState.kind === 'preview' && !isH5Runtime() ? (
<View className='asset-download-confirm'>
<Text className='row-main'></Text>
<Text className='row-meta'>使</Text>

View File

@@ -12,6 +12,7 @@ import {
type PaymentCreateResult,
type SvipPlan,
} from '@/services/commerce';
import { isH5Runtime, isWeappRuntime } from '@/env';
import { loadProfile, type StudentProfile } from '@/services/profile';
import '../student.css';
@@ -56,7 +57,7 @@ function buildPaymentUrl(result?: PaymentCreateResult) {
function tryOpenPaymentUrl(url: string) {
if (!url) return false;
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
if (isH5Runtime() && typeof window !== 'undefined') {
window.location.href = url;
return true;
}
@@ -167,8 +168,8 @@ export default function StudentCheckoutPage() {
const paymentPayload = await createPayment({
orderNo: nextOrder.orderNo,
provider,
returnUrl: process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' ? window.location.href : undefined,
quitUrl: process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' ? window.location.href : undefined,
returnUrl: isH5Runtime() && typeof window !== 'undefined' ? window.location.href : undefined,
quitUrl: isH5Runtime() && typeof window !== 'undefined' ? window.location.href : undefined,
});
setPayment(paymentPayload.item || null);
setMessage(provider === 'manual' ? '已生成线下支付记录,请联系教务或客服确认。' : '支付参数已生成,请继续完成支付。');
@@ -181,7 +182,7 @@ export default function StudentCheckoutPage() {
async function handleOpenPayment() {
if (!payment) return;
if (payment.provider === 'wechat_pay' && process.env.TARO_ENV === 'weapp') {
if (payment.provider === 'wechat_pay' && isWeappRuntime()) {
const paramsForWeapp = payment.paymentParams || {};
Taro.requestPayment(paramsForWeapp as unknown as Taro.requestPayment.Option)
.then(() => order?.orderNo ? pollStatus(order.orderNo) : undefined)

View File

@@ -10,6 +10,7 @@ import {
type PaymentCreateResult,
} from '@/services/commerce';
import { getTenantContext } from '@/services/api';
import { isH5Runtime } from '@/env';
import '../student.css';
function centsToYuan(value?: number | null) {
@@ -94,13 +95,13 @@ export default function StudentOrderDetailPage() {
const payload = await createPayment({
orderNo,
provider: provider || detail?.payProvider || status?.payProvider || 'alipay',
returnUrl: process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' ? window.location.href : undefined,
quitUrl: process.env.TARO_ENV === 'h5' && typeof window !== 'undefined' ? window.location.href : undefined,
returnUrl: isH5Runtime() && typeof window !== 'undefined' ? window.location.href : undefined,
quitUrl: isH5Runtime() && typeof window !== 'undefined' ? window.location.href : undefined,
});
const nextPayment = payload.item || null;
setPayment(nextPayment);
const url = paymentUrl(nextPayment);
if (url && process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
if (url && isH5Runtime() && typeof window !== 'undefined') {
window.location.href = url;
} else if (url) {
await Taro.setClipboardData({ data: url });