E2E tests + ajv validation of services update to match structure

This commit is contained in:
Matthieu Morin 2024-04-05 15:00:47 +02:00
parent 1a75df9851
commit 0115cb501c
4 changed files with 56 additions and 1 deletions

View File

@ -5,6 +5,9 @@ import path from 'path';
const serviceSchema = JSON.parse(fs.readFileSync('./src/content/schema-categories.json', 'utf-8')); const serviceSchema = JSON.parse(fs.readFileSync('./src/content/schema-categories.json', 'utf-8'));
/**
* @param {string} filePath
*/
function validateFile(filePath) { function validateFile(filePath) {
const ajv = new Ajv(); const ajv = new Ajv();
const data = JSON.parse(fs.readFileSync(filePath, 'utf-8')); const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
@ -15,6 +18,9 @@ function validateFile(filePath) {
} }
} }
/**
* @param {string} directory
*/
function scanDirectory(directory) { function scanDirectory(directory) {
const files = fs.readdirSync(directory); const files = fs.readdirSync(directory);
for (const file of files) { for (const file of files) {
@ -30,7 +36,7 @@ function scanDirectory(directory) {
export function validateServices() { export function validateServices() {
try { try {
scanDirectory('./src/content/'); scanDirectory('./src/content/services');
console.log('All services validated successfully!'); console.log('All services validated successfully!');
} catch (error) { } catch (error) {
console.error(`Error validating services: ${error}`); console.error(`Error validating services: ${error}`);

View File

@ -0,0 +1,21 @@
// tests/e2e/category.test.ts
import { test, expect } from '@playwright/test';
test('category page renders correctly', async ({ page }) => {
const categoryId = 'pmu';
await page.goto(`/${categoryId}`);
// Assert category title
const categoryTitle = await page.locator('h1').textContent();
expect(categoryTitle).toBeDefined();
// Assert category description
const categoryDescription = await page.locator('p').first().textContent();
expect(categoryDescription).toBeDefined();
// Assert services list
// const servicesList = page.locator('ul > li');
// await expect(servicesList).toBeGreaterThan(0);
// Add more assertions as needed
});

View File

@ -0,0 +1,6 @@
import { expect, test } from '@playwright/test';
test('index page has expected h1', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('heading', { name: 'Kosmeticky Salon' })).toBeVisible();
});

22
tests/e2e/service.test.ts Normal file
View File

@ -0,0 +1,22 @@
// tests/e2e/service.test.ts
import { test, expect } from '@playwright/test';
test('service page renders correctly', async ({ page }) => {
const categoryId = 'pmu';
const serviceId = 'pmu-linky';
await page.goto(`/${categoryId}/${serviceId}`);
// Assert service title
const serviceTitle = await page.locator('h1').textContent();
expect(serviceTitle).toBeDefined();
// Assert service description
const serviceDescription = await page.locator('p').first().textContent();
expect(serviceDescription).toBeDefined();
// Assert service content
const serviceContent = await page.locator('article').textContent();
expect(serviceContent).toBeDefined();
// Add more assertions as needed
});