feat: add mobile test data generator
This commit is contained in:
@@ -0,0 +1,87 @@
|
|||||||
|
import { Page } from '@playwright/test';
|
||||||
|
import { getNetworkConfig, NetworkConfig } from '../config/network-configs';
|
||||||
|
import { getDevice, DeviceConfig } from './devices';
|
||||||
|
|
||||||
|
export class MobileTestDataGenerator {
|
||||||
|
static generateUserAgent(device: string): string {
|
||||||
|
const deviceConfig = getDevice(device);
|
||||||
|
return deviceConfig.userAgent || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
static generateNetworkConfig(type: '2G' | '3G' | '4G' | 'WiFi' | 'offline'): NetworkConfig {
|
||||||
|
const configMap = {
|
||||||
|
'2G': '2g-slow',
|
||||||
|
'3G': '3g-fast',
|
||||||
|
'4G': '4g-lte',
|
||||||
|
'WiFi': 'wifi-fast',
|
||||||
|
'offline': 'offline',
|
||||||
|
};
|
||||||
|
return getNetworkConfig(configMap[type]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TouchEventData {
|
||||||
|
type: 'tap' | 'swipe' | 'pinch' | 'longPress';
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
duration?: number;
|
||||||
|
distance?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PerformanceBaseline {
|
||||||
|
device: string;
|
||||||
|
network: string;
|
||||||
|
LCP: number;
|
||||||
|
FCP: number;
|
||||||
|
CLS: number;
|
||||||
|
FID: number;
|
||||||
|
TTI: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
MobileTestDataGenerator.generateTouchEvent = function(type: 'tap' | 'swipe' | 'pinch' | 'longPress'): TouchEventData {
|
||||||
|
const baseData = {
|
||||||
|
x: Math.floor(Math.random() * 375),
|
||||||
|
y: Math.floor(Math.random() * 667),
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'tap':
|
||||||
|
return { ...baseData, type: 'tap' };
|
||||||
|
case 'swipe':
|
||||||
|
return { ...baseData, type: 'swipe', duration: 500 };
|
||||||
|
case 'pinch':
|
||||||
|
return { ...baseData, type: 'pinch', distance: 100 };
|
||||||
|
case 'longPress':
|
||||||
|
return { ...baseData, type: 'longPress', duration: 1000 };
|
||||||
|
default:
|
||||||
|
return { ...baseData, type: 'tap' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
MobileTestDataGenerator.generatePerformanceBaseline = function(device: string, network: string): PerformanceBaseline {
|
||||||
|
const deviceMultiplier = {
|
||||||
|
'mobile-375x667': 1.2,
|
||||||
|
'mobile-414x896': 1.1,
|
||||||
|
'tablet-768x1024': 0.9,
|
||||||
|
'desktop-1920x1080': 0.8,
|
||||||
|
}[device] || 1;
|
||||||
|
|
||||||
|
const networkMultiplier = {
|
||||||
|
'2g-slow': 3,
|
||||||
|
'3g-fast': 2,
|
||||||
|
'4g-lte': 1.5,
|
||||||
|
'wifi-fast': 1,
|
||||||
|
}[network] || 1;
|
||||||
|
|
||||||
|
const multiplier = deviceMultiplier * networkMultiplier;
|
||||||
|
|
||||||
|
return {
|
||||||
|
device,
|
||||||
|
network,
|
||||||
|
LCP: 2500 * multiplier,
|
||||||
|
FCP: 1800 * multiplier,
|
||||||
|
CLS: 0.1,
|
||||||
|
FID: 100 * multiplier,
|
||||||
|
TTI: 3800 * multiplier,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user