E2E tests + ajv validation of services update to match structure
This commit is contained in:
parent
1a75df9851
commit
0115cb501c
|
@ -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}`);
|
||||||
|
|
|
@ -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
|
||||||
|
});
|
|
@ -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();
|
||||||
|
});
|
|
@ -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
|
||||||
|
});
|
Loading…
Reference in New Issue