import { test, expect } from '@playwright/test'; import { NetworkSimulator } from '../../utils/NetworkSimulator'; import { networkConfigs } from '../../config/network-configs'; test.describe('NetworkSimulator', () => { test('should set 3G network condition', async ({ page, context }) => { const simulator = new NetworkSimulator(context); await simulator.setNetworkCondition(networkConfigs['3g-fast']); await page.goto('/'); await expect(page.locator('header')).toBeVisible(); }); test('should switch to offline mode', async ({ page, context }) => { const simulator = new NetworkSimulator(context); await page.goto('/'); await simulator.goOffline(); await page.reload(); await expect(page.locator('header')).toBeVisible(); }); test('should switch back to online mode', async ({ page, context }) => { const simulator = new NetworkSimulator(context); await simulator.goOffline(); await simulator.goOnline(); await page.goto('/'); await expect(page.locator('header')).toBeVisible(); }); test('should simulate network switch', async ({ page, context }) => { const simulator = new NetworkSimulator(context); await simulator.simulateNetworkSwitch(networkConfigs['wifi-fast'], networkConfigs['3g-fast']); await page.goto('/'); await expect(page.locator('header')).toBeVisible(); }); test('should reset network condition', async ({ page, context }) => { const simulator = new NetworkSimulator(context); await simulator.setNetworkCondition(networkConfigs['3g-fast']); await simulator.resetNetworkCondition(); await page.goto('/'); await expect(page.locator('header')).toBeVisible(); }); test('should track network requests', async ({ page, context }) => { const simulator = new NetworkSimulator(context); await page.goto('/'); const requests = simulator.getRequests(); expect(requests.length).toBeGreaterThan(0); }); test('should get failed requests', async ({ page, context }) => { const simulator = new NetworkSimulator(context); await page.goto('/'); const failedRequests = simulator.getFailedRequests(); expect(Array.isArray(failedRequests)).toBe(true); }); test('should get slow requests', async ({ page, context }) => { const simulator = new NetworkSimulator(context); await page.goto('/'); const slowRequests = simulator.getSlowRequests(1000); expect(Array.isArray(slowRequests)).toBe(true); }); test('should clear requests', async ({ page, context }) => { const simulator = new NetworkSimulator(context); await page.goto('/'); expect(simulator.getRequests().length).toBeGreaterThan(0); simulator.clearRequests(); expect(simulator.getRequests().length).toBe(0); }); });