Files
newz-qwen-9b/frontend/playwright/e2e/api.spec.ts
T

85 lines
2.6 KiB
TypeScript

import { test, expect } from '@playwright/test';
test.describe('API Integration E2E Tests', () => {
test('makes request to articles endpoint', async ({ page }) => {
await page.goto('/');
// Verify page loads without errors
const consoleMessages = page.locator('#root');
await expect(consoleMessages).not.toHaveCount(0);
});
test('API base URL is configured correctly', async ({ page }) => {
await page.goto('/api');
const url = page.url();
expect(url).toContain('/api');
});
test('article page loads with correct ID parameter', async ({ page }) => {
await page.goto('/articles/123');
const titleElement = page.locator('.article-page-placeholder');
await expect(titleElement).toBeVisible();
});
test('categories page renders properly', async ({ page }) => {
await page.goto('/categories');
const categoriesSection = page.locator('.categories-page-placeholder');
await expect(categoriesSection).toBeVisible();
});
test('navigation between pages works via client-side routing', async ({ page }) => {
await page.goto('/');
// Check initial state
const homeContent = page.locator('.home-page');
await expect(homeContent).toBeVisible();
// Navigate to articles
const articlesLink = page.getByRole('link', { name: /articles/i });
await articlesLink.click();
// Verify client-side navigation
const articleContent = page.locator('.article-page-placeholder');
await expect(articleContent).toBeVisible();
});
test('no console errors during page load and navigation', async ({ page }) => {
let hasErrors = false;
page.on('console', message => {
if (message.type() === 'error') {
hasErrors = true;
console.error('Console error:', message.text());
}
});
await page.goto('/');
await page.waitForTimeout(1000);
expect(hasErrors).toBe(false);
});
test('article cards display expected content structure', async ({ page }) => {
await page.goto('/');
const articleCards = page.locator('.article-card');
const thumbnailPlaceholders = articleCards.locator('.article-thumbnail-placeholder');
const contentDivs = articleCards.locator('.article-content');
if (await articleCards.count() > 0) {
await expect(thumbnailPlaceholders).toBeVisible();
await expect(contentDivs).toBeVisible();
}
});
test('footer contains copyright information', async ({ page }) => {
await page.goto('/');
const footer = page.locator('.footer-section');
await expect(footer).toContainText('© 2024 newzy');
});
});